Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include "btBulletDynamicsCommon.h"
- #include "components/TransformComponent.hpp"
- #include "physics/MyMotionState.hpp"
- namespace sw {
- struct PhysicsComponent : public ex::Component<PhysicsComponent> {
- PhysicsComponent() { }
- ~PhysicsComponent() {
- delete motionState_;
- delete shape_;
- delete body_;
- }
- PhysicsComponent(ex::Entity entity, btCollisionShape *collisionShape,
- btScalar mass = 0.0f, short group = sw::COL_DYNAMIC, short mask = sw::COL_STATIC)
- : group_(group), mask_(mask) {
- motionState_ = new MyMotionState(entity);
- shape_ = collisionShape;
- //shape_ = new btBoxShape(btVector3(2.0f, 1.0f, 1.0f));
- // calculate the local inertia
- btVector3 localInertia(0, 0, 0);
- // objects of infinite mass can't
- // move or rotate
- if (mass != 0.0f)
- shape_->calculateLocalInertia(mass, localInertia);
- btRigidBody::btRigidBodyConstructionInfo bodyConstructionInfo(mass, motionState_, shape_, localInertia);
- body_ = new btRigidBody(bodyConstructionInfo);
- }
- short group_;
- short mask_;
- MyMotionState *motionState_;
- btCollisionShape *shape_;
- btRigidBody *body_;
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement