A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
KartObjectProxy.cc
1#include "KartObjectProxy.hh"
2
3#include "game/kart/CollisionGroup.hh"
4#include "game/kart/KartObject.hh"
5#include "game/kart/KartObjectManager.hh"
6#include "game/kart/KartState.hh"
7#include "game/kart/KartSub.hh"
8#include "game/kart/KartSuspension.hh"
9#include "game/kart/KartTire.hh"
10
11#include "game/system/CourseMap.hh"
12#include "game/system/RaceManager.hh"
13#include "game/system/map/MapdataCannonPoint.hh"
14
15#include <egg/math/Math.hh>
16
17#include <algorithm>
18
19namespace Kart {
20
22KartObjectProxy::KartObjectProxy() : m_accessor(nullptr) {
23 s_proxyList.push_back(this);
24}
25
26KartObjectProxy::~KartObjectProxy() = default;
27
29void KartObjectProxy::setPos(const EGG::Vector3f &pos) {
30 dynamics()->setPos(pos);
31}
32
34void KartObjectProxy::setRot(const EGG::Quatf &q) {
35 dynamics()->setFullRot(q);
36 dynamics()->setMainRot(q);
37}
38
40void KartObjectProxy::setInertiaScale(const EGG::Vector3f &scale) {
41 const EGG::Vector3f *cuboids = bsp().cuboids;
42 dynamics()->setInertia(cuboids[0] * scale, cuboids[1] * scale);
43}
44
46KartAction *KartObjectProxy::action() {
47 return m_accessor->action;
48}
49
51const KartAction *KartObjectProxy::action() const {
52 return m_accessor->action;
53}
54
56KartBody *KartObjectProxy::body() {
57 return m_accessor->body;
58}
59
61const KartBody *KartObjectProxy::body() const {
62 return m_accessor->body;
63}
64
66KartCollide *KartObjectProxy::collide() {
67 return m_accessor->collide;
68}
69
71const KartCollide *KartObjectProxy::collide() const {
72 return m_accessor->collide;
73}
74
76CollisionGroup *KartObjectProxy::collisionGroup() {
77 return m_accessor->body->physics()->hitboxGroup();
78}
79
81const CollisionGroup *KartObjectProxy::collisionGroup() const {
82 return m_accessor->body->physics()->hitboxGroup();
83}
84
86KartMove *KartObjectProxy::move() {
87 return m_accessor->move;
88}
89
91const KartMove *KartObjectProxy::move() const {
92 return m_accessor->move;
93}
94
95KartHalfPipe *KartObjectProxy::halfPipe() {
96 return m_accessor->move->halfPipe();
97}
98
99const KartHalfPipe *KartObjectProxy::halfPipe() const {
100 return m_accessor->move->halfPipe();
101}
102
104KartJump *KartObjectProxy::jump() {
105 return m_accessor->move->jump();
106}
107
109const KartJump *KartObjectProxy::jump() const {
110 return m_accessor->move->jump();
111}
112
114KartParam *KartObjectProxy::param() {
115 return m_accessor->param;
116}
117
119const KartParam *KartObjectProxy::param() const {
120 return m_accessor->param;
121}
122
124const BSP &KartObjectProxy::bsp() const {
125 return param()->bsp();
126}
127
129KartPhysics *KartObjectProxy::physics() {
130 return body()->physics();
131}
132
134const KartPhysics *KartObjectProxy::physics() const {
135 return body()->physics();
136}
137
139KartDynamics *KartObjectProxy::dynamics() {
140 return physics()->dynamics();
141}
142
144const KartDynamics *KartObjectProxy::dynamics() const {
145 return physics()->dynamics();
146}
147
148KartState *KartObjectProxy::state() {
149 return m_accessor->state;
150}
151
152const KartState *KartObjectProxy::state() const {
153 return m_accessor->state;
154}
155
157KartSub *KartObjectProxy::sub() {
158 return m_accessor->sub;
159}
160
162const KartSub *KartObjectProxy::sub() const {
163 return m_accessor->sub;
164}
165
167KartSuspension *KartObjectProxy::suspension(u16 suspIdx) {
168 return m_accessor->suspensions[suspIdx];
169}
170
172const KartSuspension *KartObjectProxy::suspension(u16 suspIdx) const {
173 return m_accessor->suspensions[suspIdx];
174}
175
177KartSuspensionPhysics *KartObjectProxy::suspensionPhysics(u16 suspIdx) {
178 return m_accessor->suspensions[suspIdx]->suspPhysics();
179}
180
182const KartSuspensionPhysics *KartObjectProxy::suspensionPhysics(u16 suspIdx) const {
183 return m_accessor->suspensions[suspIdx]->suspPhysics();
184}
185
187KartTire *KartObjectProxy::tire(u16 tireIdx) {
188 return m_accessor->tires[tireIdx];
189}
190
192const KartTire *KartObjectProxy::tire(u16 tireIdx) const {
193 return m_accessor->tires[tireIdx];
194}
195
197WheelPhysics *KartObjectProxy::tirePhysics(u16 tireIdx) {
198 return tire(tireIdx)->wheelPhysics();
199}
200
202const WheelPhysics *KartObjectProxy::tirePhysics(u16 tireIdx) const {
203 return m_accessor->tires[tireIdx]->wheelPhysics();
204}
205
207CollisionData &KartObjectProxy::collisionData() {
208 return physics()->hitboxGroup()->collisionData();
209}
210
212const CollisionData &KartObjectProxy::collisionData() const {
213 return m_accessor->body->physics()->hitboxGroup()->collisionData();
214}
215
217const System::KPad *KartObjectProxy::inputs() const {
218 return System::RaceManager::Instance()->player().inputs();
219}
220
222Render::KartModel *KartObjectProxy::model() {
223 return m_accessor->model;
224}
225
227const Render::KartModel *KartObjectProxy::model() const {
228 return m_accessor->model;
229}
230
232Field::ObjectCollisionKart *KartObjectProxy::objectCollisionKart() {
233 return m_accessor->objectCollisionKart;
234}
235
237const Field::ObjectCollisionKart *KartObjectProxy::objectCollisionKart() const {
238 return m_accessor->objectCollisionKart;
239}
240
242Field::BoxColUnit *KartObjectProxy::boxColUnit() {
243 return m_accessor->boxColUnit;
244}
245
247const Field::BoxColUnit *KartObjectProxy::boxColUnit() const {
248 return m_accessor->boxColUnit;
249}
250
252CollisionData &KartObjectProxy::collisionData(u16 tireIdx) {
253 return tirePhysics(tireIdx)->hitboxGroup()->collisionData();
254}
255
257const CollisionData &KartObjectProxy::collisionData(u16 tireIdx) const {
258 return m_accessor->tires[tireIdx]->wheelPhysics()->hitboxGroup()->collisionData();
259}
260
262const EGG::Vector3f &KartObjectProxy::scale() const {
263 return move()->scale();
264}
265
267const EGG::Matrix34f &KartObjectProxy::pose() const {
268 return physics()->pose();
269}
270
273EGG::Vector3f KartObjectProxy::bodyFront() const {
274 const EGG::Matrix34f &mtx = pose();
275 return EGG::Vector3f(mtx[0, 2], mtx[1, 2], mtx[2, 2]);
276}
277
280EGG::Vector3f KartObjectProxy::bodyForward() const {
281 const EGG::Matrix34f &mtx = pose();
282 return EGG::Vector3f(mtx[0, 0], mtx[1, 0], mtx[2, 0]);
283}
284
287EGG::Vector3f KartObjectProxy::bodyUp() const {
288 const EGG::Matrix34f &mtx = pose();
289 return EGG::Vector3f(mtx[0, 1], mtx[1, 1], mtx[2, 1]);
290}
291
293const EGG::Vector3f &KartObjectProxy::componentXAxis() const {
294 return physics()->xAxis();
295}
296
298const EGG::Vector3f &KartObjectProxy::componentYAxis() const {
299 return physics()->yAxis();
300}
301
303const EGG::Vector3f &KartObjectProxy::componentZAxis() const {
304 return physics()->zAxis();
305}
306
308const EGG::Vector3f &KartObjectProxy::pos() const {
309 return dynamics()->pos();
310}
311
313const EGG::Vector3f &KartObjectProxy::prevPos() const {
314 return physics()->pos();
315}
316
317const EGG::Quatf &KartObjectProxy::fullRot() const {
318 return dynamics()->fullRot();
319}
320
321const EGG::Vector3f &KartObjectProxy::extVel() const {
322 return dynamics()->extVel();
323}
324
325const EGG::Vector3f &KartObjectProxy::intVel() const {
326 return dynamics()->intVel();
327}
328
329const EGG::Vector3f &KartObjectProxy::velocity() const {
330 return dynamics()->velocity();
331}
332
334f32 KartObjectProxy::speed() const {
335 return move()->speed();
336}
337
338f32 KartObjectProxy::acceleration() const {
339 return move()->acceleration();
340}
341
342f32 KartObjectProxy::softSpeedLimit() const {
343 return move()->softSpeedLimit();
344}
345
346const EGG::Quatf &KartObjectProxy::mainRot() const {
347 return dynamics()->mainRot();
348}
349
350const EGG::Vector3f &KartObjectProxy::angVel2() const {
351 return dynamics()->angVel2();
352}
353
355bool KartObjectProxy::isBike() const {
356 return param()->isBike();
357}
358
360u16 KartObjectProxy::suspCount() const {
361 return param()->suspCount();
362}
363
365u16 KartObjectProxy::tireCount() const {
366 return param()->tireCount();
367}
368
370bool KartObjectProxy::hasFloorCollision(const WheelPhysics *wheelPhysics) const {
371 return wheelPhysics->hitboxGroup()->collisionData().bFloor;
372}
373
375std::pair<EGG::Vector3f, EGG::Vector3f> KartObjectProxy::getCannonPosRot() {
376 auto *cannon = System::CourseMap::Instance()->getCannonPoint(state()->cannonPointId());
377 const EGG::Vector3f &cannonPos = cannon->pos();
378 EGG::Vector3f cannonRot = cannon->rot();
379 EGG::Vector3f radRot = cannon->rot() * DEG2RAD;
380 EGG::Matrix34f rotMat;
381 rotMat.makeR(radRot);
382 cannonRot = rotMat.multVector33(EGG::Vector3f::ez);
383 EGG::Vector3f distance_to_cannon = this->pos() - cannonPos;
384 distance_to_cannon.y = 0.0f;
385 EGG::Vector3f local60 = EGG::Vector3f::ey.cross(cannonRot);
386 f32 temp0 = local60.dot(distance_to_cannon);
387 return std::pair(cannonPos + local60 * temp0, cannonRot);
388}
389
391f32 KartObjectProxy::speedRatio() const {
392 return move()->speedRatio();
393}
394
396f32 KartObjectProxy::speedRatioCapped() const {
397 return move()->speedRatioCapped();
398}
399
401bool KartObjectProxy::isInRespawn() const {
402 return move()->respawnTimer() > 0 || move()->respawnPostLandTimer() > 0;
403}
404
406void KartObjectProxy::apply(size_t idx) {
407 m_accessor = KartObjectManager::Instance()->object(idx)->accessor();
408}
409
413void KartObjectProxy::ApplyAll(const KartAccessor *pointers) {
414 for (auto iter = s_proxyList.begin(); iter != s_proxyList.end(); ++iter) {
415 (*iter)->m_accessor = pointers;
416 }
417}
418
419std::list<KartObjectProxy *> KartObjectProxy::s_proxyList;
420
421} // namespace Kart
A 3 x 4 matrix.
Definition Matrix.hh:8
Vector3f multVector33(const Vector3f &vec) const
Multiplies a 3x3 matrix by a vector.
Definition Matrix.cc:243
void makeR(const Vector3f &r)
Sets 3x3 rotation matrix from a vector of Euler angles.
Definition Matrix.cc:122
Relates a KartObject with its convex hull representation.
Included in Kinoko because it mysteriously sets an angle member variable in KartBody.
Definition KartModel.hh:9
Pertains to kart-related functionality.
A quaternion, used to represent 3D rotation.
Definition Quat.hh:12
A 3D float vector.
Definition Vector.hh:83
f32 dot(const Vector3f &rhs) const
The dot product between two vectors.
Definition Vector.hh:182
A representation of the boundaries of an entity that has dynamic collision.
Shared between classes who inherit KartObjectProxy so they can access one another.