A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by FunkyJive » Wed Jun 17, 2009 1:56 pm
I am just getting into the physics aspect of my game and decided to use the Newton SDK. I got a simple demo up and running in my game engine. I then wanted to wrap the physics abstractly into my engine so as to be easier for me. The problem comes when I abstract it away into a class. When I do this the force and torque callback never seems to get called. I have tried everything including unfreezing the body but it never gets updated.
PS. When I do unfreeze the body in the Setup() the callback gets called once but shouldn't it keep updating itself as I continually set the force?
So I tried to create the most basic example and the callback is still is not being called. Here is the code demonstrating the problem.
main.cpp
- Code: Select all
#include "phys.h"
phys physworld;
int main()
{
physworld.Setup();
while(true)
{
physworld.Update();
}
return 0;
}
phys.h
- Code: Select all
#include <iostream>
#include <Newton/Newton.h>
class phys
{
private:
NewtonWorld* world;
NewtonBody* body;
NewtonCollision* collision;
public:
void Setup();
void Update();
};
and finally phys.cpp
- Code: Select all
void PhysicsApplyForceAndTorque(const NewtonBody* body)
{
float curforce[3];
curforce[0] = 0;
curforce[1] = -9.8;
curforce[2] = 0;
NewtonBodySetForce(body, &curforce[0]);
printf("Object updated! \n");
}
void phys::Setup()
{
world = NewtonCreate(NULL, NULL);
dFloat min = -1000;
dFloat max = 1000;
NewtonSetWorldSize(world, &min, &max);
collision = NewtonCreateBox(world, 1,1,1, NULL);
body = NewtonCreateBody(world, collision);
NewtonReleaseCollision(world, collision);
NewtonBodySetMassMatrix(body, 1.0f, 1.0f, 1.0f, 1.0f);
NewtonBodySetForceAndTorqueCallback(body, PhysicsApplyForceAndTorque);
float mat[16];
for(int i=0; i<16; i++)
{
mat[i] = 0;
}
mat[0] = 1;
mat[5] = 1;
mat[10] = 1;
mat[15] = 1;
NewtonBodySetMatrix(body, &mat[0]);
}
void phys::Update()
{
NewtonUpdate(world, 1.0/60.0f);
}
I expect for the output window to get flooded with "Object updated!" but it never gets called once. Forgive me for being new to this library and having minimal knowledge of it.
Any ideas of what is going wrong?
Thanks in advance!
-
FunkyJive
-
- Posts: 6
- Joined: Wed Jun 17, 2009 1:42 pm
by Dave Gravel » Wed Jun 17, 2009 2:01 pm
Your PhysicsApplyForceAndTorque(const NewtonBody* body) callback seen wrong...
[Current from newton 2.01]
typedef void (*NewtonApplyForceAndTorque) (const NewtonBody* body, dFloat timestep, int threadIndex);
-

Dave Gravel
-
- Posts: 801
- Joined: Sat Apr 01, 2006 9:31 pm
- Location: Quebec in Canada.
-
by FunkyJive » Wed Jun 17, 2009 2:43 pm
I am still using Newton 1.53 should I move up to 2.0? Isin't it still in beta?
Anyways the callback will get called if I continually unfreeze the body so the function is getting called if I force it however even when this happens the body doesn't move.
-
FunkyJive
-
- Posts: 6
- Joined: Wed Jun 17, 2009 1:42 pm
by Dave Gravel » Wed Jun 17, 2009 2:53 pm
Ok sorry I thinking you use 2.01 with 1.53 callback method...
I think your error is the world size, you use float but normally they is vector.
-

Dave Gravel
-
- Posts: 801
- Joined: Sat Apr 01, 2006 9:31 pm
- Location: Quebec in Canada.
-
by FunkyJive » Wed Jun 17, 2009 3:05 pm
Thank you so much!!!
I changed it to a vector describing the min and max and now it works. I was seriously pounding my head against the wall.
Thanks again!
-
FunkyJive
-
- Posts: 6
- Joined: Wed Jun 17, 2009 1:42 pm
Return to General Discussion
Who is online
Users browsing this forum: No registered users and 3 guests