dynamicsWorld->rayTest issues

JohnBoyManbullet

17-07-2011 01:51:03

Hello all i am using dynamicsWorld->rayTest to test my rays when they hit terrain. I find that when i use the test in my frame started or frameRenderingQueued my screen get choppy right when it detects a hit. the frame kinda freezes for that moment. it is very annoying, i ruins everything i had been working on. Can someone give me some advice on where i should put it or how i can sovle this .

thanks

JohnBoyManbullet

17-07-2011 04:23:13

I figured it out, the step simulation was off. so i reset it to dynamicsWorld->stepSimulation(evt.timeSinceLastFrame, 1.0 / 60.0);

captaincrunch80

17-07-2011 04:37:35

Take care John!

The function definition is this:

void stepSimulation(const Ogre::Real elapsedTime, int maxSubSteps = 1, const Ogre::Real fixedTimestep = 1./60.);


That means you just assigned maxSubSteps = 1.0/60.0 what will result in ZERO after conversion to integer .... do you see it ?
That could lead to odd behavior. If you do not know what you are doing, leave the defaults.

maxSubSteps == 0 ?

If you pass maxSubSteps=0 to the function, then it will assume a variable tick rate. Every tick, it will move the simulation along by exactly the timeStep you pass, in a single tick, instead of a number of ticks equal to fixedTimeStep.
This is not officially supported, and the death of determinism and framerate independance. Don't do it.

(Quote from Bullet Wiki)


You should read the wiki page that covers this
http://bulletphysics.org/mediawiki-1.5.8/index.php/Stepping_The_World
and set it optimized for your application.


Best regards, and better results!

JohnBoyManbullet

17-07-2011 07:07:31

thanks your right i fixed it

captaincrunch80

17-07-2011 08:14:10

Ah good.

I hope that solved your problem.

About the Raycast to terrain. That's a function of mine. I use it for walking on the terrain and for the PagedGeometry AddOn.



Ogre::Ray ray;
float
getTerrainHeight(const float x, const float z, void *userData){
ray.setOrigin(Ogre::Vector3(x, 10000.0f, z));
ray.setDirection(Ogre::Vector3::NEGATIVE_UNIT_Y);
Ogre::TerrainGroup::RayResult rayResult = mTerrainGroup->rayIntersects(ray);
return rayResult.position.y;
}


It works good so far.
This happens about 1.000.000 while loading the Terrain (for each grass and tree and bush that has to be placed) and later at least once per frame (in the frameEnded function, frameQuery does my physics) with no big performance impact.

What also could lead to lag is CCD (Continuous Collision Detection). Have you activated it on RigitBodies?
Means: Have you used these functions?
bulletBody->getBulletRigidBody()->setCcdMotionThreshold(0.0001);
bulletBody->getBulletRigidBody()->setCcdSweptSphereRadius(0.9*size.length());
If yes try without or use a higher Threshold. Only use these for small high speed objects that could slip trough the terrain or other objects otherwise.

JohnBoyManbullet

19-07-2011 05:30:36

i have done non of this


What also could lead to lag is CCD (Continuous Collision Detection). Have you activated it on RigitBodies?
Means: Have you used these functions?
bulletBody->getBulletRigidBody()->setCcdMotionThreshold(0.0001);
bulletBody->getBulletRigidBody()->setCcdSweptSphereRadius(0.9*size.length());
If yes try without or use a higher Threshold. Only use these for small high speed objects that could slip trough the terrain or other objects otherwise.


I have done non of that, the ray test still makes the screen choppy, is the above in relation to fixing that?