void GhostComponent::setParent(Entity* entity) { PhysicsComponent::setParent(entity); btCollisionShape* ghostShape; this->ghostObject = new btGhostObject(); BtOgre::StaticMeshToShapeConverter* converter = new BtOgre::StaticMeshToShapeConverter(this->physicsEntity); if (this->physicsShape == PhysicsModule::PLANE) { ghostShape = converter->createPlane(); } else { ghostShape = converter->createBox(); ghostShape->setLocalScaling(btVector3(0.5, 0.5, 0.5)); } Ogre::Vector3 position = this->parent->getNode()->_getDerivedPosition(); btTransform trans(btTransform(btQuaternion(0, 0, 0, 1), BtOgre::Convert::toBullet(position))); this->ghostObject->setCollisionShape(ghostShape); this->ghostObject->setUserPointer(this); this->ghostObject->setWorldTransform(trans); this->ghostObject->setCollisionFlags(btCollisionObject::CF_NO_CONTACT_RESPONSE | this->ghostObject->getCollisionFlags()); ENGINE->getPhysics()->getWorld()->addCollisionObject(ghostObject, PhysicsModule::CollisionMask::COL_GHOST, PhysicsModule::CollisionMask::COL_PLAYER); }
void PhysicsComponent::createBody() { int numObjects = this->parent->getNode()->numAttachedObjects(); if (numObjects > 0) { physicsEntity = dynamic_cast<Ogre::Entity*> (parent->getNode()->getAttachedObject(0)); BtOgre::StaticMeshToShapeConverter* converter = new BtOgre::StaticMeshToShapeConverter(physicsEntity); switch (physicsShape) { case PhysicsModule::BOX: { shape = converter->createBox(); break; } case PhysicsModule::CYLINDER: { shape = converter->createCylinder(); break; } case PhysicsModule::TRIMESH: { shape = converter->createTrimesh(); break; } case PhysicsModule::PLANE: { shape = converter->createPlane(); break; } case PhysicsModule::SPHERE: default: { shape = converter->createSphere(); break; } } } else { switch (physicsShape) { case PhysicsModule::BOX: { shape = new btBoxShape(btVector3(0, 0, 0)); break; } case PhysicsModule::CYLINDER: { shape = new btCylinderShape(btVector3(0, 0, 0)); break; } case PhysicsModule::PLANE: { shape = new btStaticPlaneShape(btVector3(0, 1, 0), 1); break; } case PhysicsModule::TRIMESH: case PhysicsModule::SPHERE: default: { shape = new btSphereShape(0); break; } } } // calculating inertia if (mass != 0) { inertia = btVector3(0, 0, 0); shape->calculateLocalInertia(mass, inertia); } else { inertia = btVector3(0, 0, 0); } // creating BtOgre MotionState (connects Ogre and Bullet) state = new BtOgre::RigidBodyState(parent->getNode()); btRigidBody::btRigidBodyConstructionInfo bodyProps(mass, state, shape, inertia); bodyProps.m_friction = 20; body = new btRigidBody(bodyProps); // creating the Body if (mass == 0) { body->setCollisionFlags(body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT); body->setActivationState(DISABLE_DEACTIVATION); } body->setUserPointer(this); ENGINE->getPhysics()->getWorld()->addRigidBody(body, group, mask); }