Welcome to mirror list, hosted at ThFree Co, Russian Federation.

RigidBody.h « Dynamics « BulletDynamics « bullet « extern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 527e37bc57df2fdd35d1411256018c4605473630 (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#ifndef RIGIDBODY_H
#define RIGIDBODY_H

#include <vector>
#include <SimdPoint3.h>
#include <SimdTransform.h>

class CollisionShape;
struct MassProps;
typedef SimdScalar dMatrix3[4*3];


/// RigidBody class for RigidBody Dynamics
/// 
class RigidBody  {
public:

	RigidBody(const MassProps& massProps,SimdScalar linearDamping,SimdScalar angularDamping,SimdScalar friction,SimdScalar restitution);

	void			proceedToTransform(const SimdTransform& newTrans); 
	
	bool			mergesSimulationIslands() const;
	
	/// continuous collision detection needs prediction
	void			predictIntegratedTransform(SimdScalar step, SimdTransform& predictedTransform) const;
	
	void			applyForces(SimdScalar step);
	
	void			setGravity(const SimdVector3& acceleration);  
	
	void			setDamping(SimdScalar lin_damping, SimdScalar ang_damping);
	
	CollisionShape*	GetCollisionShape() { return m_collisionShape; }
	
	void			setMassProps(SimdScalar mass, const SimdVector3& inertia);
	
	SimdScalar		getInvMass() const { return m_inverseMass; }
	const SimdMatrix3x3& getInvInertiaTensorWorld() const { return m_invInertiaTensorWorld; }
		
	void			integrateVelocities(SimdScalar step);

	void			setCenterOfMassTransform(const SimdTransform& xform);

	void			applyCentralForce(const SimdVector3& force)
	{
		m_totalForce += force;
	}
    
	const SimdVector3& getInvInertiaDiagLocal()
	{
		return m_invInertiaLocal;
	};

	void	setInvInertiaDiagLocal(const SimdVector3& diagInvInertia)
	{
		m_invInertiaLocal = diagInvInertia;
	}

	void	applyTorque(const SimdVector3& torque)
	{
		m_totalTorque += torque;
	}
	
	void	applyForce(const SimdVector3& force, const SimdVector3& rel_pos) 
	{
		applyCentralForce(force);
		applyTorque(rel_pos.cross(force));
	}
	
	void applyCentralImpulse(const SimdVector3& impulse)
	{
		m_linearVelocity += impulse * m_inverseMass;
	}
	
  	void applyTorqueImpulse(const SimdVector3& torque)
	{
		m_angularVelocity += m_invInertiaTensorWorld * torque;

	}
	
	void applyImpulse(const SimdVector3& impulse, const SimdVector3& rel_pos) 
	{
		if (m_inverseMass != 0.f)
		{
			applyCentralImpulse(impulse);
			applyTorqueImpulse(rel_pos.cross(impulse));
		}
	}
	
	void clearForces() 
	{
		m_totalForce.setValue(0.0f, 0.0f, 0.0f);
		m_totalTorque.setValue(0.0f, 0.0f, 0.0f);
	}
	
	void updateInertiaTensor();    
	
	const SimdPoint3&     getCenterOfMassPosition() const { return m_worldTransform.getOrigin(); }
	SimdQuaternion getOrientation() const;
	
	const SimdTransform&  getCenterOfMassTransform() const { return m_worldTransform; }
	const SimdVector3&   getLinearVelocity() const { return m_linearVelocity; }
	const SimdVector3&    getAngularVelocity() const { return m_angularVelocity; }
	

	void setLinearVelocity(const SimdVector3& lin_vel);
	void setAngularVelocity(const SimdVector3& ang_vel) { m_angularVelocity = ang_vel; }

	SimdVector3 getVelocityInLocalPoint(const SimdVector3& rel_pos) const
	{
		return m_linearVelocity + m_angularVelocity.cross(rel_pos);
	}

	void translate(const SimdVector3& v) 
	{
		m_worldTransform.getOrigin() += v; 
	}

	void	SetCollisionShape(CollisionShape* mink);

	void	getAabb(SimdVector3& aabbMin,SimdVector3& aabbMax) const;

	int	GetActivationState() const { return m_activationState1;}
	void SetActivationState(int newState);

	void	setRestitution(float rest)
	{
		m_restitution = rest;
	}
	float	getRestitution() const
	{
		return m_restitution;
	}
	void	setFriction(float frict)
	{
		m_friction = frict;
	}
	float	getFriction() const
	{
		return m_friction;
	}

private:
	SimdTransform	m_worldTransform;
	SimdMatrix3x3	m_invInertiaTensorWorld;
	SimdVector3		m_gravity;	
	SimdVector3		m_invInertiaLocal;
	SimdVector3		m_totalForce;
	SimdVector3		m_totalTorque;
	SimdQuaternion	m_orn1;
	
	SimdVector3		m_linearVelocity;
	
	SimdVector3		m_angularVelocity;
	
	SimdScalar		m_linearDamping;
	SimdScalar		m_angularDamping;
	SimdScalar		m_inverseMass;

	SimdScalar		m_friction;
	SimdScalar		m_restitution;

	CollisionShape*	m_collisionShape;

	
public:
	/// for ode solver-binding
	dMatrix3		m_R;//temp
	dMatrix3		m_I;
	dMatrix3		m_invI;
	int				m_islandTag1;//temp
	int				m_activationState1;//temp
	int				m_odeTag;
	SimdVector3		m_tacc;//temp
	SimdVector3		m_facc;
	SimdScalar		m_hitFraction; //time of impact calculation

	int	m_debugBodyId;
};



#endif