Bullet First Person Camera with Collision

Physics APIs, Physics file formats, Maya, Max, XSI, Cinema 4D, Lightwave, Blender, thinkingParticles™ and other simulation tools, exporters and importers
GLphyX
Posts: 2
Joined: Tue Oct 30, 2007 11:44 pm

Bullet First Person Camera with Collision

Post by GLphyX »

Can someone please help im kinda stuck, like the subject of this topic imply im trying to implement a first person camera using bullet. My problem is that I cannot find on method to be capable to do it... here's my code below and the problem that I meet for all of them, the following code use cylinder, but I also try with sphere and cube without success... can someone point me out what Im doing wrong or give me an example how to get it done...

Tks in advance,

Cheers!

Code: Select all


		...
		...

		camera->shape = new btCylinderShapeZ( btVector3( 1.0, 0.0, 2.0 ) );

		camera->shape->setMargin( 0.5 );
		
		trans.setIdentity();
		
		camera->motion = new btDefaultMotionState( trans );
		
		camera->shape->calculateLocalInertia( 80.0, inertia );
		
		camera->body = new btRigidBody( 80.0, camera->motion, camera->shape, inertia,
											 (btScalar)10.0,
											 (btScalar)10.0,
											 (btScalar)10.0,
											 (btScalar)10.0 );
		
		camera->body->setAngularFactor( 0.0 );

		world->addRigidBody( camera->body );


		...
		...

		// Front & Back ~ Working but because of the translation motion when
		// I go to a corner and forward I got some major jaggin....
		camera->body->translate( btVector3( ( _dir * camera->dir->x ) / camera->speed,
							  ( _dir * camera->dir->y ) / camera->speed,
							  0.0 ) );


			/*
			// Work but cannot stay stable when climbing stairs
			camera->body->internalApplyImpulse( btVector3( -camera->vel->x,
									     -camera->vel->y,
									     0.5 ),
									     btVector3( 0.0, 0.0, 0.0 ),
									     0.25 );
			*/
			
			/*
			// Work but cannot climb stairs or ramps ( this is the one that give the most smooth result but...)
			camera->body->internalApplyImpulse( btVector3( -camera->vel->x,
														   		-camera->vel->y,
														   		0.0 ),
													btVector3( 0.0, 0.0, 0.0 ),
												    0.25 );
			*/
			
			
			/*
			// Work but cannot climb stairs or ramps
			camera->body->applyImpulse(  btVector3( -camera->vel->x * camera->speed,
														 -camera->vel->y * camera->speed,
														 -1.0 ),
														
											 btVector3( camera->pos->x,
														camera->pos->y,
														camera->pos->z ) );
			*/
			
			
			/*
			// Work but cannot climb stairs or ramps
			camera->body->setLinearVelocity( btVector3( -camera->vel->x * camera->speed,
														 		   -camera->vel->y * camera->speed,
														   		   -10.0 ) );
			*/
	...
	...