First I want to clarify that I am using a translator because my English is not good.
I'm using the Ogre3D rendering engine and I need to make use of Bullet Physics for my University project.
The truth is that they have not taught us how to do it, I must learn it on my own and I find it very difficult since I have never worked with a physical simulation engine.
They were only given a class called "MyMotionState" which is as follows:
Code: Select all
#include "MyMotionState.h"
MyMotionState::MyMotionState(const btTransform &initialpos, Ogre::SceneNode *node){
_visibleobj = node;
_pos = initialpos;
}
MyMotionState::~MyMotionState(){ }
void MyMotionState::setNode(Ogre::SceneNode *node) {
_visibleobj = node;
}
void MyMotionState::getWorldTransform(btTransform &worldTrans) const {
worldTrans = _pos;
}
void MyMotionState::setWorldTransform(const btTransform &worldTrans) {
if(NULL == _visibleobj) return; // Si no hay nodo, return
btQuaternion rot = worldTrans.getRotation();
_visibleobj->setOrientation(rot.w(), rot.x(), rot.y(), rot.z());
btVector3 pos = worldTrans.getOrigin();
_visibleobj->setPosition(pos.x(), pos.y(), pos.z());
}
I can not compile OgreBullet and in the University I have not been given a solution, I only have to do manual integration.
Very well now I will explain my game.
I have the gun well positioned, and the camera also, for the moment the Player is not going to be able to move, it will only be able to move your mouse freely.
I need to know which rigid bodies I have to create, for the moment I have created a class called "Physics"
Code: Select all
#include "Physics.h"
Physics::Physics() {
}
Physics::Physics(const Physics& orig) {
}
Physics::~Physics() {
}
void Physics::initObjects(){
collisionConfiguration = new btDefaultCollisionConfiguration();
dispatcher = new btCollisionDispatcher(collisionConfiguration);
overlappingPairCache = new btDbvtBroadphase();
solver = new btSequentialImpulseConstraintSolver();
dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher, overlappingPairCache, solver, collisionConfiguration);
dynamicsWorld->setGravity(btVector3(0,-10,0));
}
btDiscreteDynamicsWorld* Physics::getDynamicsWorld(){
return dynamicsWorld;
}
std::vector<btCollisionShape *> Physics::getCollisionShapes(){
return collisionShapes;
}
Code: Select all
void PlayState::createBullet(){
_contador++;
string idBullet = static_cast<std::ostringstream*>(&(std::ostringstream() << _contador))->str();
Ogre::Entity* entBullet = _sceneMgr->createEntity("Bullet"+idBullet+"Ent", "Circle.mesh");
Ogre::SceneNode* nodeBullet = _sceneMgr->getRootSceneNode()->createChildSceneNode("NodeBullet" + idBullet);
nodeBullet->attachObject(entBullet);
Ogre::Vector3 posWeapon = _sceneMgr->getRootSceneNode()->convertLocalToWorldPosition(_nodePerson->getPosition());
Ogre::Quaternion oriWeapon = _sceneMgr->getRootSceneNode()->convertLocalToWorldOrientation(_nodePerson->getOrientation());
posWeapon.y = posWeapon.y + 3;
posWeapon = _camera->getRealPosition();
oriWeapon = _camera->getRealOrientation();
nodeBullet->setPosition(posWeapon);
nodeBullet->setOrientation(oriWeapon);
MyMotionState* fallMotionState = new MyMotionState(
btTransform(btQuaternion(0,0,0,1),btVector3(0,0,0)), nodeBullet);
btScalar mass = 0.1;
btVector3 fallInertia(0,0,0);
_fallShape->calculateLocalInertia(mass,fallInertia);
btRigidBody::btRigidBodyConstructionInfo fallRigidBodyCI(
mass,fallMotionState,_fallShape,fallInertia);
_fallRigidBody = new btRigidBody(fallRigidBodyCI);
_fallRigidBody->setCollisionFlags(_fallRigidBody->getCollisionFlags() & ~btCollisionObject::CF_STATIC_OBJECT);
physicsEngine->getDynamicsWorld()->addRigidBody(_fallRigidBody);
_fallRigidBody->activate(true);
btTransform weaponTransform(btQuaternion(oriWeapon.x, oriWeapon.y, oriWeapon.z, oriWeapon.w),btVector3(posWeapon.x, posWeapon.y, posWeapon.z));
btTransform weaponRotation = weaponTransform;
weaponRotation.setOrigin(btVector3(0.0, 0.0, 0.0));
btVector3 localZ(0.0, 0.0, 1.0);
btVector3 shootDirection = weaponRotation * localZ;
btScalar bulletSpeed = 20000.0;
btVector3 bulletVelocity = bulletSpeed * shootDirection;
btScalar weaponBarrelLength = 0.5;
btVector3 bulletPosition = weaponTransform.getOrigin() + weaponBarrelLength * (weaponRotation * localZ);
_fallRigidBody->setLinearVelocity(bulletVelocity);
btTransform bulletTransform = weaponRotation;
bulletTransform.setOrigin(bulletPosition);
_fallRigidBody->setWorldTransform(bulletTransform);
}
I really do not know how to solve it.
I do not mind having a good physics, I just want basic physics.
I want the bullet to move in the appropriate direction.
Then I will be interested to know about collision, but for the moment this is the problem that I want to solve.