Newton Moving Object to an Irrlicht Camera Target

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Newton Moving Object to an Irrlicht Camera Target

Postby Nutu » Sun May 30, 2010 7:53 am

Hello again, I have another little problem to solve .
Code here:
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
*.......
*other code here
*................... //Here is the code that generates the problem
dir= camera->getTarget() - camera->getPosition(); //I get the camera target
dir.normalize(); //Normalize the 3df verctor
totalSpeed[0]=dir.X; //Assign the vector values to the speed
totalSpeed[1]=dir.Y;
totalSpeed[2]=dir.Z;
nodeRotation =camera->getRotation(); //I rotate the Mesh .. etc
vNode->setRotation(nodeRotation);
NewtonBodySetVelocity(body,zeroForce); //Here I apply the speed to my object
*...
*other code here
*.........
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
So, I first get the target direction of my Irrlicht FPS camera, then i set a speed on the object to that direction and the object moves into that direction, quite simple
-------------------------------------------------------Problem----------------------------------------------------------------------------------------------------------------------------
The problem is that each time i rotate the camera with the mouse, as the new target values change, my object stops moving.
It is because the FPS camera in Irrlicht refreshes is such a way that it stops the Physics engine to work ?
* While the camera moves, the object doesn't move into the camera direction
* While the camera is not rotating, the object moves to the camera direction
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Nutu
 
Posts: 4
Joined: Sat May 15, 2010 9:54 am

Re: Newton Moving Object to an Irrlicht Camera Target

Postby Nutu » Sun Jun 13, 2010 12:46 pm

Well I finally solved this little problem.
In my application I used Irrlicht as the game engine.
I created an irrlicht Fps camera, an object and a Newton World
My object contains an AnimatedMEshSceneNode, a NewtonMesh* nwtMesh and a NewtonBody* body.

To move it in the mainLoop of the game I called a function: getInput(), defined in my object. the function looked at the camera coordinates, rotation etc , and applied on the newtonBody a force in the direction of the camera.
But the FPS camera in irrlicht has an animator called each time you send an input so the camera basically moves much faster than the times you can call the getInput() and so at 700-800 FPS( demo xD ) my character lagged o_O.

To solve this i put the getInput() int the cameras animator, so each time the animator is called, you call also the getInput();
This way, you update the force applied on the object corectly and your char don't lag any more.

(Hope this is usefull for somboy :-) )
Nutu
 
Posts: 4
Joined: Sat May 15, 2010 9:54 am


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron