made almost all classes POD

This commit is contained in:
aap 2017-08-04 21:47:15 +02:00
parent 36c01a4c70
commit 9a26a380a8
4 changed files with 49 additions and 51 deletions

2
TODO
View File

@ -10,6 +10,8 @@
- more file formats (PNG) - more file formats (PNG)
- PS2 rendering! - PS2 rendering!
- Im2d and Im3d - Im2d and Im3d
- skeleton
- examples
BUGS: BUGS:
- fseek with negative offset on ps2 over ps2link messes up the current position - fseek with negative offset on ps2 over ps2link messes up the current position

View File

@ -33,10 +33,10 @@ bool32 streamAppendFrames = 0;
char *debugFile = nil; char *debugFile = nil;
static Matrix identMat = { static Matrix identMat = {
V3d(1.0f, 0.0f, 0.0f), Matrix::IDENTITY|Matrix::TYPEORTHONORMAL, { 1.0f, 0.0f, 0.0f }, Matrix::IDENTITY|Matrix::TYPEORTHONORMAL,
V3d(0.0f, 1.0f, 0.0f), 0, { 0.0f, 1.0f, 0.0f }, 0,
V3d(0.0f, 0.0f, 1.0f), 0, { 0.0f, 0.0f, 1.0f }, 0,
V3d(0.0f, 0.0f, 0.0f), 0 { 0.0f, 0.0f, 0.0f }, 0
}; };
// lazy implementation // lazy implementation
@ -60,10 +60,10 @@ strncmp_ci(const char *s1, const char *s2, int n)
Quat Quat
mult(const Quat &q, const Quat &p) 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, 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.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.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); q.w*p.z + q.z*p.w + q.x*p.y - q.y*p.x);
} }
Quat Quat
@ -76,10 +76,10 @@ lerp(const Quat &q, const Quat &p, float32 r)
c = -c; c = -c;
q1 = negate(q1); q1 = negate(q1);
} }
return Quat(q1.w + r*(p.w - q1.w), return makeQuat(q1.w + r*(p.w - q1.w),
q1.x + r*(p.x - q1.x), q1.x + r*(p.x - q1.x),
q1.y + r*(p.y - q1.y), q1.y + r*(p.y - q1.y),
q1.z + r*(p.z - q1.z)); q1.z + r*(p.z - q1.z));
}; };
Quat Quat
@ -108,9 +108,9 @@ slerp(const Quat &q, const Quat &p, float32 a)
V3d V3d
cross(const V3d &a, const V3d &b) cross(const V3d &a, const V3d &b)
{ {
return V3d(a.y*b.z - a.z*b.y, return makeV3d(a.y*b.z - a.z*b.y,
a.z*b.x - a.x*b.z, a.z*b.x - a.x*b.z,
a.x*b.y - a.y*b.x); a.x*b.y - a.y*b.x);
} }
void void
@ -457,9 +457,9 @@ Matrix::orthogonalError(void)
float32 float32
Matrix::identityError(void) Matrix::identityError(void)
{ {
V3d r(right.x-1.0, right.y, right.z); V3d r { right.x-1.0f, right.y, right.z };
V3d u(up.x, up.y-1.0, up.z); V3d u { up.x, up.y-1.0f, up.z };
V3d a(at.x, at.y, at.z-1.0); V3d a { at.x, at.y, at.z-1.0f };
return dot(r,r) + dot(u,u) + dot(a,a) + dot(pos,pos); return dot(r,r) + dot(u,u) + dot(a,a) + dot(pos,pos);
} }

View File

@ -288,8 +288,8 @@ Geometry::calculateBoundingSphere(void)
{ {
for(int32 i = 0; i < this->numMorphTargets; i++){ for(int32 i = 0; i < this->numMorphTargets; i++){
MorphTarget *m = &this->morphTargets[i]; MorphTarget *m = &this->morphTargets[i];
V3d min( 1000000.0f, 1000000.0f, 1000000.0f); V3d min { 1000000.0f, 1000000.0f, 1000000.0f };
V3d max(-1000000.0f, -1000000.0f, -1000000.0f); V3d max { -1000000.0f, -1000000.0f, -1000000.0f };
float32 *v = m->vertices; float32 *v = m->vertices;
for(int32 j = 0; j < this->numVertices; j++){ for(int32 j = 0; j < this->numVertices; j++){
if(v[0] > max.x) max.x = v[0]; if(v[0] > max.x) max.x = v[0];

View File

@ -91,74 +91,70 @@ struct Matrix;
struct V2d struct V2d
{ {
float32 x, y; 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){ void set(float32 x, float32 y){
this->x = x; this->y = y; } this->x = x; this->y = y; }
}; };
inline V2d neg(const V2d &a) { return V2d(-a.x, -a.y); } inline V2d makeV2d(float32 x, float32 y) { V2d v = { x, y }; return v; }
inline V2d add(const V2d &a, const V2d &b) { return V2d(a.x+b.x, a.y+b.y); } inline V2d neg(const V2d &a) { return makeV2d(-a.x, -a.y); }
inline V2d sub(const V2d &a, const V2d &b) { return V2d(a.x-b.x, a.y-b.y); } inline V2d add(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 V2d(a.x*r, a.y*r); } 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 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)); } inline V2d normalize(const V2d &v) { return scale(v, 1.0f/length(v)); }
struct V3d struct V3d
{ {
float32 x, y, z; 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){ void set(float32 x, float32 y, float32 z){
this->x = x; this->y = y; this->z = z; } this->x = x; this->y = y; this->z = z; }
static void transformPoints(V3d *out, V3d *in, int32 n, Matrix *m); static void transformPoints(V3d *out, V3d *in, int32 n, Matrix *m);
static void transformVectors(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 makeV3d(float32 x, float32 y, float32 z) { V3d v = { x, y, z }; return v; }
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 neg(const V3d &a) { return makeV3d(-a.x, -a.y, -a.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 add(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 V3d(a.x*r, a.y*r, a.z*r); } 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 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 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)); } inline V3d setlength(const V3d &v, float32 l) { return scale(v, l/length(v)); }
V3d cross(const V3d &a, const V3d &b); 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 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){ inline V3d lerp(const V3d &a, const V3d &b, float32 r){
return V3d(a.x + r*(b.x - a.x), return makeV3d(a.x + r*(b.x - a.x),
a.y + r*(b.y - a.y), a.y + r*(b.y - a.y),
a.z + r*(b.z - a.z)); 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 struct Quat
{ {
// order is important for streaming // order is important for streaming
float32 x, y, z, w; 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){ 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){ void set(float32 w, float32 x, float32 y, float32 z){
this->w = w; this->x = x; this->y = y; this->z = 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 makeQuat(float32 w, float32 x, float32 y, float32 z) { Quat q = { x, y, z, w }; return q; }
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 makeQuat(float32 w, const V3d &vec) { Quat q = { vec.x, vec.y, vec.z, w }; return q; }
inline Quat negate(const Quat &q) { return Quat(-q.w, -q.x, -q.y, -q.z); } 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 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 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 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); 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 lerp(const Quat &q, const Quat &p, float32 r);
Quat slerp(const Quat &q, const Quat &p, float32 a); Quat slerp(const Quat &q, const Quat &p, float32 a);