Advertisement
Guest User

PhysicsComponent

a guest
May 19th, 2015
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.42 KB | None | 0 0
  1. #pragma once
  2.  
  3. #include "btBulletDynamicsCommon.h"
  4. #include "components/TransformComponent.hpp"
  5. #include "physics/MyMotionState.hpp"
  6.  
  7. namespace sw {
  8.  
  9.     struct PhysicsComponent : public ex::Component<PhysicsComponent> {
  10.  
  11.         PhysicsComponent() { }
  12.  
  13.         ~PhysicsComponent() {
  14.             delete motionState_;
  15.             delete shape_;
  16.             delete body_;
  17.         }
  18.  
  19.         PhysicsComponent(ex::Entity entity, btCollisionShape *collisionShape,
  20.                          btScalar mass = 0.0f, short group = sw::COL_DYNAMIC, short mask = sw::COL_STATIC)
  21.                 : group_(group), mask_(mask) {
  22.  
  23.             motionState_ = new MyMotionState(entity);
  24.             shape_ = collisionShape;
  25.  
  26.             //shape_ = new btBoxShape(btVector3(2.0f, 1.0f, 1.0f));
  27.  
  28.             // calculate the local inertia
  29.             btVector3 localInertia(0, 0, 0);
  30.  
  31.             // objects of infinite mass can't
  32.             // move or rotate
  33.  
  34.  
  35.  
  36.             if (mass != 0.0f)
  37.                 shape_->calculateLocalInertia(mass, localInertia);
  38.  
  39.  
  40.             btRigidBody::btRigidBodyConstructionInfo bodyConstructionInfo(mass, motionState_, shape_, localInertia);
  41.  
  42.             body_ = new btRigidBody(bodyConstructionInfo);
  43.  
  44.  
  45.         }
  46.  
  47.  
  48.         short group_;
  49.         short mask_;
  50.  
  51.         MyMotionState *motionState_;
  52.  
  53.         btCollisionShape *shape_;
  54.  
  55.         btRigidBody *body_;
  56.  
  57.  
  58.     };
  59.  
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement