1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-22 18:32:44 +01:00

clang-format files in rwengine/src/dynamics

This commit is contained in:
Daniel Evans 2016-09-09 21:13:18 +01:00
parent d5e853d23f
commit 8534d7ff5d
3 changed files with 169 additions and 168 deletions

View File

@ -1,26 +1,23 @@
#include <dynamics/CollisionInstance.hpp>
#include <objects/GameObject.hpp>
#include <engine/GameWorld.hpp>
#include <engine/GameData.hpp>
#include <engine/GameWorld.hpp>
#include <objects/GameObject.hpp>
class GameObjectMotionState : public btMotionState
{
class GameObjectMotionState : public btMotionState {
public:
GameObjectMotionState(GameObject *object)
: m_object(object)
{ }
GameObjectMotionState(GameObject* object) : m_object(object) {
}
virtual void getWorldTransform(btTransform& tform) const
{
virtual void getWorldTransform(btTransform& tform) const {
auto& position = m_object->getPosition();
auto& rotation = m_object->getRotation();
tform.setOrigin(btVector3(position.x, position.y, position.z));
tform.setRotation(btQuaternion(rotation.x, rotation.y, rotation.z, rotation.w));
tform.setRotation(
btQuaternion(rotation.x, rotation.y, rotation.z, rotation.w));
}
virtual void setWorldTransform(const btTransform& tform)
{
virtual void setWorldTransform(const btTransform& tform) {
auto& o = tform.getOrigin();
auto r = tform.getRotation();
glm::vec3 position(o.x(), o.y(), o.z());
@ -32,8 +29,7 @@ private:
GameObject* m_object;
};
CollisionInstance::~CollisionInstance()
{
CollisionInstance::~CollisionInstance() {
if (m_body) {
GameObject* object = static_cast<GameObject*>(m_body->getUserPointer());
@ -54,8 +50,10 @@ CollisionInstance::~CollisionInstance()
}
}
bool CollisionInstance::createPhysicsBody(GameObject *object, const std::string& modelName, DynamicObjectData *dynamics, VehicleHandlingInfo *handling)
{
bool CollisionInstance::createPhysicsBody(GameObject* object,
const std::string& modelName,
DynamicObjectData* dynamics,
VehicleHandlingInfo* handling) {
auto phyit = object->engine->data->collisions.find(modelName);
if (phyit != object->engine->data->collisions.end()) {
btCompoundShape* cmpShape = new btCompoundShape;
@ -63,7 +61,8 @@ bool CollisionInstance::createPhysicsBody(GameObject *object, const std::string&
m_motionState = new GameObjectMotionState(object);
m_shapes.push_back(cmpShape);
btRigidBody::btRigidBodyConstructionInfo info(0.f, m_motionState, cmpShape);
btRigidBody::btRigidBodyConstructionInfo info(0.f, m_motionState,
cmpShape);
CollisionModel& physInst = *phyit->second.get();
@ -75,8 +74,10 @@ bool CollisionInstance::createPhysicsBody(GameObject *object, const std::string&
auto& box = physInst.boxes[i];
auto size = (box.max - box.min) / 2.f;
auto mid = (box.min + box.max) / 2.f;
btCollisionShape* bshape = new btBoxShape( btVector3(size.x, size.y, size.z) );
btTransform t; t.setIdentity();
btCollisionShape* bshape =
new btBoxShape(btVector3(size.x, size.y, size.z));
btTransform t;
t.setIdentity();
t.setOrigin(btVector3(mid.x, mid.y, mid.z));
cmpShape->addChildShape(t, bshape);
@ -90,8 +91,10 @@ bool CollisionInstance::createPhysicsBody(GameObject *object, const std::string&
for (size_t i = 0; i < physInst.spheres.size(); ++i) {
auto& sphere = physInst.spheres[i];
btCollisionShape* sshape = new btSphereShape(sphere.radius);
btTransform t; t.setIdentity();
t.setOrigin(btVector3(sphere.center.x, sphere.center.y, sphere.center.z));
btTransform t;
t.setIdentity();
t.setOrigin(
btVector3(sphere.center.x, sphere.center.y, sphere.center.z));
cmpShape->addChildShape(t, sshape);
colMin = std::min(colMin, sphere.center.z - sphere.radius);
@ -102,15 +105,14 @@ bool CollisionInstance::createPhysicsBody(GameObject *object, const std::string&
if (physInst.vertices.size() > 0 && physInst.indices.size() >= 3) {
m_vertArray = new btTriangleIndexVertexArray(
physInst.indices.size()/3,
(int*) physInst.indices.data(),
sizeof(uint32_t)*3,
physInst.vertices.size(),
&(physInst.vertices[0].x),
sizeof(glm::vec3));
btBvhTriangleMeshShape* trishape = new btBvhTriangleMeshShape(m_vertArray, false);
physInst.indices.size() / 3, (int*)physInst.indices.data(),
sizeof(uint32_t) * 3, physInst.vertices.size(),
&(physInst.vertices[0].x), sizeof(glm::vec3));
btBvhTriangleMeshShape* trishape =
new btBvhTriangleMeshShape(m_vertArray, false);
trishape->setMargin(0.05f);
btTransform t; t.setIdentity();
btTransform t;
t.setIdentity();
cmpShape->addChildShape(t, trishape);
m_shapes.push_back(trishape);
@ -121,15 +123,13 @@ bool CollisionInstance::createPhysicsBody(GameObject *object, const std::string&
if (dynamics) {
if (dynamics->uprootForce > 0.f) {
info.m_mass = 0.f;
}
else {
} else {
btVector3 inert;
cmpShape->calculateLocalInertia(dynamics->mass, inert);
info.m_mass = dynamics->mass;
info.m_localInertia = inert;
}
}
else if( handling ) {
} else if (handling) {
btVector3 inert;
cmpShape->calculateLocalInertia(handling->mass, inert);
info.m_mass = handling->mass;
@ -141,20 +141,18 @@ bool CollisionInstance::createPhysicsBody(GameObject *object, const std::string&
object->engine->dynamicsWorld->addRigidBody(m_body);
if (dynamics && dynamics->uprootForce > 0.f) {
m_body->setCollisionFlags(m_body->getCollisionFlags()
| btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK);
m_body->setCollisionFlags(
m_body->getCollisionFlags() |
btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK);
}
}
else
{
} else {
return false;
}
return true;
}
void CollisionInstance::changeMass(float newMass)
{
void CollisionInstance::changeMass(float newMass) {
GameObject* object = static_cast<GameObject*>(m_body->getUserPointer());
auto dynamicsWorld = object->engine->dynamicsWorld;
dynamicsWorld->removeRigidBody(m_body);

View File

@ -3,8 +3,8 @@
#define _COLLISIONINSTANCE_HPP_
#include <btBulletDynamicsCommon.h>
#include <vector>
#include <string>
#include <vector>
class GameObject;
struct DynamicObjectData;
@ -13,27 +13,28 @@ struct VehicleHandlingInfo;
/**
* @brief CollisionInstance stores bullet body information
*/
class CollisionInstance
{
class CollisionInstance {
public:
CollisionInstance()
: m_body(nullptr)
, m_vertArray(nullptr)
, m_motionState(nullptr)
, m_collisionHeight(0.f)
{ }
, m_collisionHeight(0.f) {
}
~CollisionInstance();
bool createPhysicsBody(GameObject* object,
const std::string &modelName,
bool createPhysicsBody(GameObject* object, const std::string& modelName,
DynamicObjectData* dynamics = nullptr,
VehicleHandlingInfo* handling = nullptr);
btRigidBody *getBulletBody() const { return m_body; }
btRigidBody* getBulletBody() const {
return m_body;
}
float getBoundingHeight() const { return m_collisionHeight; }
float getBoundingHeight() const {
return m_collisionHeight;
}
void changeMass(float newMass);
@ -44,7 +45,6 @@ private:
btMotionState* m_motionState;
float m_collisionHeight;
};
#endif

View File

@ -4,19 +4,22 @@
/**
* Implements raycast callback that ignores a specified btCollisionObject
*/
class ClosestNotMeRayResultCallback : public btCollisionWorld::ClosestRayResultCallback
{
class ClosestNotMeRayResultCallback
: public btCollisionWorld::ClosestRayResultCallback {
btCollisionObject* _self;
public:
ClosestNotMeRayResultCallback(btCollisionObject* self,
const btVector3& from, const btVector3& to)
: ClosestRayResultCallback(from, to), _self(self) {
}
ClosestNotMeRayResultCallback( btCollisionObject* self, const btVector3& from, const btVector3& to )
: ClosestRayResultCallback( from, to ), _self( self ) {}
virtual btScalar addSingleResult(btCollisionWorld::LocalRayResult &rayResult, bool normalInWorldSpace)
{
virtual btScalar addSingleResult(
btCollisionWorld::LocalRayResult& rayResult, bool normalInWorldSpace) {
if (rayResult.m_collisionObject == _self) {
return 1.0;
}
return ClosestRayResultCallback::addSingleResult( rayResult, normalInWorldSpace );
return ClosestRayResultCallback::addSingleResult(rayResult,
normalInWorldSpace);
}
};