Struct alignment and other question

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Struct alignment and other question

Postby Rune Hunter » Mon Dec 08, 2008 7:52 pm

Well, I began wrapping Newton 2.0 in C# code and as I was doing the structs I realized that I should double check to see what kind of alignment rules Newton uses. I'm assumming it is the default align to 16bit boundries that VC++ does. Am I right?

Also why is the ray origin and collision destination in the following struct a 4D vector? I noticed other structs also use 4D vectors.

Code: Select all
   typedef struct NewtonUserMeshCollisionRayHitDescTag
   {
      dFloat m_p0[4];                     // ray origin in collision local space
      dFloat m_p1[4];                         // ray destination in collision local space   
      dFloat m_normalOut[4];               // copy here the normal at the ray intersection
      int m_userIdOut;                        // copy here a user defined id for further feedback 
      void* m_userData;                       // user data passed to the collision geometry at creation time
   } NewtonUserMeshCollisionRayHitDesc;
Newton Help Documentation for 1.53: http://www.runehunter.phpnet.us/NewtonHelp.html
Rune Hunter
 
Posts: 8
Joined: Fri Jul 22, 2005 12:07 am
Location: USA

Re: Struct alignment and other question

Postby Julio Jerez » Tue Dec 09, 2008 10:50 am

you do no neet to worried abuot the alignent. intennally teh engine tak ecare of that,
the vectors are 4 valuer qunatity because, they are dVector, an d d vector call can be use with simd instrutions.

I am changing the format

Code: Select all
typedef struct nametag
{
 ...
} name;


to teh natove c++

Code: Select all
struct name
{
...
}


in tehory teh first format shoudl be many compatible to many compilers, buy I foudn that
it is the c compiler who have more problems with c syntax, so unless a c compler is really old today all of then handle the secund syntact beter
Julio Jerez
Moderator
Moderator
 
Posts: 11154
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Struct alignment and other question

Postby Rune Hunter » Wed Dec 10, 2008 11:47 pm

All right so data alignment won't be an issue.

So, just to clarify my understanding simd instructions only allow you to load single, double, or 4 value quantities which is why you use a 4D vector instead of a 3D vector. That makes perfect sense to me. However, what I am now confused about is the functions in Newton. When a function gives you a vector out of a parameter does it actually give a 4D vector but we only use the first three values of the quantity? If so, than when we pass a function a vector do we need to pass it a 4D vector or can we just pass it three floats?
Newton Help Documentation for 1.53: http://www.runehunter.phpnet.us/NewtonHelp.html
Rune Hunter
 
Posts: 8
Joined: Fri Jul 22, 2005 12:07 am
Location: USA

Re: Struct alignment and other question

Postby Julio Jerez » Wed Dec 10, 2008 11:57 pm

you can pass safet;y teh tre float fo ra vector because teh engien local vareible for call back

velaise are teh copied to and aprorprate aligned vector.

for example set velocoty funtion is writeen like this

Code: Select all
SetVelocity (body*  b, float *veloc)
{
   dVector  v (veloc[0], veloc[1], veloc[2], 1.0);
   b->SetVelocity (v);
}
Julio Jerez
Moderator
Moderator
 
Posts: 11154
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 3 guests