diff options
-rw-r--r-- | src/GameTick.cpp | 2 | ||||
-rw-r--r-- | src/Models.cpp | 8 | ||||
-rw-r--r-- | src/Quaternions.cpp | 21 | ||||
-rw-r--r-- | src/Quaternions.h | 28 | ||||
-rw-r--r-- | src/cimport.zig | 1 |
5 files changed, 22 insertions, 38 deletions
diff --git a/src/GameTick.cpp b/src/GameTick.cpp index 8adbbfe..c4fff12 100644 --- a/src/GameTick.cpp +++ b/src/GameTick.cpp @@ -436,7 +436,7 @@ void Game::Tick() if (timeremaining <= 0) { score += ++mission * 50 + 100; - highscore = max(score, highscore); + highscore = std::max(score, highscore); flashamount = flashg = 1; flashr = flashb = 0; diff --git a/src/Models.cpp b/src/Models.cpp index 6632562..ad0f357 100644 --- a/src/Models.cpp +++ b/src/Models.cpp @@ -54,7 +54,7 @@ void Model::CalculateNormals() boundingsphereradius = 0; for (int i = 0; i < vertexNum; ++i) - boundingsphereradius = max(boundingsphereradius, + boundingsphereradius = std::max(boundingsphereradius, findDistancefast(boundingspherecenter, vertex[i])); boundingsphereradius = sqrt(boundingsphereradius); } @@ -186,7 +186,11 @@ int Model::LineCheck2(XYZ *p1,XYZ *p2, XYZ *p, XYZ *move, float *rotate) boundingspherecenter.x,boundingspherecenter.y,boundingspherecenter.z, boundingsphereradius)) for (j=0;j<TriangleNum;j++){ - intersecting=LineFacetd(p1,p2,&vertex[Triangles[j].vertex[0]],&vertex[Triangles[j].vertex[1]],&vertex[Triangles[j].vertex[2]],&normals[j],&point); + intersecting = LineFacetd(*p1, *p2, + vertex[Triangles[j].vertex[0]], + vertex[Triangles[j].vertex[1]], + vertex[Triangles[j].vertex[2]], + normals[j], &point); if (intersecting == 0) continue; distance=(point.x-p1->x)*(point.x-p1->x)+(point.y-p1->y)*(point.y-p1->y)+(point.z-p1->z)*(point.z-p1->z); if((distance<olddistance||firstintersecting==-1)&&intersecting){olddistance=distance; firstintersecting=j; *p=point;} diff --git a/src/Quaternions.cpp b/src/Quaternions.cpp index 0bd0442..6fe85bf 100644 --- a/src/Quaternions.cpp +++ b/src/Quaternions.cpp @@ -117,27 +117,6 @@ float LineFacetd(XYZ p1,XYZ p2,XYZ pa,XYZ pb,XYZ pc, XYZ n, XYZ *p) return 1; } -float LineFacetd(XYZ *p1,XYZ *p2,XYZ *pa,XYZ *pb,XYZ *pc, XYZ *n, XYZ *p) -{ - - //Calculate the parameters for the plane - d = - n->x * pa->x - n->y * pa->y - n->z * pa->z; - - //Calculate the position on the line that intersects the plane - denom = n->x * (p2->x - p1->x) + n->y * (p2->y - p1->y) + n->z * (p2->z - p1->z); - if (abs(denom) < 0.0000001) // Line and plane don't intersect - return 0; - mu = - (d + n->x * p1->x + n->y * p1->y + n->z * p1->z) / denom; - p->x = p1->x + mu * (p2->x - p1->x); - p->y = p1->y + mu * (p2->y - p1->y); - p->z = p1->z + mu * (p2->z - p1->z); - if (mu < 0 || mu > 1) // Intersection not along line segment - return 0; - - if(!PointInTriangle( p, *n, pa, pb, pc)){return 0;} - return 1; -} - void ReflectVector(XYZ *vel, XYZ *n) { XYZ vn; diff --git a/src/Quaternions.h b/src/Quaternions.h index 8cf1eff..ee3e876 100644 --- a/src/Quaternions.h +++ b/src/Quaternions.h @@ -1,8 +1,6 @@ #ifndef BLACKSHADES_QUATERNIONS_H #define BLACKSHADES_QUATERNIONS_H -using namespace std; - struct XYZ { float x, y, z; }; @@ -38,23 +36,25 @@ constexpr XYZ& operator-=(XYZ& u, const XYZ& v) { return u = u - v; } constexpr XYZ& operator*=(XYZ& u, const XYZ& v) { return u = u * v; } constexpr XYZ& operator*=(XYZ& u, float k) { return u = u * k; } constexpr XYZ& operator/=(XYZ& u, float k) { return u = u / k; } - -float LineFacetd(XYZ p1, XYZ p2, XYZ pa, XYZ pb, XYZ pc, XYZ n, XYZ* p); -float LineFacetd(XYZ* p1, XYZ* p2, XYZ* pa, XYZ* pb, XYZ* pc, XYZ* n, XYZ* p); #endif // __cplusplus #ifdef __cplusplus extern "C" { #endif // __cplusplus - void CrossProduct(XYZ P, XYZ Q, XYZ *V); - void Normalise(XYZ *vectory); - bool PointInTriangle(XYZ *p, XYZ normal, XYZ *p1, XYZ *p2, XYZ *p3); - void ReflectVector(XYZ *vel, XYZ *n); - XYZ DoRotation(XYZ thePoint, float xang, float yang, float zang); - float findDistance(XYZ point1, XYZ point2); - float findLengthfast(XYZ point1); - float findDistancefast(XYZ point1, XYZ point2); - float dotproduct(XYZ point1, XYZ point2); + void CrossProduct(struct XYZ P, struct XYZ Q, struct XYZ *V); + void Normalise(struct XYZ *vectory); + bool PointInTriangle(struct XYZ *p, struct XYZ normal, + struct XYZ *p1, struct XYZ *p2, struct XYZ *p3); + float LineFacetd(struct XYZ p1, struct XYZ p2, + struct XYZ pa, struct XYZ pb, struct XYZ pc, + struct XYZ n, struct XYZ *p); + void ReflectVector(struct XYZ *vel, struct XYZ *n); + struct XYZ DoRotation(struct XYZ thePoint, + float xang, float yang, float zang); + float findDistance(struct XYZ point1, struct XYZ point2); + float findLengthfast(struct XYZ point1); + float findDistancefast(struct XYZ point1, struct XYZ point2); + float dotproduct(struct XYZ point1, struct XYZ point2); bool sphere_line_intersection(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3, float r); diff --git a/src/cimport.zig b/src/cimport.zig index b5d66e9..efde6b7 100644 --- a/src/cimport.zig +++ b/src/cimport.zig @@ -1,4 +1,5 @@ usingnamespace @cImport({ @cInclude("Game.h"); @cInclude("Constants.h"); + @cInclude("Quaternions.h"); }); |