Terrain Clamping
3 posters
Terrain Clamping
Has anyone had any luck with terrain clamping yet? Or any sample code that would point us in the right direction?
Thank you!
Thank you!
flying24- Posts : 9
Join date : 2009-02-13
Re: Terrain Clamping
Check tutorial06_1 or 06_2 for an FPS camera, for a third person camera check tutorial09...
Re: Terrain Clamping
By terrain clamping I mean locking an object to a mesh, which would allow it to follow the mesh without having to use physics.
flying24- Posts : 9
Join date : 2009-02-13
Re: Terrain Clamping
Think of a game like Mario Kart where you have a "player object" that stays upright relative to the "terrain mesh" even when you are in the air above it. It would probably involve some sort of ray casting downward from the "player" that would then return the angle of the "terrain" directly below it and adjust the player so that his rotation is orthogonal to the terrain. Does that make sense?
flying24- Posts : 9
Join date : 2009-02-13
Re: Terrain Clamping
You can easily do a collision ray with the world and get back the point in space and its normal, after that is just a matter of acos a dot product to get the angle ... check tutorial09 for more info about the collision ray... however any collision shape would do the same thing automatically anyway so you should actually leave that to bullet
Please check again tutorial06 & 09 for more info...
Cheers,
Please check again tutorial06 & 09 for more info...
Cheers,
Re: Terrain Clamping
Ok I think I can figure out how to do that. Thank you for your help!
flying24- Posts : 9
Join date : 2009-02-13
Re: Terrain Clamping
I got it working to an extent. Here is the code I used:
This casts a ray straight downwards, then uses ray.m_hitPointWorld to determine the z position of the terrain below. ray.m_hitNormalWorld can be used to find the angle of the terrain and tilt the camera or player object accordingly.
- Code:
btVector3 from( sio2->_SIO2camera->_SIO2transform->loc->x,
sio2->_SIO2camera->_SIO2transform->loc->y,
sio2->_SIO2camera->_SIO2transform->loc->z + 100.0f );
btVector3 to( sio2->_SIO2camera->_SIO2transform->loc->x, sio2->_SIO2camera->_SIO2transform->loc->y, sio2->_SIO2camera->_SIO2transform->loc->z - 100.0f );
btCollisionWorld::ClosestRayResultCallback ray( from, to );
sio2->_SIO2physic->_btSoftRigidDynamicsWorld->getCollisionWorld()->rayTest( from, to, ray );
if( ray.hasHit() )
{
VAR1 = ray.m_hitPointWorld.z();
ray.m_hitNormalWorld.normalize();
VAR2 = ray.m_hitNormalWorld.y();
}
This casts a ray straight downwards, then uses ray.m_hitPointWorld to determine the z position of the terrain below. ray.m_hitNormalWorld can be used to find the angle of the terrain and tilt the camera or player object accordingly.
flying24- Posts : 9
Join date : 2009-02-13
Re: Terrain Clamping
Hi, has anyone else noticed that when you cast a ray this way that the call to affects rigid body collisions? What I'm seeing is that after calls to m_hitPointWorld(), my physic objects don't collide properly with meshes as though something is being affected in collision callbacks.
This thread in the Bullet forums suggest that you should use a BroadphaseProxy filter:
http://bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=3392&p=13053&hilit=rayTest#p13053
But I can't get it to work within SIO2. Any other tips on how to effectively calculate the object/player's height above the terrain/mesh?
Would hate to have to calculate by hand or use a height map, rayTest should work.
--yarri
This thread in the Bullet forums suggest that you should use a BroadphaseProxy filter:
http://bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=3392&p=13053&hilit=rayTest#p13053
But I can't get it to work within SIO2. Any other tips on how to effectively calculate the object/player's height above the terrain/mesh?
Would hate to have to calculate by hand or use a height map, rayTest should work.
--yarri
yarri- Posts : 81
Join date : 2009-04-10
Re: Terrain Clamping
I can guarantee you that the hit ray in bullet have no side effect... Im using them intensively in my game and haven't notice any strange effect...
Permissions in this forum:
You cannot reply to topics in this forum