SMG-Decomp
A decompilation of Super Mario Galaxy 1
Loading...
Searching...
No Matches
ClipAreaShape.cpp
1#include "Game/MapObj/ClipAreaShape.hpp"
2#include <Game/Util.hpp>
3
4ClipAreaShape::ClipAreaShape(const char *pName) : mModelData(nullptr) {
5 mModelData = MR::getJ3DModelData(pName);
6}
7
8bool ClipAreaShape::isInArea(const TVec3f &a1, f32 a2, const TPos3f &a3, const TVec3f &a4) const {
9 if (MR::isNearZero(a4.x, 0.001f) || (MR::isNearZero(a4.y, 0.001f) || MR::isNearZero(a4.z, 0.001f))) {
10 return false;
11 }
12
13 TPos3f mtx;
14 mtx.identity();
15 mtx.invert(a3);
16 TVec3f srcVec;
17 mtx.mult(a1, srcVec);
18
19 srcVec.x = (srcVec.x / a4.x);
20 srcVec.y = (srcVec.y / a4.y);
21 srcVec.z = (srcVec.z / a4.z);
22 return isInArea(srcVec);
23}
24
25void ClipAreaShape::calcVolumeMatrix(TPos3f *pVolMtx, const TPos3f &rSrcMtx, const TVec3f &a3) const {
26 pVolMtx->set(rSrcMtx);
27 MR::preScaleMtx(pVolMtx->toMtxPtr(), a3);
28}
29
30void ClipAreaShape::drawVolumeShape(const TPos3f &rMtx, const TVec3f &rPos) const {
31 TPos3f volMtx;
32 volMtx.identity();
33 calcVolumeMatrix(&volMtx, rMtx, rPos);
34 PSMTXConcat(MR::getCameraViewMtx(), *volMtx.toCMtx(), *volMtx.toMtx());
35 GXLoadPosMtxImm(volMtx.toMtxPtr(), 0);
36 MR::drawSimpleModel(mModelData);
37}
38
39bool ClipAreaShapeSphere::isInArea(register const TVec3f &rVec) const {
40 register const ClipAreaShapeSphere* sphere = this;
41
42 __asm volatile {
43 psq_l f1, 0(rVec), 0, 0
44 lfs f0, sphere->mRadius
45 ps_mul f1, f1, f1
46 lfs f2, 8(rVec)
47 ps_madd f2, f2, f2, f1
48 ps_sum0 f2, f2, f1, f1
49 fcmpo, cr0, f2, f0
50 mfcr r3
51 srwi r3, r3, 31
52 blr
53 };
54}
55
56ClipAreaShapeCone::ClipAreaShapeCone(s32 a1) : ClipAreaShape("ClipVolumeSphere") {
57 _8 = 500.0f;
58 _C = 1000.0f;
59 _10 = a1;
60}
61
62bool ClipAreaShapeCone::isInArea(const TVec3f &rVec) const {
63 f32 v3 = (rVec.y / _C);
64
65 if (!MR::isInRange(v3, 0.0f, 1.0f)) {
66 return false;
67 }
68
69 if (_10 == 1) {
70 v3 = (1.0f - v3);
71 }
72
73 f32 v23 = ((rVec.x * rVec.x) + (rVec.z * rVec.z));
74 f32 v24 = (v3 * _8) * (v3 * _8);
75 return v23 == v24;
76}
77
78bool ClipAreaShape::isInArea(const TVec3f &) const {
79 return false;
80}