-
Notifications
You must be signed in to change notification settings - Fork 1
/
PhysicsShapeHandler.h
97 lines (80 loc) · 4.2 KB
/
PhysicsShapeHandler.h
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
/*
Copyright (C) 2011-2012 Alican Sekerefe
TeamTwo is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
TeamTwo is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Contact: projectteamtwo@gmail.com
*/
#ifndef PHYSICSSHAPEHANDLER_H
#define PHYSICSSHAPEHANDLER_H
#include "stdafx.h"
#include "CollisionObjectInfo.h"
/* PhysicsHandler
PhysicsHandler is a physics utility
based on Bullet Physics engine with
OgreBullet. It simplifies and specifies
some common actions such as creating
a rigidbody or performing a raycast test.
Since all of the methods are static, it
can be called anywhere in the code. However,
it requires a DynamicsWorld object for physics
operations.
*/
class PhysicsHandler
{
public:
//creates and returns a BoxCollisionShape by taking Ogre::Entity and a scale factor for the box shape
static OgreBulletCollisions::BoxCollisionShape* createBoxShape(Ogre::Entity* entity,Ogre::Vector3 scaleFactor=Ogre::Vector3(1,1,1));
//creates and returns a RigidBody object by taking necessary attributes of the body
static OgreBulletDynamics::RigidBody* addRigidBody(std::string bodyName,SceneNode* sceneNode,
OgreBulletCollisions::CollisionShape* shape,OgreBulletDynamics::DynamicsWorld* dynamics,
Ogre::Vector3 position=Ogre::Vector3::ZERO,float mass=1,Quaternion orientation=Quaternion::IDENTITY);
//creates and returns a CapsuleShape by taking Entity and a scalefactor for the entity
static OgreBulletCollisions::CapsuleCollisionShape* createCapsuleShape(Ogre::Entity* entity,Ogre::Vector3 scaleFactor);
//creates a compound shape, adds the given collision object and shifts it by considering its position
static OgreBulletCollisions::CompoundCollisionShape* createCompoundShapeAndAddChild(OgreBulletCollisions::CollisionShape* shape,Ogre::Vector3 position);
//performs a raycast test by taking the starting and ending points. it stores the collision data to the passed last two parameters
static bool performRaycastTest(Ogre::Vector3 start, Ogre::Vector3 end,
OgreBulletDynamics::DynamicsWorld* dynamics,btCollisionObject* object=NULL,Ogre::Vector3* hitPos = NULL);
//creates a scaled mesh shape for the given entity. this method should be used for creating static collision shapes
static btScaledBvhTriangleMeshShape* createScaledTriangleMeshShape(Entity* entity,Ogre::Vector3 scale=Ogre::Vector3(1,1,1));
//adds a static rigidbody to the given mesh shape.
static OgreBulletDynamics::RigidBody* addStaticMeshRigidBody(std::string bodyName,btScaledBvhTriangleMeshShape* shape,OgreBulletDynamics::DynamicsWorld* dynamics,
Ogre::Vector3 position=Ogre::Vector3::ZERO,Quaternion orientation=Quaternion::IDENTITY);
};
/*
class _CustomMotionState:public btMotionState
{
public:
_CustomMotionState(const btTransform &pos, Ogre::SceneNode* objectNode,std::string name)
{
this->objectNode=objectNode;
this->position=pos;
this->name=name;
}
void getWorldTransform(btTransform& worldPos) const
{
worldPos = position;
}
void setWorldTransform(const btTransform& worldPos)
{
btQuaternion orientation = worldPos.getRotation();
Quaternion q(orientation.w(), orientation.x(), orientation.y(), orientation.z());
objectNode->setOrientation(q);
btVector3 pos = worldPos.getOrigin();
objectNode->setPosition(OgreBulletCollisions::BtOgreConverter::to(pos));
}
protected:
Ogre::SceneNode* objectNode;
btTransform position;
std::string name;
};
*/
#endif