TorqueAndForceCallback

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

TorqueAndForceCallback

Postby spark-plug » Wed Jul 22, 2009 9:29 am

I'm sorry because of having this question, but I haven't found any topic with a solution.

I have no idea why my forcecallback doesn't work:

Code: Select all
void spInitiatePhysics(void)
{
   nWorld = NewtonCreate(NULL,NULL);

   dVector minSize(-10000, -10000, -10000);
   dVector maxSize( 10000,  10000,  10000);
   NewtonSetWorldSize(nWorld, &minSize[0], &maxSize[0]);
}

void spForceCallback(const NewtonBody* body)
{
   dFloat mass;
   dFloat Ixx;
   dFloat Iyy;
   dFloat Izz;
   float force[3];

   NewtonBodyGetMassMatrix (body,&mass,&Ixx,&Iyy,&Izz);
   force[0]=0.0;
   force[1]=-mass*9.81;
   force[2]=0.0;
   NewtonBodySetForce(body,force);
}

void main(void)
{
   spInitiatePhysics();

   cCar = NewtonCreateBox(nWorld,30,30,30,fCar);
   bCar = NewtonCreateBody(nWorld,cCar);
   NewtonReleaseCollision(nWorld,cCar);

   NewtonBodySetForceAndTorqueCallback(bCar,spForceCallback);
   
   NewtonBodySetMassMatrix(bCar,1000,1,1,1);

   float tireoffset[16] = {0,1,0,0, 0,0,1,0, 1,0,0,0, 0,0,0,1};
   float vector[3];
   jCar = DGRaycastVehicleCreate(4,tireoffset,bCar);
   
   vector[0]=9;vector[1]=-1;vector[2]=-13.5;
   DGRaycastVehicleAddTire(jCar,NULL,vector,   0.5, 14, 5, 0.1, 0.25, 70, 5, 1);

   vector[0]=9;vector[1]=-1;vector[2]=15;
   DGRaycastVehicleAddTire(jCar,NULL,vector,   0.5, 14, 5, 0.1, 0.25, 70, 5, 1);

   vector[0]=-9;vector[1]=-1;vector[2]=-13.5;
   DGRaycastVehicleAddTire(jCar,NULL,vector,  0.5, 14, 5, 0.1, 0.25, 70, 5, 1);
   
   vector[0]=-9;vector[1]=-1;vector[2]=15;
   DGRaycastVehicleAddTire(jCar,NULL,vector,   0.5, 14, 5, 0.1, 0.25, 70, 5, 1);

   while (true)
   {
      DGRaycastVehicleSetCustomTireTorque(jCar,1,1500);
      DGRaycastVehicleSetCustomTireTorque(jCar,0,1500);

      /.../

      DGRayCarGetChassisMatrixLocal(jCar,spmCar);
      
                /.../

      for(i=0;i<=3;i++)
      {
         DGRayCarTireMatrix(jCar,i,spmCar);
         /.../
      }

                /.../

      NewtonUpdate(nWorld,spGetTimer());
   }

   return;
}


I get this error:

Code: Select all
1>------ Erstellen gestartet: Projekt: ..., Konfiguration: Debug Win32 ------
1>Kompilieren...
1>Main.cpp
1>...\main.cpp(213) : error C2664: 'NewtonBodySetForceAndTorqueCallback': Konvertierung des Parameters 2 von 'void (__cdecl *)(const NewtonBody *)' in 'NewtonApplyForceAndTorque' nicht möglich
1>        Keine Funktion mit diesem Namen im Gültigkeitsbereich stimmt mit dem Zieltyp überein
1>Das Buildprotokoll wurde unter "file://...\Debug\BuildLog.htm" gespeichert.
1>Driver - 1 Fehler, 0 Warnung(en)
========== Erstellen: 0 erfolgreich, Fehler bei 1, 0 aktuell, 0 übersprungen ==========


This sounds logic, but the examples uses a 'void'-function, too. The compiler wanted a 'NewtonApplyForceAndTorque'-function...

Need help, if there is a tutorial, please post. I haven't found a solution in the demos.

Thanks!
spark-plug
 
Posts: 13
Joined: Wed Jul 08, 2009 10:28 am

Re: TorqueAndForceCallback

Postby Julio Jerez » Wed Jul 22, 2009 10:44 am

http://newtondynamics.com/wiki/index.ph ... =Tutorials
thsi tutoriasl migh tell you how to make your force and torque callback
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: TorqueAndForceCallback

Postby brotwurst » Wed Jul 22, 2009 5:58 pm

spark-plug wrote:
Code: Select all

   NewtonBodySetForceAndTorqueCallback(bCar,spForceCallback);
   



Code: Select all
   NewtonBodySetForceAndTorqueCallback(bCar,(NewtonApplyForceAndTorque)spForceCallback);


casts ftw :)
brotwurst
 
Posts: 3
Joined: Mon Jul 20, 2009 2:17 am

Re: TorqueAndForceCallback

Postby Julio Jerez » Wed Jul 22, 2009 6:38 pm

you can't do that
you need to write the function callback with the correct function prototype

void spForceCallback(const NewtonBody* body, float time, int thead);
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: TorqueAndForceCallback

Postby spark-plug » Thu Jul 23, 2009 7:36 am

