SO3Engine
src
SO3PhysicGraph
SO3HingeContraint.cpp
Go to the documentation of this file.
1
8
#include "
SO3PhysicGraph/SO3HingeContraint.h
"
9
#include "
SO3SceneGraph/SO3Scene.h
"
10
11
namespace
SO3
12
{
13
14
SHingeContraint::SHingeContraint() :
SPhysicContraint
(0, 0, 0,
SPhysicContraint
::SO3_HINGE_CONTRAINT)
15
{
16
// Forbiden, private.
17
}
18
19
SHingeContraint::SHingeContraint(
SScene
* scene,
SBody
* son,
SBody
* parent, Ogre::Vector3 position, Ogre::Vector3 pin,
bool
useLimits) :
SPhysicContraint
(scene, son, parent,
SPhysicContraint
::SO3_HINGE_CONTRAINT)
20
{
21
mPosition = position;
22
mPin = pin;
23
mUseLimits = useLimits;
24
mUseMotor =
false
;
25
26
UpdateJoint();
27
}
28
29
SHingeContraint::~SHingeContraint
()
30
{
31
//mjoint deleted in SPhysicContraint
32
}
33
34
void
SHingeContraint::SetParentBody
(
SBody
* body)
35
{
36
mParentBody
= body;
37
38
UpdateJoint();
39
}
40
41
void
SHingeContraint::SetSonBody
(
SBody
* body)
42
{
43
mSonBody
= body;
44
45
UpdateJoint();
46
}
47
48
void
SHingeContraint::UpdateJoint()
49
{
50
mScene
->
GetPhysicsWorld
()->
GetPhysicWorld
()->
waitForUpdateToFinish
();
51
SAFE_DELETE(
mJoint
);
52
53
if
(
mSonBody
)
54
{
55
OgreNewt::Body
* bparent =
mParentBody
!= NULL ?
mParentBody
->
getOgreNewtBodyPointer
() : NULL;
56
mJoint
=
static_cast<
OgreNewt::Joint
*
>
(
new
OgreNewt::Hinge
(
mSonBody
->
getOgreNewtBodyPointer
(), bparent, mPosition, mPin));
57
static_cast<
OgreNewt::Hinge
*
>
(
mJoint
)->enableLimits(mUseLimits);
58
static_cast<
OgreNewt::Hinge
*
>
(
mJoint
)->enableMotor(mUseMotor);
59
}
60
}
61
62
void
SHingeContraint::UseLimits
(
bool
state)
63
{
64
mUseLimits = state;
65
if
(
mJoint
!= NULL)
66
static_cast<
OgreNewt::Hinge
*
>
(
mJoint
)->enableLimits(mUseLimits);
67
}
68
69
void
SHingeContraint::SetLimits
(Ogre::Radian minAngle, Ogre::Radian maxAngle)
70
{
71
if
(minAngle > maxAngle)
72
minAngle = maxAngle;
73
74
if
(
mJoint
!= NULL)
75
static_cast<
OgreNewt::Hinge
*
>
(
mJoint
)->setLimits(minAngle, maxAngle);
76
}
77
78
Ogre::Radian
SHingeContraint::GetAngle
()
79
{
80
if
(
mJoint
== NULL)
81
return
Ogre::Radian(0.0f);
82
else
83
return
static_cast<
OgreNewt::Hinge
*
>
(
mJoint
)->getJointAngle();
84
}
85
86
Ogre::Radian
SHingeContraint::GetAngularVelocity
()
87
{
88
if
(
mJoint
== NULL)
89
return
Ogre::Radian(0.0f);
90
else
91
return
static_cast<
OgreNewt::Hinge
*
>
(
mJoint
)->getJointAngularVelocity();
92
}
93
94
Ogre::Vector3
SHingeContraint::GetForce
()
95
{
96
if
(
mJoint
== NULL)
97
return
Ogre::Vector3::ZERO;
98
else
99
return
static_cast<
OgreNewt::Hinge
*
>
(
mJoint
)->getJointForce();
100
}
101
102
Ogre::Vector3
SHingeContraint::GetPin
()
103
{
104
if
(
mJoint
== NULL)
105
return
Ogre::Vector3::ZERO;
106
else
107
return
static_cast<
OgreNewt::Hinge
*
>
(
mJoint
)->getJointPin();
108
}
109
110
void
SHingeContraint::SetMotorOmega
(Ogre::Radian omega, Ogre::Real strength)
111
{
112
if
(
mJoint
!= NULL)
113
static_cast<
OgreNewt::Hinge
*
>
(
mJoint
)->setDesiredOmega(omega, strength);
114
}
115
116
void
SHingeContraint::SetMotorAngle
(Ogre::Radian angle, Ogre::Real minFriction, Ogre::Real maxFriction)
117
{
118
if
(
mJoint
!= NULL)
119
static_cast<
OgreNewt::Hinge
*
>
(
mJoint
)->setDesiredAngle(angle, minFriction, maxFriction);
120
}
121
122
void
SHingeContraint::SetTorque
(Ogre::Real torque)
123
{
124
if
(
mJoint
!= NULL)
125
static_cast<
OgreNewt::Hinge
*
>
(
mJoint
)->setTorque(torque);
126
}
127
128
void
SHingeContraint::SetBrake
(Ogre::Real maxForce)
129
{
130
if
(
mJoint
!= NULL)
131
static_cast<
OgreNewt::Hinge
*
>
(
mJoint
)->setBrake(maxForce);
132
}
133
134
void
SHingeContraint::UseMotor
(
bool
state)
135
{
136
mUseMotor = state;
137
if
(
mJoint
!= NULL)
138
static_cast<
OgreNewt::Hinge
*
>
(
mJoint
)->enableMotor(mUseMotor);
139
}
140
141
}
SO3HingeContraint.h
SO3Scene.h
OgreNewt::Body
main class for all Rigid Bodies in the system.
Definition
OgreNewt_Body.h:39
OgreNewt::Hinge
hinge joint.
Definition
OgreNewt_BasicJoints.h:145
OgreNewt::Joint
base class for all joints.
Definition
OgreNewt_Joint.h:31
OgreNewt::World::waitForUpdateToFinish
void waitForUpdateToFinish() const
Definition
OgreNewt_World.h:361
SO3::SBody
Definition
SO3Body.h:43
SO3::SBody::getOgreNewtBodyPointer
OgreNewt::Body * getOgreNewtBodyPointer()
Definition
SO3Body.cpp:340
SO3::SHingeContraint::SetMotorOmega
void SetMotorOmega(Ogre::Radian omega, Ogre::Real strength=0.5f)
Definition
SO3HingeContraint.cpp:110
SO3::SHingeContraint::GetAngle
Ogre::Radian GetAngle()
Definition
SO3HingeContraint.cpp:78
SO3::SHingeContraint::SetMotorAngle
void SetMotorAngle(Ogre::Radian angle, Ogre::Real minFriction=0, Ogre::Real maxFriction=0)
Definition
SO3HingeContraint.cpp:116
SO3::SHingeContraint::UseMotor
void UseMotor(bool state)
Definition
SO3HingeContraint.cpp:134
SO3::SHingeContraint::GetForce
Ogre::Vector3 GetForce()
Definition
SO3HingeContraint.cpp:94
SO3::SHingeContraint::GetPin
Ogre::Vector3 GetPin()
Definition
SO3HingeContraint.cpp:102
SO3::SHingeContraint::SetParentBody
virtual void SetParentBody(SBody *body)
Definition
SO3HingeContraint.cpp:34
SO3::SHingeContraint::SetTorque
void SetTorque(Ogre::Real torque)
Definition
SO3HingeContraint.cpp:122
SO3::SHingeContraint::GetAngularVelocity
Ogre::Radian GetAngularVelocity()
Definition
SO3HingeContraint.cpp:86
SO3::SHingeContraint::UseLimits
void UseLimits(bool state)
Definition
SO3HingeContraint.cpp:62
SO3::SHingeContraint::SetBrake
void SetBrake(Ogre::Real maxForce=0)
Definition
SO3HingeContraint.cpp:128
SO3::SHingeContraint::~SHingeContraint
~SHingeContraint()
Definition
SO3HingeContraint.cpp:29
SO3::SHingeContraint::SetLimits
void SetLimits(Ogre::Radian maxAngle, Ogre::Radian minAngle)
Definition
SO3HingeContraint.cpp:69
SO3::SHingeContraint::SetSonBody
virtual void SetSonBody(SBody *body)
Definition
SO3HingeContraint.cpp:41
SO3::SPhysicContraint
Definition
SO3PhysicContraint.h:42
SO3::SPhysicContraint::mParentBody
SBody * mParentBody
Definition
SO3PhysicContraint.h:54
SO3::SPhysicContraint::mJoint
OgreNewt::Joint * mJoint
Definition
SO3PhysicContraint.h:57
SO3::SPhysicContraint::mScene
SScene * mScene
Definition
SO3PhysicContraint.h:56
SO3::SPhysicContraint::mSonBody
SBody * mSonBody
Definition
SO3PhysicContraint.h:55
SO3::SPhysicWorld::GetPhysicWorld
OgreNewt::World * GetPhysicWorld()
Definition
SO3Physics.cpp:93
SO3::SScene
Definition
SO3Scene.h:125
SO3::SScene::GetPhysicsWorld
SPhysicWorld * GetPhysicsWorld()
Definition
SO3Scene.cpp:1332
SPhysicContraint
Manage Physics Contraint. .
SO3
Definition
SO3DataScol.h:38
Generated by
1.9.8