-
Notifications
You must be signed in to change notification settings - Fork 43
/
SimpleDynamicBodyComponent.h
63 lines (46 loc) · 2.15 KB
/
SimpleDynamicBodyComponent.h
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
/* Copyright 2012-2020 Matthew Reid
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
#include "DynamicBodyComponent.h"
#include <SkyboltCommon/Math/MathUtility.h>
namespace skybolt {
namespace sim {
class SimpleDynamicBodyComponent : public DynamicBodyComponent
{
public:
SimpleDynamicBodyComponent(Node* node, Real mass, const Vector3& momentofInertia);
void setLinearVelocity(const Vector3& v) override { mLinearVelocity = v; }
Vector3 getLinearVelocity() const override { return mLinearVelocity; }
//! Angular velocity is in world space
void setAngularVelocity(const Vector3& v) override { mAngularVelocity = v; }
Vector3 getAngularVelocity() const override { return mAngularVelocity; }
Real getMass() const override { return mMass; }
void setMass(Real mass) override { mMass = mass; }
void setCenterOfMass(const Vector3& relPosition) override { mCenterOfMass = relPosition; }
//! Apply force at center of mass. Force is in world axes.
void applyCentralForce(const Vector3& force) override;
//! Force and relPosition are in world axes
void applyForce(const Vector3& force, const Vector3& relPosition) override;
//! Apply torque. Torque is in world axes.
void applyTorque(const Vector3& torque) override;
void updatePreDynamicsSubstep(TimeReal dtSubstep) override;
void updatePostDynamics(TimeReal dt, TimeReal dtWallClock) override;
virtual void setCollisionsEnabled(bool enabled) override {}
std::vector<std::type_index> getExposedTypes() const override
{
return {typeid(DynamicBodyComponent), typeid(SimpleDynamicBodyComponent)};
}
private:
Node* mNode;
Real mMass;
Vector3 mMomentOfInertia;
Vector3 mCenterOfMass = math::dvec3Zero();
Vector3 mLinearVelocity = math::dvec3Zero(); //!< World space
Vector3 mAngularVelocity = math::dvec3Zero(); //!< World space
Vector3 mTotalForce = math::dvec3Zero(); //!< World space
Vector3 mTotalTorque = math::dvec3Zero(); //!< World space
};
} // namespace sim
} // namespace skybolt