Thank you brotwurst, works perfect :D

Offtopic; is their a command in newton which can translate a model into a newtonbody? Or should I built it with a GETFACEmatrix-command and the newton tree-commands?
spark-plug
 
Posts: 13
Joined: Wed Jul 08, 2009 10:28 am

Re: TorqueAndForceCallback

Postby agi_shi » Thu Jul 23, 2009 8:55 am

spark-plug wrote:Thank you brotwurst, works perfect :D

Like Julio said, that's the wrong way of doing it:
Julio Jerez wrote:you can't do that
you need to write the function callback with the correct function prototype

void spForceCallback(const NewtonBody* body, float time, int thead);


Offtopic; is their a command in newton which can translate a model into a newtonbody? Or should I built it with a GETFACEmatrix-command and the newton tree-commands?

First of all, tree collisions are not dynamic bodies (their mass is always 0).

Second, no there is no such function - you need to load your model however you want, and then feed it's faces to the tree collision, or you can build a convex hull out of it (for dynamic bodies). If you need a concave dynamic body, you can build the object out of multiple collision parts "glued" together into a compound collision (for example, a table would be formed out of 5 boxes/convex hulls).
agi_shi
 
Posts: 263
Joined: Fri Aug 17, 2007 6:54 pm

Re: TorqueAndForceCallback

Postby spark-plug » Thu Jul 23, 2009 12:38 pm

OK.

But if I want to create the Level (=static, of course low-polygon) in Newton I shell use the Tree-Collision, not?
spark-plug
 
Posts: 13
Joined: Wed Jul 08, 2009 10:28 am

Re: TorqueAndForceCallback

Postby JernejL » Thu Jul 23, 2009 3:05 pm

Yep, trimesh is totally appropriate for statis map environment.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: TorqueAndForceCallback

Postby brotwurst » Thu Jul 23, 2009 6:57 pm

Julio Jerez wrote:you can't do that
you need to write the function callback with the correct function prototype

void spForceCallback(const NewtonBody* body, float time, int thead);

i know its the "wrong" way of doing it, BUT it works :)

also, in the wiki it says:
Code: Select all
void _cdecl callbackSimpleGravity(const NewtonBody* body)
{
   float force[3];
   float mass;
   float inertia[3];

   NewtonBodyGetMassMatrix( body, &mass, &inertia[0] );

   float force[0] = 0.0f;
   float force[1] = -9.8f * mass;
   float force[2] = 0.0f;

   NewtonBodyAddForce( body, &force[0] );
}



so i thought the callback changed in 2.0 or something like that (never used any older verison)... so i suggested something that would probably work for 2.0 and older versions (i dont know what hes using :lol: )

PS: my compiler even throws an error if i use a correct prototype without casting...
brotwurst
 
Posts: 3
Joined: Mon Jul 20, 2009 2:17 am

Re: TorqueAndForceCallback

Postby Julio Jerez » Thu Jul 23, 2009 8:16 pm

you need to dowload 2.04
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: TorqueAndForceCallback

Postby JernejL » Fri Jul 24, 2009 3:29 am

brotwurst: callbackSimpleGravity is a example for newton 1.53 and will work in that form with 1.53, but i suggest you try to move to newton2 soon.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: TorqueAndForceCallback

Postby brotwurst » Fri Jul 24, 2009 4:41 am

Delfi wrote:brotwurst: callbackSimpleGravity is a example for newton 1.53 and will work in that form with 1.53, but i suggest you try to move to newton2 soon.

what are you talking about?! I am using 2.0. and i never used an older version. is my english really THAT bad?

brotwurst wrote:so i thought the callback changed in 2.0 or something like that (never used any older verison)


i know its an example for 1.53... i only said, that i think, because its a different prototype than the 2.0 one, it changed in 2.0...

and i only suggested casting the function pointer, because i know it works in the following situations:
1. your compiler, for whatever reason, throws an error "...cannot convert <something> to 'NewtonApplyForceAndTorque'...", even though your callback prototype is correct. (sometimes happens... dont know why)

2.you are using 2.0 but your callback prototype is like the one from the example (1.53). in this case, you CAN still cast the function pointer, and it will COMPILE and RUN. i know its the f**king worst way of getting it working but it is the only thing i could suggest trying without knowing the version spark-plug's using...

clearer now? if not, well, my english * too much to express myself any better
brotwurst
 
Posts: 3
Joined: Mon Jul 20, 2009 2:17 am

Re: TorqueAndForceCallback

Postby JernejL » Fri Jul 24, 2009 5:45 am

All is ok then, as long as the function declaration and calling conventions (cdecl) match, a lot of callbacks did change with 2.0.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: TorqueAndForceCallback

Postby spark-plug » Fri Jul 24, 2009 8:47 am

Is there a lib or header to get the Matrix of each face or vertex of a 3d model? I need a function to build my newton-world-body...
spark-plug
 
Posts: 13
Joined: Wed Jul 08, 2009 10:28 am

Re: TorqueAndForceCallback

Postby JernejL » Fri Jul 24, 2009 9:12 am

A single 3-d model usually has a single matrix, which specifies the location of model in physical space, and vertex coordinates & geometry specify the shape of the object.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Next

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 0 guests