1 | #include <stdio.h> |
---|
2 | #include "BulletObject.h" |
---|
3 | |
---|
4 | BulletObject::BulletObject(Environment *bullet) |
---|
5 | { |
---|
6 | m_bullet = bullet; |
---|
7 | } |
---|
8 | |
---|
9 | |
---|
10 | btRigidBody* BulletObject::localCreateRigidBody (btScalar mass, const btTransform& startTransform, btCollisionShape* shape) { |
---|
11 | bool isDynamic = (mass != 0.f); |
---|
12 | |
---|
13 | btVector3 localInertia(0,0,0); |
---|
14 | if (isDynamic) |
---|
15 | shape->calculateLocalInertia(mass,localInertia); |
---|
16 | |
---|
17 | btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform); |
---|
18 | btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,shape,localInertia); |
---|
19 | btRigidBody* body = new btRigidBody(rbInfo); |
---|
20 | |
---|
21 | m_bullet->getDynamicsWorld()->addRigidBody(body); |
---|
22 | |
---|
23 | return body; |
---|
24 | } |
---|
25 | |
---|
26 | btRigidBody* BulletObject::createBulletObject(btCollisionShape* colShape, btVector3 position, btScalar mass) |
---|
27 | { |
---|
28 | m_bullet->getCollisionShapes().push_back(colShape); |
---|
29 | |
---|
30 | btTransform startTransform; |
---|
31 | startTransform.setIdentity(); |
---|
32 | startTransform.setOrigin(SCALING*position); |
---|
33 | |
---|
34 | btRigidBody *body = localCreateRigidBody(mass, startTransform, colShape); |
---|
35 | body->setActivationState(ISLAND_SLEEPING); |
---|
36 | |
---|
37 | return body; |
---|
38 | } |
---|
39 | |
---|
40 | |
---|
41 | btRigidBody* BulletObject::createBulletObject(btCollisionShape* colShape, btTransform transform, btScalar mass) |
---|
42 | { |
---|
43 | m_bullet->getCollisionShapes().push_back(colShape); |
---|
44 | |
---|
45 | btRigidBody *body = localCreateRigidBody(mass, transform, colShape); |
---|
46 | body->setActivationState(ISLAND_SLEEPING); |
---|
47 | |
---|
48 | return body; |
---|
49 | } |
---|