RigidObject.h 2.02 KB
Newer Older
Yuwei Xiao's avatar
init  
Yuwei Xiao committed
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
#ifndef RIGIDOBJECT_H
#define RIGIDOBJECT_H

#include "BaseObject.h"

/*
 * Base class representing a simple rigid object.
 */
class RigidObject : public BaseObject {
public:
	RigidObject() {}
	RigidObject(const std::string& mesh_path,
		const ObjType t = ObjType::DYNAMIC);
	virtual ~RigidObject() {}
	void applyForceToCOM(const Eigen::Vector3d& f);
	/*
	 * Apply force f at point p.
	 */
	void applyForce(const Eigen::Vector3d& f, const Eigen::Vector3d& p);
	void applyTorque(const Eigen::Vector3d& t);
	void printDebug(const std::string& message = "") const;

#pragma region GettersAndSetters
	virtual void setType(ObjType t) override;
	void setMass(double m);
	void setInertia(const Eigen::Matrix3d& I);
	void setLinearMomentum(const Eigen::Vector3d& p);
	void setAngularMomentum(const Eigen::Vector3d& l);
	void setLinearVelocity(const Eigen::Vector3d& v);
	void setAngularVelocity(const Eigen::Vector3d& w);
	void setForce(const Eigen::Vector3d& f);
	void setTorque(const Eigen::Vector3d& t);
	void resetForce();
	void resetTorque();

	double getMass() const;
	double getMassInv() const;
	Eigen::Matrix3d getInertia() const;
	Eigen::Matrix3d getInertiaInv() const;
	Eigen::Matrix3d getInertiaInvWorld() const;
	Eigen::Matrix3d getInertiaWorld() const;
	Eigen::Vector3d getLinearMomentum() const;
	Eigen::Vector3d getAngularMomentum() const;
	Eigen::Vector3d getLinearVelocity() const;
	Eigen::Vector3d getVelocity(const Eigen::Vector3d& point) const;
	Eigen::Vector3d getAngularVelocity() const;
	Eigen::Vector3d getForce() const;
	Eigen::Vector3d getTorque() const;
#pragma endregion GettersAndSetters

protected:
	virtual void resetMembers() override;

private:
	double m_mass;                 // Body mass
	double m_massInv;              // Inverted mass
	Eigen::Matrix3d m_inertia;     // Intertial Tensor (initially set to cube)
	Eigen::Matrix3d m_inertiaInv;  // Inverse

	Eigen::Vector3d m_v;  // Linear velocity
	Eigen::Vector3d m_w;  // Angular velocity

	Eigen::Vector3d m_force;   // Force on body
	Eigen::Vector3d m_torque;  // Torque on body
};

#endif