-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhysBody3D.cpp
More file actions
55 lines (48 loc) · 1.38 KB
/
PhysBody3D.cpp
File metadata and controls
55 lines (48 loc) · 1.38 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
#include "PhysBody3D.h"
#include "glmath.h"
#include "Bullet/include/btBulletDynamicsCommon.h"
// =================================================
PhysBody3D::PhysBody3D(btRigidBody* body) : body(body)
{}
// ---------------------------------------------------------
PhysBody3D::~PhysBody3D()
{
delete body;
}
// ---------------------------------------------------------
void PhysBody3D::Push(float x, float y, float z)
{
body->applyCentralImpulse(btVector3(x, y, z));
}
// ---------------------------------------------------------
void PhysBody3D::GetTransform(float* matrix) const
{
if(body != NULL && matrix != NULL)
{
body->getWorldTransform().getOpenGLMatrix(matrix);
}
}
// ---------------------------------------------------------
void PhysBody3D::SetTransform(const float* matrix) const
{
if(body != NULL && matrix != NULL)
{
btTransform t;
t.setFromOpenGLMatrix(matrix);
body->setWorldTransform(t);
}
}
// ---------------------------------------------------------
void PhysBody3D::SetPos(float x, float y, float z)
{
btTransform t = body->getWorldTransform();
t.setOrigin(btVector3(x, y, z));
body->setWorldTransform(t);
}
void PhysBody3D::SetSensor(bool state)
{
if (state)
body->setCollisionFlags(body->getCollisionFlags() | btCollisionObject::CF_NO_CONTACT_RESPONSE);
else
body->setCollisionFlags(body->getCollisionFlags() &~btCollisionObject::CF_NO_CONTACT_RESPONSE);
}