-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameObject.cpp
More file actions
136 lines (107 loc) · 2.85 KB
/
GameObject.cpp
File metadata and controls
136 lines (107 loc) · 2.85 KB
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
#include "GameObject.h"
#include "Simulator.h"
GameObject::GameObject(Ogre::String nym, Ogre::SceneManager* mgr, Simulator* sim)
{
name = nym;
sceneMgr = mgr;
simulator = sim;
rootNode = sceneMgr->getRootSceneNode()->createChildSceneNode(name);
shape = NULL;
tr.setIdentity();
mass = 0.0f;
inertia.setZero();
geom = NULL;
motionState = NULL;
body = NULL;
restitution = 0.95f;
friction = 0.5f;
kinematic = false;
needsUpdates = false;
context = NULL;
cCallBack = NULL;
}
GameObject::~GameObject()
{
}
void GameObject::updateTransform()
{
Ogre::Vector3 pos = rootNode->getPosition();
tr.setOrigin(btVector3(pos.x, pos.y, pos.z));
Ogre::Quaternion qt = rootNode->getOrientation();
tr.setRotation(btQuaternion(qt.x, qt.y, qt.z, qt.w));
if (motionState) motionState->updateTransform(tr);
}
void GameObject::addToSimulator()
{
//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
updateTransform();
motionState = new OgreMotionState(tr, rootNode);
//rigidbody is dynamic if and only if mass is non zero, otherwise static
if (mass != 0.0f) shape->calculateLocalInertia(mass, inertia);
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, motionState, shape, inertia);
rbInfo.m_restitution = restitution;
rbInfo.m_friction = friction;
body = new btRigidBody(rbInfo);
body->setUserPointer(this);
context = new CollisionContext();
cCallBack = new BulletContactCallback(*body, *context);
simulator->addObject(this);
}
void GameObject::removeFromScene(void) {
rootNode->detachObject(geom);
}
void GameObject::removeFromSimulator(void) {
simulator->removeObject(this);
}
btRigidBody* GameObject::getBody()
{
return body;
}
void GameObject::update()
{
}
BulletContactCallback* GameObject::getCollisionCallback()
{
return cCallBack;
}
Ogre::Vector3 GameObject::getPos()
{
return rootNode->getPosition();
}
Ogre::SceneNode* GameObject::getNode() {
return rootNode;
}
OgreMotionState* GameObject::getMotionState() {
return motionState;
}
btTransform* GameObject::getTransform() {
return &tr;
}
btScalar GameObject::getMass() {
return mass;
}
btCollisionShape * GameObject::getShape() {
return shape;
}
btVector3 GameObject::getInertia() {
return inertia;
}
btScalar GameObject::getFriction() {
return friction;
}
btScalar GameObject::getRestitution() {
return restitution;
}
void GameObject::setMotionState(OgreMotionState* newState) {
motionState = newState;
}
void GameObject::setBody(btRigidBody* newBody) {
body = newBody;
newBody->setUserPointer(this);
}
void GameObject::setPosition(float x, float y, float z){
rootNode->setPosition(Ogre::Vector3(x,y,z));
}
std::string GameObject::getName() {
return name;
}