-
Notifications
You must be signed in to change notification settings - Fork 0
/
PhysBody3D.cpp
72 lines (64 loc) · 1.72 KB
/
PhysBody3D.cpp
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
#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::SetAsSensor(bool pIsSensor)
{
if (this->isSensor != pIsSensor)
{
this->isSensor = pIsSensor;
if (pIsSensor == true)
body->setCollisionFlags(body->getCollisionFlags() | btCollisionObject::CF_NO_CONTACT_RESPONSE);
else
body->setCollisionFlags(body->getCollisionFlags() & ~btCollisionObject::CF_NO_CONTACT_RESPONSE);
}
}
//vec3 PhysBody3D::GetPos()
//{
// btVector3 getP = body->getWorldTransform().getOrigin();
//
// vec3 pos;
// pos.x = getP.x();
// pos.y = getP.y();
// pos.z = getP.z();
//
// return pos;
//}