FORUM CLOSED, PLEASE REGISTER AT FORUM.SIO2INTERACTIVE.COM
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Terrain Clamping

3 posters

Go down

Terrain Clamping Empty Terrain Clamping

Post  flying24 Fri Feb 13, 2009 3:09 am

Has anyone had any luck with terrain clamping yet? Or any sample code that would point us in the right direction?

Thank you!

flying24

Posts : 9
Join date : 2009-02-13

Back to top Go down

Terrain Clamping Empty Re: Terrain Clamping

Post  sio2interactive Fri Feb 13, 2009 4:04 am

Check tutorial06_1 or 06_2 for an FPS camera, for a third person camera check tutorial09...
sio2interactive
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 45
Location : Shanghai

http://sio2interactive.com

Back to top Go down

Terrain Clamping Empty Re: Terrain Clamping

Post  flying24 Fri Feb 13, 2009 4:58 am

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

Back to top Go down

Terrain Clamping Empty Re: Terrain Clamping

Post  sio2interactive Fri Feb 13, 2009 4:03 pm

give me and example... and please define what you consider "mesh" and "object"
sio2interactive
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 45
Location : Shanghai

http://sio2interactive.com

Back to top Go down

Terrain Clamping Empty Re: Terrain Clamping

Post  flying24 Sat Feb 14, 2009 1:40 am

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

Back to top Go down

Terrain Clamping Empty Re: Terrain Clamping

Post  sio2interactive Sat Feb 14, 2009 6:16 am

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 Wink... 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 Wink

Please check again tutorial06 & 09 for more info...


Cheers,
sio2interactive
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 45
Location : Shanghai

http://sio2interactive.com

Back to top Go down

Terrain Clamping Empty Re: Terrain Clamping

Post  flying24 Sat Feb 14, 2009 11:55 pm

Ok I think I can figure out how to do that. Thank you for your help!

flying24

Posts : 9
Join date : 2009-02-13

Back to top Go down

Terrain Clamping Empty Re: Terrain Clamping

Post  flying24 Mon Feb 16, 2009 1:31 am

I got it working to an extent. Here is the code I used:


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

Back to top Go down

Terrain Clamping Empty Re: Terrain Clamping

Post  yarri Thu Jun 11, 2009 1:32 am

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

yarri

Posts : 81
Join date : 2009-04-10

Back to top Go down

Terrain Clamping Empty Re: Terrain Clamping

Post  sio2interactive Thu Jun 11, 2009 1:45 am

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...
sio2interactive
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 45
Location : Shanghai

http://sio2interactive.com

Back to top Go down

Terrain Clamping Empty Re: Terrain Clamping

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum