diff --git a/src/SB/Core/x/xClumpColl.h b/src/SB/Core/x/xClumpColl.h index 982d7beb1..75f564470 100644 --- a/src/SB/Core/x/xClumpColl.h +++ b/src/SB/Core/x/xClumpColl.h @@ -40,6 +40,16 @@ struct xClumpCollBSPTree xClumpCollBSPTriangle* triangles; }; +struct xClumpCollV3dGradient +{ + F32 dydx; + F32 dzdx; + F32 dxdy; + F32 dzdy; + F32 dxdz; + F32 dydz; +}; + struct nodeInfo { U32 type; @@ -61,5 +71,13 @@ struct TempAtomicList void xClumpColl_InstancePointers(xClumpCollBSPTree* tree, RpClump* clump); xClumpCollBSPTree* xClumpColl_StaticBufferInit(void* data, U32 param_2); +void xClumpColl_ForAllCapsuleLeafNodeIntersections( + xClumpCollBSPTree* tree, + RwLine* line, + F32 dist, + xClumpCollV3dGradient* grad, + int (*tri)(xClumpCollBSPTriangle*, void*), + void* data +); #endif diff --git a/src/SB/Core/x/xCollide.cpp b/src/SB/Core/x/xCollide.cpp index 7e63b2888..00f77dcf3 100644 --- a/src/SB/Core/x/xCollide.cpp +++ b/src/SB/Core/x/xCollide.cpp @@ -2,10 +2,13 @@ #include "zSurface.h" #include "iCollide.h" #include "iMath3.h" +#include "rpcollis.h" +#include "xMathInlines.h" +#include #include -// extern F32 lbl_803CCAA8; // 0.0 +S32 sSweptSphereHitFound; _xCollsIdx xCollideGetCollsIdx(const xCollis* coll, const xVec3* tohit, const xMat3x3* mat) { @@ -241,6 +244,16 @@ U32 xSphereHitsSphere(const xSphere* a, const xSphere* b, xCollis* coll) return uVar1; } +U32 xSphereHitsOBB_nu(const xSphere*, const xBox*, const xMat4x3*, xCollis*) +{ + return 0; +} + +U32 xSphereHitsModel(const xSphere*, const xModelInstance*, xCollis*) +{ + return false; +} + void xParabolaRecenter(xParabola* p, F32 newZeroT) { xVec3 newPos; @@ -251,7 +264,384 @@ void xParabolaRecenter(xParabola* p, F32 newZeroT) xVec3Copy(&p->initPos, &newPos); xVec3Copy(&p->initVel, &newVel); - + p->maxTime -= newZeroT; p->minTime -= newZeroT; } + +S32 xParabolaHitsEnv(xParabola*, const xEnv*, xCollis*) +{ + return false; +} + + + +U32 xBoxHitsObb(const xBox*, const xBox*, const xMat4x3*, xCollis*) +{ + return 0; +} + +void xCollideCalcTri(xCollis::tri_data&, const xModelInstance&, const xVec3&, const xVec3&) +{ +} + +xVec3 xCollisTriHit(const xCollis::tri_data&, const xModelInstance&) +{ + return xVec3(); +} + +struct RpCollBSPTree; +struct RpV3dGradient; + +RpCollBSPTree* _rpCollBSPTreeForAllCapsuleLeafNodeIntersections( + RpCollBSPTree* tree, + RwLine* line, + F32 radius, + RpV3dGradient* grad, + S32 (* callBack)(S32, S32, void*), + void* data) +{ + return NULL; +} + +void xSweptSpherePrepare(xSweptSphere*, xVec3*, xVec3*, F32) +{ +} + +void xSweptSphereGetResults(xSweptSphere*) +{ +} + +S32 xSweptSphereToTriangle(xSweptSphere*, xVec3*, xVec3*, xVec3*) +{ + return 0; +} + +void xsqrtfast(F32& out, F32 in) +{ + out = std::sqrtf(in); +} + +// We don't have the implementation provided +F32 std::sqrtf(F32 x) +{ + if (x > 0.0f) + { + F64 guess = __frsqrte(x); + guess = 0.5 * guess * -(guess * guess * x - 3); + guess = 0.5 * guess * -(guess * guess * x - 3); + guess = 0.5 * guess * -(guess * guess * x - 3); + return x * guess; + } + else + { + return x; + } +} + +S32 xSweptSphereToBox(xSweptSphere*, xBox*, xMat4x3*) +{ + return 0; +} + +RpCollisionTriangle* SweptSphereHitsEnvCB( + RpIntersection* intersection, RpWorldSector* sector, RpCollisionTriangle* collTriangle, + RwReal distance, void* data) +{ + return NULL; +} + +S32 SweptSphereLeafNodeCB(xClumpCollBSPTriangle*, void*) +{ + return 0; +} + +S32 xSweptSphereToEnv(xSweptSphere* sphere, xEnv* env) +{ + if (sphere->dist == 0.0f) + return 0; + + sSweptSphereHitFound = 0; + if (env->geom->jsp) + { + RwLine line; + line.start = *(RwV3d*)(&sphere->start); + line.end = *(RwV3d*)(&sphere->end); + + xClumpCollV3dGradient gradient; + F32 delx = line.end.x - line.start.x; + F32 dely = line.end.y - line.start.y; + F32 delz = line.end.z - line.start.z; + + F32 xfactor = 0.0f; + if (delx != 0.0f) + { + xfactor = 1.0f / delx; + } + gradient.dydx = dely * xfactor; + gradient.dzdx = delz * xfactor; + + F32 yfactor = 0.0f; + if (dely != 0.0f) + { + yfactor = 1.0f / dely; + } + gradient.dxdy = delx * yfactor; + gradient.dzdy = delz * yfactor; + + F32 zfactor = 0.0f; + if (delz != 0.0f) + { + zfactor = 1.0f / delz; + } + gradient.dxdz = delx * zfactor; + gradient.dydz = dely * zfactor; + + xClumpColl_ForAllCapsuleLeafNodeIntersections( + env->geom->jsp->colltree, + &line, + sphere->radius, + &gradient, + SweptSphereLeafNodeCB, + sphere + ); + } + else + { + RpIntersection intersect; + intersect.type = rpINTERSECTBOX; + // Cast here suggests that the type of xSweptSphere::box may actually be + // some struct with RwV3ds in it instead of an xBox. + intersect.t.box.sup = *(RwV3d*)(&sphere->box.upper); + intersect.t.box.inf = *(RwV3d*)(&sphere->box.lower); + RpCollisionWorldForAllIntersections(env->geom->world, &intersect, + SweptSphereHitsEnvCB, sphere); + } + return sSweptSphereHitFound; +} + +S32 xSweptSphereToModel(xSweptSphere*, RpAtomic*, RwMatrixTag*) +{ + return 0; +} + +S32 xSweptSphereToScene(xSweptSphere*, xScene*, xEnt*, unsigned char) +{ + return 0; +} + +S32 xSweptSphereToStatDyn(xSweptSphere*, xScene*, xEnt*, unsigned char) +{ + return 0; +} + +S32 xSweptSphereToNPC(xSweptSphere*, xScene*, xEnt*, unsigned char) +{ + return 0; +} + +S32 xSweptSphereToNonMoving(xSweptSphere*, xScene*, xEnt*, unsigned char) +{ + return 0; +} + +void xSphereHitsBound(const xSphere&, const xBound&) +{ +} + +bool xOBBHitsOBB(const xBox&, const xMat4x3&, const xBox&, const xMat4x3&) +{ + return false; +} + +bool xSphereHitsVCylinder(const xVec3&, F32, const xVec3&, F32, F32) +{ + return false; +} + +bool xSphereHitsVCircle(const xVec3&, F32, const xVec3&, F32) +{ + return false; +} + +void xVec3AddScaled(xVec3* o, const xVec3* v, F32 s) +{ + o->x += v->x * s; + o->y += v->y * s; + o->z += v->z * s; +} + +void xVec3Cross(xVec3* o, const xVec3* a, const xVec3* b) +{ + o->x = a->y * b->z - b->y * a->z; + o->y = a->z * b->x - b->z * a->x; + o->z = a->x * b->y - b->x * a->y; +} + +F32 xVec3Length2(const xVec3* vec) +{ + return vec->x * vec->x + vec->y * vec->y + vec->z * vec->z; +} + +F32 xVec3Dist(const xVec3* a, const xVec3* b) +{ + F32 dx = a->x - b->x; + F32 dy = a->y - b->y; + F32 dz = a->z - b->z; + return xsqrt(dx * dx + dy * dy + dz * dz); +} + +void xMat4x3OrthoInv(xMat4x3* a,const xMat4x3* b) +{ + xVec3 vec; + xMat3x3Transpose(a, b); + xMat3x3RMulVec(&vec, a, &b->pos); + xVec3Inv(&a->pos, &vec); +} + +F32 xMat3x3LookVec3(xMat3x3& mat, const xVec3& at) +{ + F32 len = at.length(); + if (len >= -0.0000099999997f && len <= 0.0000099999997f) + { + mat = g_I3; + len = 0.0f; + } + else + { + mat.at = at; + mat.at *= 1.0f / len; + F32 absx = xabs(mat.at.x); + F32 absy = xabs(mat.at.y); + F32 absz = xabs(mat.at.z); + if (absx < absy && absx < absz) + { + mat.right.assign(0.0f, absz, -absy); + } + else + { + if (absy < absz) + { + mat.right.assign(-mat.at.z, 0.0f, mat.at.x); + } + else + { + mat.right.assign(mat.at.y, -mat.at.x, 0.0f); + } + } + mat.right.normalize(); + mat.up = mat.at.cross(mat.right); + } + return len; +} + +void xModelAnimCollRestore(const xModelInstance&) +{ +} + +void xModelAnimCollApply(const xModelInstance&) +{ +} + +bool xModelAnimCollDirty(const xModelInstance&) +{ + return false; +} + +// Make these into inline definitions somewhere appropriate later +xVec3 xVec3::operator+(const xVec3& v) const +{ + xVec3 vec = *this; + vec += v; + return vec; +} + +xVec3& xVec3::operator+=(const xVec3& v) +{ + x += v.x; + y += v.y; + z += v.z; + return *this; +} + +xVec3 xVec3::get_abs() const +{ + xVec3 vec = *this; + return vec.set_abs(); +} + +xVec3& xVec3::set_abs() +{ + x = xabs(x); + y = xabs(y); + z = xabs(z); + return *this; +} + +F32 xVec3::dot(const xVec3& v) const +{ + return x * v.x + y * v.y + z * v.z; +} + +xVec3& xVec3::normalize() +{ + *this /= length(); + return *this; +} + +xVec3 xVec3::operator/(F32 f) const +{ + xVec3 vec = *this; + vec /= f; + return vec; +} + +void xParabolaEvalVel(const xParabola*, xVec3*, F32) +{ +} + +void xParabolaEvalPos(const xParabola*, xVec3*, F32) +{ +} + +bool xSphereHitsOBB(const xSphere&, const xBox&, const xMat4x3&) +{ + return false; +} + +bool xSphereHitsSphere(const xVec3&, F32, const xVec3&, F32) +{ + return false; +} + +void xQuickCullForRay(xQCData*, const xRay3*) +{ +} + +void xQuickCullForBox(xQCData*, const xBox*) +{ +} + +U8 xSphereHitsCapsule(const xVec3&, F32, const xVec3&, const xVec3&, F32) +{ + return 0; +} + +F32 xVec2::length2() const +{ + return x * x + y * y; +} + +xVec2 xVec2::operator-(const xVec2& v) const +{ + xVec2 vec = *this; + vec -= v; + return vec; +} + +xVec2& xVec2::operator-=(const xVec2& v) +{ + x -= v.x; + y -= v.y; + return *this; +} diff --git a/src/SB/Core/x/xMath2.h b/src/SB/Core/x/xMath2.h index 81f9367d2..8ec004b54 100644 --- a/src/SB/Core/x/xMath2.h +++ b/src/SB/Core/x/xMath2.h @@ -15,6 +15,7 @@ template struct basic_rect basic_rect& assign(T x, T y, T w, T h); basic_rect& contract(T x, T y, T w, T h); + basic_rect& expand(T x, T y, T w, T h); basic_rect& move(T x, T y); basic_rect& scale(T s); basic_rect& scale(T x, T y); @@ -41,6 +42,7 @@ struct xVec2 } xVec2& assign(F32 x, F32 y); F32 length() const; + F32 length2() const; F32 normal() const; xVec2& normalize(); F32 dot(const xVec2&) const; @@ -50,6 +52,8 @@ struct xVec2 xVec2 operator/=(F32); xVec2& operator+=(const xVec2&); xVec2& operator*=(F32); + xVec2& operator-=(const xVec2&); + xVec2 operator-(const xVec2&) const; }; F32 xVec2Dist(F32 x1, F32 y1, F32 x2, F32 y2); diff --git a/src/SB/Core/x/xMath3.cpp b/src/SB/Core/x/xMath3.cpp index a612628d9..0daf9e6ea 100644 --- a/src/SB/Core/x/xMath3.cpp +++ b/src/SB/Core/x/xMath3.cpp @@ -11,7 +11,15 @@ //#include "xVec3Inlines.h" // xVec3Init, imported, realized xClimate has a declaration as well though. const xVec3 g_O3 = { 0, 0, 0 }; +const xVec3 g_X3 = { 1, 0, 0 }; +const xVec3 g_Y3 = { 0, 1, 0 }; +const xVec3 g_Z3 = { 0, 0, 1 }; +const xVec3 g_NX3 = { -1, 0, 0 }; +const xVec3 g_NY3 = { 0, -1, 0 }; +const xVec3 g_NZ3 = { 0, 0, -1 }; +const xVec3 g_Onez = { 1, 1, 1 }; const xQuat g_IQ = { 0.0f, 0.0f, 0.0f, 1.0f }; +xMat4x3 g_I3; S32 xPointInBox(const xBox* b, const xVec3* p) { @@ -29,10 +37,6 @@ S32 xPointInBox(const xBox* b, const xVec3* p) return (char)ret; } -void xMat4x3Copy(xMat4x3* o, const xMat4x3* m) -{ -} - void xMat4x3Rot(xMat4x3* m, const xVec3* a, F32 t, const xVec3* p) { xMat4x3 temp; @@ -87,10 +91,6 @@ void xMat3x3Euler(xMat3x3* m, F32 yaw, F32 pitch, F32 roll) m->flags = 0; } -void xMat4x3Toworld(xVec3* o, const xMat4x3* m, const xVec3* v) -{ -} - /* xMat3x3RotC (xMat3x3 *, float, float, float, float) */ void xMat3x3RotC(xMat3x3* m, F32 _x, F32 _y, F32 _z, F32 t) { @@ -169,14 +169,6 @@ void xMat3x3RotZ(xMat3x3* m, F32 t) m->flags = 0; } -void xMat3x3MulRotC(xMat3x3* o, xMat3x3* m, F32 _x, F32 _y, F32 _z, F32 t) -{ -} - -void xMat4x3Identity(xMat4x3* m) -{ -} - /* xMat3x3Normalize (xMat3x3 *, xMat3x3 const *) */ void xMat3x3Normalize(xMat3x3* o, const xMat3x3* m) { @@ -185,10 +177,6 @@ void xMat3x3Normalize(xMat3x3* o, const xMat3x3* m) xVec3Normalize(&o->at, &m->at); } -void xMat4x3Tolocal(xVec3* o, const xMat4x3* m, const xVec3* v) -{ -} - /* xMat3x3Tolocal (xVec3 *, xMat3x3 const *, xVec3 const *) */ void xMat3x3Tolocal(xVec3* o, const xMat3x3* m, const xVec3* v) { @@ -327,13 +315,6 @@ void xQuatDiff(xQuat* o, const xQuat* a, const xQuat* b) } } -F32 xQuatGetAngle(const xQuat* q) -{ - F32 angle; - angle = 5.0; - return angle; -} - /* xQuatFromMat (xQuat *, xMat3x3 const *) */ void xQuatFromMat(xQuat* q, const xMat3x3* m) { @@ -497,10 +478,6 @@ void xQuatMul(xQuat* o, const xQuat* a, const xQuat* b) xQuatNormalize(o, o); } -void xQuatConj(xQuat* o, const xQuat* q) -{ -} - /* xQuatSMul (xQuat *, xQuat const *, float) */ void xQuatSMul(xQuat* q, const xQuat* a, F32 t) { @@ -515,10 +492,6 @@ void xQuatAdd(xQuat* q, const xQuat* a, const xQuat* b) xVec3Add((xVec3*)q, (xVec3*)a, (xVec3*)b); } -void xMat3x3LookAt(xMat3x3* m, const xVec3* pos, const xVec3* at) -{ -} - /* xMat3x3LookVec (xMat3x3 *, xVec3 const *) */ F32 xMat3x3LookVec(xMat3x3* m, const xVec3* at) { @@ -578,14 +551,6 @@ F32 xMat3x3LookVec(xMat3x3* m, const xVec3* at) return temp_f31; } -void xBoxInitBoundOBB(xBox* o, const xBox* b, const xMat4x3* m) -{ -} - -void xMat3x3Scale(xMat3x3* m, const xVec3* s) -{ -} - /* xMat3x3ScaleC (xMat3x3 *, float, float, float) */ void xMat3x3ScaleC(xMat3x3* m, F32 x, F32 y, F32 z) { @@ -742,14 +707,6 @@ void xMat3x3SMul(xMat3x3*, const xMat3x3*, F32) { } -void xBoxFromLine(xBox& box, const xLine3& line) -{ -} - -void xBoxFromRay(xBox& box, const xRay3& ray) -{ -} - void xBoxUnion(xBox& a, const xBox& b, const xBox& c) { a.upper.x = MAX(b.upper.x, c.upper.x); diff --git a/src/SB/Core/x/xMath3.h b/src/SB/Core/x/xMath3.h index dbfda11a5..c7cc0d56c 100644 --- a/src/SB/Core/x/xMath3.h +++ b/src/SB/Core/x/xMath3.h @@ -80,12 +80,14 @@ struct xRay3; extern const xQuat g_IQ; extern const xVec3 g_O3; -extern xVec3 g_X3; -extern xVec3 g_Y3; -extern xVec3 g_NY3; -extern xVec3 g_Z3; +extern const xVec3 g_X3; +extern const xVec3 g_Y3; +extern const xVec3 g_Z3; +extern const xVec3 g_NX3; +extern const xVec3 g_NY3; +extern const xVec3 g_NZ3; +extern const xVec3 g_Onez; extern xMat4x3 g_I3; -extern xVec3 g_Onez; void xMat3x3Copy(xMat3x3* o, const xMat3x3* m); // TODO: These functions should be inline void xMat4x3Copy(xMat4x3* o, const xMat4x3* m); @@ -107,6 +109,7 @@ void xMat4x3MoveLocalUp(xMat4x3* m, F32 mag); void xMat4x3OrthoInv(xMat4x3* o, const xMat4x3* m); void xMat3x3GetEuler(const xMat3x3* m, xVec3* a); void xMat3x3Euler(xMat3x3* m, const xVec3* ypr); +void xMat3x3Transpose(xMat3x3* o, const xMat3x3* m); void xQuatToMat(const xQuat* q, xMat3x3* m); void xQuatDiff(xQuat* o, const xQuat* a, const xQuat* b); F32 xQuatGetAngle(const xQuat* q); diff --git a/src/SB/Core/x/xVec3.h b/src/SB/Core/x/xVec3.h index 455055d47..b711e7d36 100644 --- a/src/SB/Core/x/xVec3.h +++ b/src/SB/Core/x/xVec3.h @@ -27,6 +27,7 @@ struct xVec3 xVec3 operator+(const xVec3&) const; xVec3 operator-(const xVec3&) const; xVec3 operator*(F32) const; + xVec3 operator/(F32) const; xVec3& operator+=(const xVec3&); xVec3& operator+=(F32 f) { @@ -73,6 +74,8 @@ struct xVec3 xVec3& normalize(); xVec3& assign(F32 val); + xVec3 get_abs() const; + xVec3& set_abs(); }; F32 xVec3Normalize(xVec3* o, const xVec3* v);