Problem controlling Newton.

BlitzMax Forums/BlitzMax Programming/Problem controlling Newton.

DirtBikeDude(Posted 2006) [#1]
I need to create a space sim movement in Newton. I started using a falling box tutorial by Haramanai http://www.blitzmax.com/Community/posts.php?topic=51140.
When I change the values for force, Newton does'nt use the new values. Maybe I need to call a function somewhere.
Here's the Newton functions



DirtBikeDude(Posted 2006) [#2]
I found a post in the newton forums about changing the force values during gameplay. http://newtondynamics.com/forum/viewtopic.php?t=2627
I was wondering if someone could help me interpret this code.
This newton wrapper is confussing me.


Sweenie(Posted 2006) [#3]
Move the line
NewtonBodyGetMassMatrix (Body,Varptr Mass, Varptr IXX, Varptr IYY, Varptr IZZ);

to the line above the part there you multiply the mass with the forces.
In the current state you multiply the forcevalues with a zero mass.


DirtBikeDude(Posted 2006) [#4]
Ok, the force was added when I set a value to the force at the begining of the game. My input code changes the values for force.
The mesh still does'nt move with input.
The post I found was about the same problem. They solved it with NewtonbodySetFreeze and NewtonWorldSetAutoFreeze. The post was in C++, I don't know where and how to implement it.

Here's my force and torque function.



Sweenie(Posted 2006) [#5]
You still haven't move that line...

change this...
Local Force:Float[] =  [-mass * ForceX, -mass * ForceY, -mass * ForceZ]
Local Torque:Float[] = [TorqueX, TorqueY, TorqueZ]
NewtonBodyGetMassMatrix (Body,Varptr Mass, Varptr IXX, Varptr IYY, Varptr IZZ);


to this...
NewtonBodyGetMassMatrix (Body,Varptr Mass, Varptr IXX, Varptr IYY, Varptr IZZ);
Local Force:Float[] =  [-mass * ForceX, -mass * ForceY, -mass * ForceZ]
Local Torque:Float[] = [TorqueX, TorqueY, TorqueZ]


When you declare the mass variable as local in the beginning it will be set to 0.
NewtonBodyGetMassMatrix retrieves the mass and inertia values for the body which you when use to apply the correct force.

To make sure the body is always responding to input even if it's gone to sleep you can trigger the function NewtonWorldUnfreezeBody at the same time you press any of the keys.

Using NewtonBodySetAutoFreeze to make a body active all the time works as well, but defeats the purpose of the autosleep function which is important for performance, especially if you have a large amount of bodies.

If you still want to use it you just call it right after the creation of the body.


DirtBikeDude(Posted 2006) [#6]
sorry, this was my code.


Same problem.
But, how do I setup a newton command out side the newton function, in the input method?
When I added the NewtonWorldUnfreezeBody(nWorld, body) command in my input method I get the error "Identifier 'body' not found". These wrapper modules are confusing.
Thank you.


Sweenie(Posted 2006) [#7]
The PhysicsApplyForceAndTorque (Body:Byte Ptr) is a callback function that the physicsengine will call every time it is updating the physics for every body in the simulation.
The passed parameter is the pointer to the Body it's currently updating.

If you want to affect a body outside this callback function you will have to use your own pointer to this body. In your case I believe it's the BoxBody variable?