FPP camera how solve collision detection problem?

JanBielanski
Posts: 2
Joined: Thu Apr 18, 2013 4:10 pm

FPP camera how solve collision detection problem?

Post by JanBielanski »

Hello
I am new in Bullet Physics library and many things are difficult for me now.
I wrote simple game engine by using OPENGL, GLFW and GLM libraries. Now I am trying add physics simulation from BulletPhysics library.
My physics engine class looking:

Code: Select all

class PhysicsSystem
{
private:
static PhysicsSystem *physicsEngine;
btDynamicsWorld *world;
btDispatcher *dispatcher;
btCollisionConfiguration *collisionConfig;
btBroadphaseInterface *broadphase;
btConstraintSolver *solver;
std::vector<btBvhTriangleMeshShape*> staticObjectCollisionShapes;
std::vector<btRigidBody*> bodies;	
private:
 PhysicsSystem();
 ~PhysicsSystem();
public:
 static PhysicsSystem *initialize(glm::vec3 gravity = glm::vec3(0.0f,-9.8067f,0.0f));
 static PhysicsSystem *remove();	
 void addStaticObjectCollisionShapes(ModelsManager* &model);
 //void deleteStaticObjectCollisionShapes(ModelsManager* &model);	
 void simulationUpdate();
 void addSphere(float rad, glm::vec3 position, float mass, bool useAcceleration = false, glm::vec3 observedpoint = glm::vec3(0.0f,0.0f,0.0f));
 void removeSphere(uint index);
};
PhysicsSystem have full access to Camera. Sample camera update move function look:

Code: Select all

void Camera::forwardMove()
{
  if(!cameraLock) {
	glm::vec3 vMove(0.0f,0.0f,0.0f);
	glm::vec3 rotAngle(0.0f,0.0f,0.0f);
			
	rotAngle = getDirectionRad(true,true,false);
	vMove.x = forwardMoveStep*cos(rotAngle.y)*cos(rotAngle.x);
	vMove.y = forwardMoveStep*sin(rotAngle.y);
	vMove.z = forwardMoveStep*cos(rotAngle.y)*sin(rotAngle.x);
	
        //Here I need check collision for updated position

	vCamPos += vMove;
	vViewPoint += vMove;
  }
}
For my code I need create Kinematic rigid bodies.
The question is:
- How create this type of object?
In code I create some sphere objects, I think this will be useful but i dont know what i should change:

Code: Select all

//Dodanie kuli do testów
void PhysicsSystem::addSphere(float rad, glm::vec3 position, float mass, bool useAcceleration, glm::vec3 observedpoint)
{
	btTransform t;
	t.setIdentity();
	t.setOrigin(btVector3(position.x,position.y,position.z));
	
	btSphereShape* sphere = new btSphereShape(rad);
	btVector3 inertia(0,0,0);
	if(mass!=0.0) {
		sphere->calculateLocalInertia(mass,inertia);
	}
	
	btMotionState *motion = new btDefaultMotionState(t);
	
	btRigidBody::btRigidBodyConstructionInfo info(mass,motion,sphere,inertia);
	btRigidBody *body=new btRigidBody(info);
	
	world->addRigidBody(body);
	
	bodies.push_back(body);
	
	if(useAcceleration) {
		observedpoint *= 2;
		body->setLinearVelocity(btVector3(observedpoint.x,observedpoint.y,observedpoint.z));
	}
}
Can I create kinematic object similary way?
- How update position of this object?

Code: Select all

void cameraPositionUpdate(glm::vec3 newPos); //This function should update position of camera kinematic rigid bodie in PhysicsSystem
I need function similary above in camera class.
- How get information about collision event?

Code: Select all

bool getCollisionEvent(); //This fuction should return information about collision, it should be part of PhysicsSystem
I have hope that description of my problem is understandable.
JanBielanski
Posts: 2
Joined: Thu Apr 18, 2013 4:10 pm

Re: FPP camera how solve collision detection problem?

Post by JanBielanski »

I solved my camera problem. I found solution here http://www.youtube.com/watch?v=R4y7fJpY2_Y .
The information about film was realy helpful.