Etterna 0.74.4
Loading...
Searching...
No Matches
RageMath.h
1/* RageMath - vector/matrix math utilities. */
2
3#ifndef RAGE_MATH_H
4#define RAGE_MATH_H
5
6#include <vector>
7
8#define PI (3.141592653589793f)
9#define DegreeToRadian(degree) ((degree) * (PI / 180.0f))
10#define RadianToDegree(radian) ((radian) * (180.0f / PI))
11
12struct lua_State;
13struct RageVector2;
14struct RageVector3;
15struct RageVector4;
16struct RageMatrix;
17
18void
19RageVec2RotateFromOrigin(RageVector2* pOut, float degrees);
20
21void
22RageVec2RotateFromPoint(RageVector2* p1, RageVector2* p2, float degrees);
23
24void
25RageVec3ClearBounds(struct RageVector3& mins, RageVector3& maxs);
26void
27RageVec3AddToBounds(const struct RageVector3& p,
28 RageVector3& mins,
29 RageVector3& maxs);
30
31void
32RageVec2Normalize(struct RageVector2* pOut, const struct RageVector2* pV);
33void
34RageVec3Normalize(struct RageVector3* pOut, const struct RageVector3* pV);
35void
36VectorFloatNormalize(std::vector<float>& v);
37void
38RageVec3Cross(struct RageVector3* ret,
39 struct RageVector3 const* a,
40 struct RageVector3 const* b);
41void
42RageVec3TransformCoord(struct RageVector3* pOut,
43 const struct RageVector3* pV,
44 const struct RageMatrix* pM);
45void
46RageVec3TransformNormal(struct RageVector3* pOut,
47 const struct RageVector3* pV,
48 const struct RageMatrix* pM);
49void
50RageVec4TransformCoord(struct RageVector4* pOut,
51 const struct RageVector4* pV,
52 const struct RageMatrix* pM);
53void
54RageMatrixIdentity(struct RageMatrix* pOut);
55void
56RageMatrixMultiply(struct RageMatrix* pOut,
57 const struct RageMatrix* pA,
58 const struct RageMatrix* pB);
59void
60RageMatrixTranslation(struct RageMatrix* pOut, float x, float y, float z);
61void
62RageMatrixScaling(struct RageMatrix* pOut, float x, float y, float z);
63void
64RageMatrixSkewX(struct RageMatrix* pOut, float fAmount);
65void
66RageMatrixSkewY(struct RageMatrix* pOut, float fAmount);
67void
68RageMatrixTranslate(struct RageMatrix* pOut,
69 float fTransX,
70 float fTransY,
71 float fTransZ);
72void
73RageMatrixScale(struct RageMatrix* pOut,
74 float fScaleX,
75 float fScaleY,
76 float fScaleZ);
77void
78RageMatrixRotationX(struct RageMatrix* pOut, float fTheta);
79void
80RageMatrixRotationY(struct RageMatrix* pOut, float fTheta);
81void
82RageMatrixRotationZ(struct RageMatrix* pOut, float fTheta);
83void
84RageMatrixRotationXYZ(struct RageMatrix* pOut, float rX, float rY, float rZ);
85void
86RageAARotate(struct RageVector3* inret,
87 struct RageVector3 const* axis,
88 float angle);
89void
90RageQuatFromHPR(struct RageVector4* pOut, struct RageVector3 hpr);
91void
92RageQuatFromPRH(struct RageVector4* pOut, struct RageVector3 prh);
93void
94RageMatrixFromQuat(struct RageMatrix* pOut, const struct RageVector4& q);
95void
96RageQuatSlerp(struct RageVector4* pOut,
97 const struct RageVector4& from,
98 const RageVector4& to,
99 float t);
100auto
101RageQuatFromH(float theta) -> struct RageVector4;
102auto
103RageQuatFromP(float theta) -> struct RageVector4;
104auto
105RageQuatFromR(float theta) -> struct RageVector4;
106void
107RageQuatMultiply(struct RageVector4* pOut,
108 const struct RageVector4& pA,
109 const RageVector4& pB);
110auto
111RageLookAt(float eyex,
112 float eyey,
113 float eyez,
114 float centerx,
115 float centery,
116 float centerz,
117 float upx,
118 float upy,
119 float upz) -> struct RageMatrix;
120void
121RageMatrixAngles(struct RageMatrix* pOut, const struct RageVector3& angles);
122void
123RageMatrixTranspose(struct RageMatrix* pOut, const struct RageMatrix* pIn);
124
125auto
126RageFastSin(float x) -> const float;
127auto
128RageFastCos(float x) -> const float;
129
131{
132 public:
133 void SetFromBezier(float fC1, float fC2, float fC3, float fC4);
134 void GetBezier(float& fC1, float& fC2, float& fC3, float& fC4) const;
135
136 void SetFromCubic(float fX1, float fX2, float fX3, float fX4);
137
138 [[nodiscard]] auto Evaluate(float fT) const -> float;
139 [[nodiscard]] auto GetSlope(float fT) const -> float;
140
141 /* Equivalent to Evaluate(0.0f) and Evaluate(1.0f), but faster: */
142 [[nodiscard]] auto GetBezierStart() const -> float { return m_fD; }
143 [[nodiscard]] auto GetBezierEnd() const -> float
144 {
145 return m_fA + m_fB + m_fC + m_fD;
146 }
147
148 void PushSelf(lua_State* L);
149
150 private:
151 float m_fA, m_fB, m_fC, m_fD;
152};
153
155{
156 public:
157 void SetFromBezier(float fC1X,
158 float fC2X,
159 float fC3X,
160 float fC4X,
161 float fC1Y,
162 float fC2Y,
163 float fC3Y,
164 float fC4Y);
165
166 void Evaluate(float fT, float* pX, float* pY) const;
167 [[nodiscard]] auto EvaluateYFromX(float fX) const -> float;
168
169 auto get_x() -> RageQuadratic& { return m_X; }
170 auto get_y() -> RageQuadratic& { return m_Y; }
171 void PushSelf(lua_State* L);
172
173 private:
174 RageQuadratic m_X;
175 RageQuadratic m_Y;
176};
177
178#endif
Definition RageMath.h:155
Definition RageMath.h:131
Definition RageTypes.h:599
Definition RageTypes.h:101
Definition RageTypes.h:172
Definition RageTypes.h:249