summaryrefslogtreecommitdiff
path: root/include/SSystem/SComponent/c_m3d_g_pla.h
blob: 007ae69c22a64ca851d3c713e5dc9d7023dd9ea0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#ifndef C_M3D_G_PLA_H_
#define C_M3D_G_PLA_H_

#include "SSystem/SComponent/c_xyz.h"
#include "SSystem/SComponent/c_m3d.h"
#include "dolphin/mtx/vec.h"
#include "global.h"

// Plane with a normal
class cM3dGPla {
public:
    /* 0x00 */ cXyz mNormal;
    /* 0x0C */ f32 mD;
    /* 0x10 */ /* vtable */

public:
    cM3dGPla() {}
    cM3dGPla(const cXyz* normal, f32 d) {
        mNormal = *normal;
        mD = d;
    }
    void CalcAngleXz(short* pAngleX, short* pAngleY) const;
    void SetupNP0(const Vec& pNormal, const Vec& pPoint);
    
    f32 getPlaneFunc(const Vec *p) const {
        return mD + VECDotProduct(&mNormal, p);
    }

    cXyz* GetNP() { return &mNormal; }
    const cXyz* GetNP() const { return &mNormal; }
    f32 GetD() const { return mD; }
    bool getCrossY(const cXyz& i_axis, f32* i_value) const {
        if (cM3d_IsZero(mNormal.y)) {
            return false;
        }
        *i_value = (-mNormal.x * i_axis.x - mNormal.z * i_axis.z - mD) / mNormal.y;
        return true;
    }
    f32 getCrossY_NonIsZero(const cXyz& i_axis) const {
        return (-mNormal.x * i_axis.x - mNormal.z * i_axis.z - mD) / mNormal.y;
    }
    bool getCrossYLessD(const Vec& i_axis, f32* i_value) const {
        if (cM3d_IsZero(mNormal.y)) {
            return false;
        }
        *i_value = (-mNormal.x * i_axis.x - mNormal.z * i_axis.z) / mNormal.y;
        return true;
    }
    f32 getSignedLenPos(const cXyz* pos) const {
        return cM3d_SignedLenPlaAndPos(this, pos);
    }
    void Set(const cM3dGPla* pla) {
        mNormal = *pla->GetNP();
        mD = pla->GetD();
    }
    void SetupFrom3Vtx(const Vec* a, const Vec* b, const Vec* c) {
        cM3d_CalcPla(a, b, c, &mNormal, &mD);
    }
    bool cross(const cM3dGLin& line, Vec& point) const {
        return cM3d_Cross_LinPla(&line, this, &point, true, true);
    }
    
    virtual ~cM3dGPla() {}
};  // Size: 0x14

STATIC_ASSERT(sizeof(cM3dGPla) == 0x14);

#endif