RageTypes.h
Go to the documentation of this file.00001
00002
00003
00004
00005
#ifndef RAGETYPES_H
00006
#define RAGETYPES_H
00007
00008 enum BlendMode {
BLEND_NORMAL,
BLEND_ADD,
BLEND_NO_EFFECT,
BLEND_INVALID };
00009 enum CullMode {
CULL_BACK,
CULL_FRONT,
CULL_NONE };
00010 enum ZTestMode {
ZTEST_OFF,
ZTEST_WRITE_ON_PASS,
ZTEST_WRITE_ON_FAIL };
00011 enum PolygonMode {
POLYGON_FILL,
POLYGON_LINE };
00012
00013
00014 struct RageVector2
00015 {
00016
public:
00017 RageVector2() {}
00018 RageVector2(
const float * f ) {
x=
f[0];
y=
f[1]; }
00019 RageVector2(
float x1,
float y1 ) {
x=x1;
y=y1; }
00020
00021
00022 operator float* () {
return &
x; };
00023 operator const float* ()
const {
return &
x; };
00024
00025
00026 RageVector2& operator += (
const RageVector2& other ) {
x+=other.
x;
y+=other.
y;
return *
this; }
00027 RageVector2& operator -= (
const RageVector2& other ) {
x-=other.
x;
y-=other.
y;
return *
this; }
00028 RageVector2& operator *= (
float f ) {
x*=
f;
y*=
f;
return *
this; }
00029 RageVector2& operator /= (
float f ) {
x/=
f;
y/=
f;
return *
this; }
00030
00031
00032 RageVector2 operator + (
const RageVector2& other )
const {
return RageVector2(
x+other.
x,
y+other.
y ); }
00033 RageVector2 operator - (
const RageVector2& other )
const {
return RageVector2(
x-other.
x,
y-other.
y ); }
00034 RageVector2 operator * (
float f )
const {
return RageVector2(
x*
f,
y*
f ); }
00035 RageVector2 operator / (
float f )
const {
return RageVector2(
x/
f,
y/
f ); }
00036
00037 friend RageVector2 operator * (
float f,
const RageVector2& other ) {
return other*
f; }
00038
00039 float x,
y;
00040 };
00041
00042
00043 struct RageVector3
00044 {
00045
public:
00046 RageVector3() {}
00047 RageVector3(
const float * f ) {
x=
f[0];
y=
f[1];
z=
f[2]; }
00048 RageVector3(
float x1,
float y1,
float z1 ) {
x=x1;
y=y1;
z=z1; }
00049
00050
00051 operator float* () {
return &
x; };
00052 operator const float* ()
const {
return &
x; };
00053
00054
00055 RageVector3& operator += (
const RageVector3& other ) {
x+=other.
x;
y+=other.
y;
z+=other.
z;
return *
this; }
00056 RageVector3& operator -= (
const RageVector3& other ) {
x-=other.
x;
y-=other.
y;
z-=other.
z;
return *
this; }
00057 RageVector3& operator *= (
float f ) {
x*=
f;
y*=
f;
z*=
f;
return *
this; }
00058 RageVector3& operator /= (
float f ) {
x/=
f;
y/=
f;
z/=
f;
return *
this; }
00059
00060
00061 RageVector3 operator + (
const RageVector3& other )
const {
return RageVector3(
x+other.
x,
y+other.
y,
z+other.
z ); }
00062 RageVector3 operator - (
const RageVector3& other )
const {
return RageVector3(
x-other.
x,
y-other.
y,
z-other.
z ); }
00063 RageVector3 operator * (
float f )
const {
return RageVector3(
x*
f,
y*
f,
z*
f ); }
00064 RageVector3 operator / (
float f )
const {
return RageVector3(
x/
f,
y/
f,
z/
f ); }
00065
00066 friend RageVector3 operator * (
float f,
const RageVector3& other ) {
return other*
f; }
00067
00068 float x,
y,
z;
00069 };
00070
00071
00072 struct RageVector4
00073 {
00074
public:
00075 RageVector4() {}
00076 RageVector4(
const float * f ) {
x=
f[0];
y=
f[1];
z=
f[2];
w=
f[3]; }
00077 RageVector4(
float x1,
float y1,
float z1,
float w1 ) {
x=x1;
y=y1;
z=z1;
w=w1; }
00078
00079
00080 operator float* () {
return &
x; };
00081 operator const float* ()
const {
return &
x; };
00082
00083
00084 RageVector4& operator += (
const RageVector4& other ) {
x+=other.
x;
y+=other.
y;
z+=other.
z;
w+=other.
w;
return *
this; }
00085 RageVector4& operator -= (
const RageVector4& other ) {
x-=other.
x;
y-=other.
y;
z-=other.
z;
w-=other.
w;
return *
this; }
00086 RageVector4& operator *= (
float f ) {
x*=
f;
y*=
f;
z*=
f;
w*=
f;
return *
this; }
00087 RageVector4& operator /= (
float f ) {
x/=
f;
y/=
f;
z/=
f;
w/=
f;
return *
this; }
00088
00089
00090 RageVector4 operator + (
const RageVector4& other )
const {
return RageVector4(
x+other.
x,
y+other.
y,
z+other.
z,
w+other.
w ); }
00091 RageVector4 operator - (
const RageVector4& other )
const {
return RageVector4(
x-other.
x,
y-other.
y,
z-other.
z,
w-other.
w ); }
00092 RageVector4 operator * (
float f )
const {
return RageVector4(
x*
f,
y*
f,
z*
f,
w*
f ); }
00093 RageVector4 operator / (
float f )
const {
return RageVector4(
x/
f,
y/
f,
z/
f,
w/
f ); }
00094
00095 friend RageVector4 operator * (
float f,
const RageVector4& other ) {
return other*
f; }
00096
00097 float x,
y,
z,
w;
00098 }
ALIGN(16);
00099
00100 struct RageColor
00101 {
00102
public:
00103 RageColor() {}
00104 RageColor(
const float * f ) {
r=
f[0];
g=
f[1];
b=
f[2];
a=
f[3]; }
00105 RageColor(
float r1,
float g1,
float b1,
float a1 ) {
r=r1;
g=g1;
b=b1;
a=a1; }
00106
00107
00108 operator float* () {
return &
r; };
00109 operator const float* ()
const {
return &
r; };
00110
00111
00112 RageColor& operator += (
const RageColor& other ) {
r+=other.
r;
g+=other.
g;
b+=other.
b;
a+=other.
a;
return *
this; }
00113 RageColor& operator -= (
const RageColor& other ) {
r-=other.
r;
g-=other.
g;
b-=other.
b;
a-=other.
a;
return *
this; }
00114 RageColor& operator *= (
const RageColor& other ) {
r*=other.
r;
g*=other.
g;
b*=other.
b;
a*=other.
a;
return *
this; }
00115 RageColor& operator *= (
float f ) {
r*=
f;
g*=
f;
b*=
f;
a*=
f;
return *
this; }
00116
00117
00118
00119
00120
00121 RageColor operator + (
const RageColor& other )
const {
return RageColor(
r+other.
r,
g+other.
g,
b+other.
b,
a+other.
a ); }
00122 RageColor operator - (
const RageColor& other )
const {
return RageColor(
r-other.
r,
g-other.
g,
b-other.
b,
a-other.
a ); }
00123 RageColor operator * (
const RageColor& other )
const {
return RageColor(
r*other.
r,
g*other.
g,
b*other.
b,
a*other.
a ); }
00124 RageColor operator * (
float f )
const {
return RageColor(
r*
f,
g*
f,
b*
f,
a*
f ); }
00125
00126 RageColor operator / (
float f )
const {
return RageColor(
r/
f,
g/
f,
b/
f,
a/
f ); }
00127
00128 friend RageColor operator * (
float f,
const RageColor& other ) {
return other*
f; }
00129
00130 bool FromString(
const CString &str )
00131 {
00132
int result = sscanf( str,
"%f,%f,%f,%f", &
r, &
g, &
b, &
a );
00133
if( result == 3 )
00134 {
00135
a = 1;
00136
return true;
00137 }
00138
if( result == 4 )
00139
return true;
00140
00141
int ir=255, ib=255, ig=255, ia=255;
00142 result = sscanf( str,
"#%2x%2x%2x%2x", &ir, &ig, &ib, &ia );
00143
if( result >= 3 )
00144 {
00145
r = ir / 255.0f;
g = ig / 255.0f;
b = ib / 255.0f;
00146
if( result == 4 )
00147
a = ia / 255.0f;
00148
else
00149
a = 1;
00150
return true;
00151 }
00152
00153
r=1;
b=1;
g=1;
a=1;
00154
return false;
00155 }
00156 float r,
g,
b,
a;
00157 }
ALIGN(16);
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169 inline unsigned char FTOC(
float a)
00170 {
00171
00172
00173
00174
00175
00176
int ret = lrintf(a*256.
f - 0.5
f);
00177
00178
00179
00180
if( ret<0 )
return 0;
00181
else if( ret>255 )
return 255;
00182
else return (
unsigned char) ret;
00183 }
00184
00185
00186
00187
00188
00189
00190
00191 class RageVColor
00192 {
00193
public:
00194 uint8_t
b,
g,
r,
a;
00195
00196 RageVColor() { }
00197 RageVColor(
const RageColor &rc) { *
this = rc; }
00198 RageVColor &operator= (
const RageColor &rc) {
00199
r =
FTOC(rc.
r);
g =
FTOC(rc.
g);
b =
FTOC(rc.
b);
a =
FTOC(rc.
a);
00200
return *
this;
00201 }
00202 };
00203
00204
00205
template <
class T>
00206 class Rect
00207 {
00208
public:
00209 Rect() {};
00210 Rect(T l, T t, T r, T b) { left = l, top = t, right = r, bottom = b; };
00211
00212 T GetWidth()
const {
return right-left; };
00213 T GetHeight()
const {
return bottom-top; };
00214 T GetCenterX()
const {
return (left+right)/2; };
00215 T GetCenterY()
const {
return (top+bottom)/2; };
00216
00217 T left, top, right, bottom;
00218 };
00219
00220 typedef Rect<int> RectI;
00221 typedef Rect<float> RectF;
00222
00223
00224
00225 struct RageSpriteVertex
00226 {
00227 RageVector3 p;
00228 RageVector3 n;
00229 RageVColor c;
00230 RageVector2 t;
00231 };
00232
00233
00234 struct RageModelVertex
00235 {
00236
00237 RageModelVertex():
00238
p(0,0,0),
00239
n(0,0,0),
00240
t(0,0)
00241 { }
00242 RageVector3 p;
00243 RageVector3 n;
00244 RageVector2 t;
00245 int8_t
bone;
00246 };
00247
00248
00249
00250
00251
00252
00253
00254
00255 struct RageMatrix
00256 {
00257
public:
00258 RageMatrix() {};
00259 RageMatrix(
const float *f ) {
for(
int i=0; i<4; i++)
for(
int j=0; j<4; j++)
m[j][i]=
f[j*4+i]; }
00260 RageMatrix(
const RageMatrix& other ) {
for(
int i=0; i<4; i++)
for(
int j=0; j<4; j++)
m[j][i]=other.
m[j][i]; }
00261
RageMatrix(
float v00,
float v01,
float v02,
float v03,
00262
float v10,
float v11,
float v12,
float v13,
00263
float v20,
float v21,
float v22,
float v23,
00264
float v30,
float v31,
float v32,
float v33 );
00265
00266
00267 float& operator () (
int iRow,
int iCol ) {
return m[iCol][iRow]; }
00268 float operator () (
int iRow,
int iCol )
const {
return m[iCol][iRow]; }
00269
00270
00271 operator float* () {
return m[0]; }
00272 operator const float* ()
const {
return m[0]; }
00273
00274
RageMatrix GetTranspose() const;
00275
00276 float m[4][4];
00277 } ALIGN(16);
00278
00279
RageColor scale(
float x,
float l1,
float h1, const
RageColor &a, const
RageColor &b );
00280
00281 #endif
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
Generated on Thu Jan 27 20:57:30 2005 for StepMania by
1.3.7