mirror of https://github.com/aap/librw.git
made almost all classes POD
This commit is contained in:
parent
36c01a4c70
commit
9a26a380a8
2
TODO
2
TODO
|
@ -10,6 +10,8 @@
|
|||
- more file formats (PNG)
|
||||
- PS2 rendering!
|
||||
- Im2d and Im3d
|
||||
- skeleton
|
||||
- examples
|
||||
|
||||
BUGS:
|
||||
- fseek with negative offset on ps2 over ps2link messes up the current position
|
||||
|
|
36
src/base.cpp
36
src/base.cpp
|
@ -33,10 +33,10 @@ bool32 streamAppendFrames = 0;
|
|||
char *debugFile = nil;
|
||||
|
||||
static Matrix identMat = {
|
||||
V3d(1.0f, 0.0f, 0.0f), Matrix::IDENTITY|Matrix::TYPEORTHONORMAL,
|
||||
V3d(0.0f, 1.0f, 0.0f), 0,
|
||||
V3d(0.0f, 0.0f, 1.0f), 0,
|
||||
V3d(0.0f, 0.0f, 0.0f), 0
|
||||
{ 1.0f, 0.0f, 0.0f }, Matrix::IDENTITY|Matrix::TYPEORTHONORMAL,
|
||||
{ 0.0f, 1.0f, 0.0f }, 0,
|
||||
{ 0.0f, 0.0f, 1.0f }, 0,
|
||||
{ 0.0f, 0.0f, 0.0f }, 0
|
||||
};
|
||||
|
||||
// lazy implementation
|
||||
|
@ -60,10 +60,10 @@ strncmp_ci(const char *s1, const char *s2, int n)
|
|||
Quat
|
||||
mult(const Quat &q, const Quat &p)
|
||||
{
|
||||
return Quat(q.w*p.w - q.x*p.x - q.y*p.y - q.z*p.z,
|
||||
q.w*p.x + q.x*p.w + q.y*p.z - q.z*p.y,
|
||||
q.w*p.y + q.y*p.w + q.z*p.x - q.x*p.z,
|
||||
q.w*p.z + q.z*p.w + q.x*p.y - q.y*p.x);
|
||||
return makeQuat(q.w*p.w - q.x*p.x - q.y*p.y - q.z*p.z,
|
||||
q.w*p.x + q.x*p.w + q.y*p.z - q.z*p.y,
|
||||
q.w*p.y + q.y*p.w + q.z*p.x - q.x*p.z,
|
||||
q.w*p.z + q.z*p.w + q.x*p.y - q.y*p.x);
|
||||
}
|
||||
|
||||
Quat
|
||||
|
@ -76,10 +76,10 @@ lerp(const Quat &q, const Quat &p, float32 r)
|
|||
c = -c;
|
||||
q1 = negate(q1);
|
||||
}
|
||||
return Quat(q1.w + r*(p.w - q1.w),
|
||||
q1.x + r*(p.x - q1.x),
|
||||
q1.y + r*(p.y - q1.y),
|
||||
q1.z + r*(p.z - q1.z));
|
||||
return makeQuat(q1.w + r*(p.w - q1.w),
|
||||
q1.x + r*(p.x - q1.x),
|
||||
q1.y + r*(p.y - q1.y),
|
||||
q1.z + r*(p.z - q1.z));
|
||||
};
|
||||
|
||||
Quat
|
||||
|
@ -108,9 +108,9 @@ slerp(const Quat &q, const Quat &p, float32 a)
|
|||
V3d
|
||||
cross(const V3d &a, const V3d &b)
|
||||
{
|
||||
return V3d(a.y*b.z - a.z*b.y,
|
||||
a.z*b.x - a.x*b.z,
|
||||
a.x*b.y - a.y*b.x);
|
||||
return makeV3d(a.y*b.z - a.z*b.y,
|
||||
a.z*b.x - a.x*b.z,
|
||||
a.x*b.y - a.y*b.x);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -457,9 +457,9 @@ Matrix::orthogonalError(void)
|
|||
float32
|
||||
Matrix::identityError(void)
|
||||
{
|
||||
V3d r(right.x-1.0, right.y, right.z);
|
||||
V3d u(up.x, up.y-1.0, up.z);
|
||||
V3d a(at.x, at.y, at.z-1.0);
|
||||
V3d r { right.x-1.0f, right.y, right.z };
|
||||
V3d u { up.x, up.y-1.0f, up.z };
|
||||
V3d a { at.x, at.y, at.z-1.0f };
|
||||
return dot(r,r) + dot(u,u) + dot(a,a) + dot(pos,pos);
|
||||
}
|
||||
|
||||
|
|
|
@ -288,8 +288,8 @@ Geometry::calculateBoundingSphere(void)
|
|||
{
|
||||
for(int32 i = 0; i < this->numMorphTargets; i++){
|
||||
MorphTarget *m = &this->morphTargets[i];
|
||||
V3d min( 1000000.0f, 1000000.0f, 1000000.0f);
|
||||
V3d max(-1000000.0f, -1000000.0f, -1000000.0f);
|
||||
V3d min { 1000000.0f, 1000000.0f, 1000000.0f };
|
||||
V3d max { -1000000.0f, -1000000.0f, -1000000.0f };
|
||||
float32 *v = m->vertices;
|
||||
for(int32 j = 0; j < this->numVertices; j++){
|
||||
if(v[0] > max.x) max.x = v[0];
|
||||
|
|
58
src/rwbase.h
58
src/rwbase.h
|
@ -91,74 +91,70 @@ struct Matrix;
|
|||
struct V2d
|
||||
{
|
||||
float32 x, y;
|
||||
// TODO: remove and make this POD
|
||||
V2d(void) : x(0.0f), y(0.0f) {}
|
||||
V2d(float32 x, float32 y) : x(x), y(y) {}
|
||||
|
||||
void set(float32 x, float32 y){
|
||||
this->x = x; this->y = y; }
|
||||
};
|
||||
|
||||
inline V2d neg(const V2d &a) { return V2d(-a.x, -a.y); }
|
||||
inline V2d add(const V2d &a, const V2d &b) { return V2d(a.x+b.x, a.y+b.y); }
|
||||
inline V2d sub(const V2d &a, const V2d &b) { return V2d(a.x-b.x, a.y-b.y); }
|
||||
inline V2d scale(const V2d &a, float32 r) { return V2d(a.x*r, a.y*r); }
|
||||
inline V2d makeV2d(float32 x, float32 y) { V2d v = { x, y }; return v; }
|
||||
inline V2d neg(const V2d &a) { return makeV2d(-a.x, -a.y); }
|
||||
inline V2d add(const V2d &a, const V2d &b) { return makeV2d(a.x+b.x, a.y+b.y); }
|
||||
inline V2d sub(const V2d &a, const V2d &b) { return makeV2d(a.x-b.x, a.y-b.y); }
|
||||
inline V2d scale(const V2d &a, float32 r) { return makeV2d(a.x*r, a.y*r); }
|
||||
inline float32 length(const V2d &v) { return sqrt(v.x*v.x + v.y*v.y); }
|
||||
inline V2d normalize(const V2d &v) { return scale(v, 1.0f/length(v)); }
|
||||
|
||||
struct V3d
|
||||
{
|
||||
float32 x, y, z;
|
||||
// TODO: remove and make this POD
|
||||
V3d(void) : x(0.0f), y(0.0f), z(0.0f) {}
|
||||
V3d(float32 x, float32 y, float32 z) : x(x), y(y), z(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);
|
||||
};
|
||||
|
||||
inline V3d neg(const V3d &a) { return V3d(-a.x, -a.y, -a.z); }
|
||||
inline V3d add(const V3d &a, const V3d &b) { return V3d(a.x+b.x, a.y+b.y, a.z+b.z); }
|
||||
inline V3d sub(const V3d &a, const V3d &b) { return V3d(a.x-b.x, a.y-b.y, a.z-b.z); }
|
||||
inline V3d scale(const V3d &a, float32 r) { return V3d(a.x*r, a.y*r, a.z*r); }
|
||||
inline V3d makeV3d(float32 x, float32 y, float32 z) { V3d v = { x, y, z }; return v; }
|
||||
inline V3d neg(const V3d &a) { return makeV3d(-a.x, -a.y, -a.z); }
|
||||
inline V3d add(const V3d &a, const V3d &b) { return makeV3d(a.x+b.x, a.y+b.y, a.z+b.z); }
|
||||
inline V3d sub(const V3d &a, const V3d &b) { return makeV3d(a.x-b.x, a.y-b.y, a.z-b.z); }
|
||||
inline V3d scale(const V3d &a, float32 r) { return makeV3d(a.x*r, a.y*r, a.z*r); }
|
||||
inline float32 length(const V3d &v) { return sqrt(v.x*v.x + v.y*v.y + v.z*v.z); }
|
||||
inline V3d normalize(const V3d &v) { return scale(v, 1.0f/length(v)); }
|
||||
inline V3d setlength(const V3d &v, float32 l) { return scale(v, l/length(v)); }
|
||||
V3d cross(const V3d &a, const V3d &b);
|
||||
inline float32 dot(const V3d &a, const V3d &b) { return a.x*b.x + a.y*b.y + a.z*b.z; }
|
||||
inline V3d lerp(const V3d &a, const V3d &b, float32 r){
|
||||
return V3d(a.x + r*(b.x - a.x),
|
||||
a.y + r*(b.y - a.y),
|
||||
a.z + r*(b.z - a.z));
|
||||
return makeV3d(a.x + r*(b.x - a.x),
|
||||
a.y + r*(b.y - a.y),
|
||||
a.z + r*(b.z - a.z));
|
||||
};
|
||||
|
||||
Quat makeQuat(float32 w, float32 x, float32 y, float32 z);
|
||||
Quat makeQuat(float32 w, const V3d &vec);
|
||||
|
||||
struct Quat
|
||||
{
|
||||
// order is important for streaming
|
||||
float32 x, y, z, w;
|
||||
Quat(void) : x(0.0f), y(0.0f), z(0.0f), w(0.0f) {}
|
||||
Quat(float32 w, float32 x, float32 y, float32 z) : x(x), y(y), z(z), w(w) {}
|
||||
Quat(float32 w, const V3d &vec) : x(vec.x), y(vec.y), z(vec.z), w(w) {}
|
||||
Quat(V3d vec) : x(vec.x), y(vec.y), z(vec.z), w(0.0f) {}
|
||||
|
||||
static Quat rotation(float32 angle, const V3d &axis){
|
||||
return Quat(cos(angle/2.0f), scale(axis, sin(angle/2.0f))); }
|
||||
return makeQuat(cos(angle/2.0f), scale(axis, sin(angle/2.0f))); }
|
||||
void set(float32 w, float32 x, float32 y, float32 z){
|
||||
this->w = w; this->x = x; this->y = y; this->z = z; }
|
||||
V3d vec(void){ return V3d(x, y, z); }
|
||||
V3d vec(void){ return makeV3d(x, y, z); }
|
||||
};
|
||||
|
||||
inline Quat add(const Quat &q, const Quat &p) { return Quat(q.w+p.w, q.x+p.x, q.y+p.y, q.z+p.z); }
|
||||
inline Quat sub(const Quat &q, const Quat &p) { return Quat(q.w-p.w, q.x-p.x, q.y-p.y, q.z-p.z); }
|
||||
inline Quat negate(const Quat &q) { return Quat(-q.w, -q.x, -q.y, -q.z); }
|
||||
inline Quat makeQuat(float32 w, float32 x, float32 y, float32 z) { Quat q = { x, y, z, w }; return q; }
|
||||
inline Quat makeQuat(float32 w, const V3d &vec) { Quat q = { vec.x, vec.y, vec.z, w }; return q; }
|
||||
inline Quat add(const Quat &q, const Quat &p) { return makeQuat(q.w+p.w, q.x+p.x, q.y+p.y, q.z+p.z); }
|
||||
inline Quat sub(const Quat &q, const Quat &p) { return makeQuat(q.w-p.w, q.x-p.x, q.y-p.y, q.z-p.z); }
|
||||
inline Quat negate(const Quat &q) { return makeQuat(-q.w, -q.x, -q.y, -q.z); }
|
||||
inline float32 dot(const Quat &q, const Quat &p) { return q.w*p.w + q.x*p.x + q.y*p.y + q.z*p.z; }
|
||||
inline Quat scale(const Quat &q, float32 r) { return Quat(q.w*r, q.x*r, q.y*r, q.z*r); }
|
||||
inline Quat scale(const Quat &q, float32 r) { return makeQuat(q.w*r, q.x*r, q.y*r, q.z*r); }
|
||||
inline float32 length(const Quat &q) { return sqrt(q.w*q.w + q.x*q.x + q.y*q.y + q.z*q.z); }
|
||||
inline Quat normalize(const Quat &q) { return scale(q, 1.0f/length(q)); }
|
||||
inline Quat conj(const Quat &q) { return Quat(q.w, -q.x, -q.y, -q.z); }
|
||||
inline Quat conj(const Quat &q) { return makeQuat(q.w, -q.x, -q.y, -q.z); }
|
||||
Quat mult(const Quat &q, const Quat &p);
|
||||
inline V3d rotate(const V3d &v, const Quat &q) { return mult(mult(q, Quat(v)), conj(q)).vec(); }
|
||||
inline V3d rotate(const V3d &v, const Quat &q) { return mult(mult(q, makeQuat(0.0f, v)), conj(q)).vec(); }
|
||||
Quat lerp(const Quat &q, const Quat &p, float32 r);
|
||||
Quat slerp(const Quat &q, const Quat &p, float32 a);
|
||||
|
||||
|
|
Loading…
Reference in New Issue