mirror of https://github.com/aap/librw.git
added some consts :(
This commit is contained in:
parent
4f5687dd2e
commit
9fc46eac37
16
src/base.cpp
16
src/base.cpp
|
@ -130,7 +130,7 @@ cross(const V3d &a, const V3d &b)
|
|||
}
|
||||
|
||||
void
|
||||
V3d::transformPoints(V3d *out, V3d *in, int32 n, Matrix *m)
|
||||
V3d::transformPoints(V3d *out, const V3d *in, int32 n, const Matrix *m)
|
||||
{
|
||||
int32 i;
|
||||
V3d tmp;
|
||||
|
@ -143,7 +143,7 @@ V3d::transformPoints(V3d *out, V3d *in, int32 n, Matrix *m)
|
|||
}
|
||||
|
||||
void
|
||||
V3d::transformVectors(V3d *out, V3d *in, int32 n, Matrix *m)
|
||||
V3d::transformVectors(V3d *out, const V3d *in, int32 n, const Matrix *m)
|
||||
{
|
||||
int32 i;
|
||||
V3d tmp;
|
||||
|
@ -263,7 +263,7 @@ Matrix::optimize(Tolerance *tolerance)
|
|||
}
|
||||
|
||||
Matrix*
|
||||
Matrix::mult(Matrix *dst, Matrix *src1, Matrix *src2)
|
||||
Matrix::mult(Matrix *dst, const Matrix *src1, const Matrix *src2)
|
||||
{
|
||||
if(src1->flags & IDENTITY)
|
||||
*dst = *src2;
|
||||
|
@ -277,7 +277,7 @@ Matrix::mult(Matrix *dst, Matrix *src1, Matrix *src2)
|
|||
}
|
||||
|
||||
Matrix*
|
||||
Matrix::invert(Matrix *dst, Matrix *src)
|
||||
Matrix::invert(Matrix *dst, const Matrix *src)
|
||||
{
|
||||
if(src->flags & IDENTITY)
|
||||
*dst = *src;
|
||||
|
@ -290,7 +290,7 @@ Matrix::invert(Matrix *dst, Matrix *src)
|
|||
|
||||
// transpose the 3x3 submatrix, pos is set to 0
|
||||
Matrix*
|
||||
Matrix::transpose(Matrix *dst, Matrix *src)
|
||||
Matrix::transpose(Matrix *dst, const Matrix *src)
|
||||
{
|
||||
if(src->flags & IDENTITY)
|
||||
*dst = *src;
|
||||
|
@ -462,7 +462,7 @@ Matrix::lookAt(const V3d &dir, const V3d &up)
|
|||
}
|
||||
|
||||
void
|
||||
Matrix::mult_(Matrix *dst, Matrix *src1, Matrix *src2)
|
||||
Matrix::mult_(Matrix *dst, const Matrix *src1, const Matrix *src2)
|
||||
{
|
||||
dst->right.x = src1->right.x*src2->right.x + src1->right.y*src2->up.x + src1->right.z*src2->at.x;
|
||||
dst->right.y = src1->right.x*src2->right.y + src1->right.y*src2->up.y + src1->right.z*src2->at.y;
|
||||
|
@ -479,7 +479,7 @@ Matrix::mult_(Matrix *dst, Matrix *src1, Matrix *src2)
|
|||
}
|
||||
|
||||
void
|
||||
Matrix::invertOrthonormal(Matrix *dst, Matrix *src)
|
||||
Matrix::invertOrthonormal(Matrix *dst, const Matrix *src)
|
||||
{
|
||||
dst->right.x = src->right.x;
|
||||
dst->right.y = src->up.x;
|
||||
|
@ -503,7 +503,7 @@ Matrix::invertOrthonormal(Matrix *dst, Matrix *src)
|
|||
}
|
||||
|
||||
Matrix*
|
||||
Matrix::invertGeneral(Matrix *dst, Matrix *src)
|
||||
Matrix::invertGeneral(Matrix *dst, const Matrix *src)
|
||||
{
|
||||
float32 det, invdet;
|
||||
// calculate a few cofactors
|
||||
|
|
|
@ -265,7 +265,11 @@ setRwRenderState(int32 state, uint32 value)
|
|||
};
|
||||
break;
|
||||
case FOGCOLOR:{
|
||||
RGBA c = *(RGBA*)&value;
|
||||
RGBA c;
|
||||
c.red = value;
|
||||
c.green = value>>8;
|
||||
c.blue = value>>16;
|
||||
c.alpha = value>>24;
|
||||
if(!equal(fogcolor, c)){
|
||||
fogcolor = c;
|
||||
setRenderState(D3DRS_FOGCOLOR, D3DCOLOR_RGBA(c.red, c.green, c.blue, c.alpha));
|
||||
|
@ -308,7 +312,7 @@ getRwRenderState(int32 state)
|
|||
case FOGENABLE:
|
||||
return fogenable;
|
||||
case FOGCOLOR:
|
||||
return *(uint32*)&fogcolor;
|
||||
return RWRGBAINT(fogcolor.red, fogcolor.green, fogcolor.blue, fogcolor.alpha);
|
||||
case CULLMODE:
|
||||
return cullmode;
|
||||
case ALPHATESTFUNC:
|
||||
|
|
|
@ -191,7 +191,12 @@ setRenderState(int32 state, uint32 value)
|
|||
break;
|
||||
case FOGCOLOR:
|
||||
// no cache check here...too lazy
|
||||
convColor(&uniformState.fogColor, (RGBA*)&value);
|
||||
RGBA c;
|
||||
c.red = value;
|
||||
c.green = value>>8;
|
||||
c.blue = value>>16;
|
||||
c.alpha = value>>24;
|
||||
convColor(&uniformState.fogColor, &c);
|
||||
stateDirty = 1;
|
||||
break;
|
||||
case CULLMODE:
|
||||
|
@ -237,7 +242,7 @@ getRenderState(int32 state)
|
|||
return uniformState.fogEnable;
|
||||
case FOGCOLOR:
|
||||
convColor(&rgba, &uniformState.fogColor);
|
||||
return *(uint32*)&rgba;
|
||||
return RWRGBAINT(rgba.red, rgba.green, rgba.blue, rgba.alpha);
|
||||
case CULLMODE:
|
||||
return cullmode;
|
||||
|
||||
|
|
17
src/rwbase.h
17
src/rwbase.h
|
@ -132,6 +132,7 @@ struct RGBA
|
|||
};
|
||||
inline RGBA makeRGBA(uint8 r, uint8 g, uint8 b, uint8 a) { RGBA c = { r, g, b, a }; return c; }
|
||||
inline bool32 equal(const RGBA &c1, const RGBA &c2) { return c1.red == c2.red && c1.green == c2.green && c1.blue == c2.blue && c1.alpha == c2.alpha; }
|
||||
#define RWRGBAINT(r, g, b, a) ((uint32)((((a)&0xff)<<24)|(((b)&0xff)<<16)|(((g)&0xff)<<8)|((r)&0xff)))
|
||||
|
||||
struct RGBAf
|
||||
{
|
||||
|
@ -207,8 +208,8 @@ struct V3d
|
|||
float32 x, y, z;
|
||||
void set(float32 x, float32 y, float32 z){
|
||||
this->x = x; this->y = y; this->z = z; }
|
||||
static void transformPoints(V3d *out, V3d *in, int32 n, Matrix *m);
|
||||
static void transformVectors(V3d *out, V3d *in, int32 n, Matrix *m);
|
||||
static void transformPoints(V3d *out, const V3d *in, int32 n, const Matrix *m);
|
||||
static void transformVectors(V3d *out, const V3d *in, int32 n, const Matrix *m);
|
||||
};
|
||||
|
||||
inline V3d makeV3d(float32 x, float32 y, float32 z) { V3d v = { x, y, z }; return v; }
|
||||
|
@ -318,9 +319,9 @@ struct Matrix
|
|||
void setIdentity(void);
|
||||
void optimize(Tolerance *tolerance = nil);
|
||||
void update(void) { flags &= ~(IDENTITY|TYPEMASK); }
|
||||
static Matrix *mult(Matrix *dst, Matrix *src1, Matrix *src2);
|
||||
static Matrix *invert(Matrix *m1, Matrix *m2);
|
||||
static Matrix *transpose(Matrix *m1, Matrix *m2);
|
||||
static Matrix *mult(Matrix *dst, const Matrix *src1, const Matrix *src2);
|
||||
static Matrix *invert(Matrix *dst, const Matrix *src);
|
||||
static Matrix *transpose(Matrix *dst, const Matrix *src);
|
||||
Matrix *rotate(V3d *axis, float32 angle, CombineOp op);
|
||||
Matrix *rotate(const Quat &q, CombineOp op);
|
||||
Matrix *translate(V3d *translation, CombineOp op);
|
||||
|
@ -330,9 +331,9 @@ struct Matrix
|
|||
void lookAt(const V3d &dir, const V3d &up);
|
||||
|
||||
// helper functions. consider private
|
||||
static void mult_(Matrix *dst, Matrix *src1, Matrix *src2);
|
||||
static void invertOrthonormal(Matrix *dst, Matrix *src);
|
||||
static Matrix *invertGeneral(Matrix *dst, Matrix *src);
|
||||
static void mult_(Matrix *dst, const Matrix *src1, const Matrix *src2);
|
||||
static void invertOrthonormal(Matrix *dst, const Matrix *src);
|
||||
static Matrix *invertGeneral(Matrix *dst, const Matrix *src);
|
||||
static void makeRotation(Matrix *dst, V3d *axis, float32 angle);
|
||||
static void makeRotation(Matrix *dst, const Quat &q);
|
||||
private:
|
||||
|
|
Loading…
Reference in New Issue