Hovering using only AddForce and SetForce

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Re: Hovering using only AddForce and SetForce

Postby Overhertz » Wed Nov 07, 2012 7:54 pm

OK that seems to have slighly fixed the problem, but now the bodies still fall through the terrain occasionally, sometimes when they are sitting still even.

I have uploaded sample app -> download here

press "c" to blast out a few cubes, then press "`" to open console and write "debug on", you will be able to see the debug lines are placed around the cubes fine, but if you watch they dont sit very well on the terrain and sometimes fall through. Any ideas?
Ziron Programming Language
Download the Assembler HERE
User avatar
Overhertz
 
Posts: 112
Joined: Mon Jul 06, 2009 11:19 am

Re: Hovering using only AddForce and SetForce

Postby Julio Jerez » Wed Nov 07, 2012 8:09 pm

has you implemented debug display, to see if the collision are in place?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Hovering using only AddForce and SetForce

Postby Overhertz » Wed Nov 07, 2012 8:10 pm

Julio Jerez wrote:has you imp[lemnet debug display, to see if the collision ares in place?


yup ->>> press "`" to open console and write "debug on"
Ziron Programming Language
Download the Assembler HERE
User avatar
Overhertz
 
Posts: 112
Joined: Mon Jul 06, 2009 11:19 am

Re: Hovering using only AddForce and SetForce

Postby Julio Jerez » Wed Nov 07, 2012 8:42 pm

can you modyfy the test so that it thoru only one mesh at a time

also you can serialize the scene by doing this, after you thorh one box the box:
NewtonSerializeToFile (newtonWorld, "fileName.bin");

then you can load the file in the Sandbodemo and see what it is.
or you can send me the file, and I can check it out.

Serialize in a eassier way for debugging in core 300
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Hovering using only AddForce and SetForce

Postby Overhertz » Thu Nov 08, 2012 6:10 am

Hi sorry for late reply,

Anyway, I have updated the rar/build, I have added the key "N" to shoot out boxes at a much slower rate, so you can put them into whatever order or test how you need, then you can open the console and write

"eval surge.newtonserialize = 'test.bin';"

without quotes of course, this will output your file to same dir as executable.

After that if you need to re-serialize often you can just open console and press the up arrow key and it will auto rewrite it for you, you could of course copy and paste that line aswell :)
Ziron Programming Language
Download the Assembler HERE
User avatar
Overhertz
 
Posts: 112
Joined: Mon Jul 06, 2009 11:19 am

Re: Hovering using only AddForce and SetForce

Postby Julio Jerez » Thu Nov 08, 2012 11:16 am

Ok I found the bug and it is fixed now.
Please sync to svn and try again.

after you do that here are couple of things.

I see that when you create the Boxes you are passing and point cloud that is already in global space.
Numerically there is nothing wrong with that, but in practice the lead that big round off error when the center of the object is very far away from the origin.

In you demo you mesh is (1400 x 1400) with origin at lower corner
the camera spawn boxes of (0.5 x 0.5 x 0.5) at around location (150 x 10 x 150)

this means that the convex hull is made of a point cloud that is far away from the origin
which this mean is that those points will have a base of (150 x 10 x 150) instead fo (0, 0, 0)

In newton core 200, I was translating the point cloud to the origin and setting the offset matrix to the convex hull origin, and this worked transparent to the user, because in core 200 the offset matrix of a collision shape was constant.

In newton 300 that transform, is a collision shape Variable than the end application can change.
In fact two convex identical shapes can have different offset transform and still share the same geometry

The bug I have was that we I was collection the faces I was multiplying the body matrix by the collision shape matrix to for to clip the face around the shape,
Instead I had to use the Origin of the AABB in the broad face and the fixes the Bug in newton, however it does no fixe that fact that the point cloud have a large offset baked in it,
and that translate to Object spawned far away from the origin behaving worse than objects spawned close to the origin.

to fix that you can pass the pound cloud in local space. and then set the collision offset matrix to the origin of the point cloud, that way everything will work at it best efficiency.

The second issue is that you are no deleting the collision shape after you assign it to the body, and that leave a memory leak. Try compiling the debug dll so that you can see those warnings.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Hovering using only AddForce and SetForce

Postby Overhertz » Thu Nov 08, 2012 1:19 pm

Excellent, the update works, I have also fixed the memory leak (hopefully, until I get round to re-installing visual studio and compiling debug dll)

Else i'm not sure i understand you correctly regarding the point cloud and offset, could you elaborate?

I will begin to play around with the Kinematic bodies shortly :)

Thanks again Julio.
Ziron Programming Language
Download the Assembler HERE
User avatar
Overhertz
 
Posts: 112
Joined: Mon Jul 06, 2009 11:19 am

Re: Hovering using only AddForce and SetForce

Postby Julio Jerez » Thu Nov 08, 2012 3:01 pm

I meant try making the convex shape by passing a point clouds in local space, not in global space.
The only reason is that this alowes for intemediate calculation use more dynamics range of 32 bit floating points

It is better to have a shape with vertices around the origin and an offset matrix,
than a shape in global space and an identity matrix as offset

what compiler do you use? that let you link VS DLLs
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Hovering using only AddForce and SetForce

Postby Overhertz » Thu Nov 08, 2012 3:16 pm

I see, I will take a look at this soon.

As for compiler, I write my test applications with Newton in a couple languages, Ziron and Delphi, both allow to import external functions.

ps. I updated the build with the new dll if you'd like to check it out :)
Ziron Programming Language
Download the Assembler HERE
User avatar
Overhertz
 
Posts: 112
Joined: Mon Jul 06, 2009 11:19 am

Re: Hovering using only AddForce and SetForce

Postby Overhertz » Thu Nov 08, 2012 8:14 pm

OK so i've began with the Kinematic Body, I have created a body that "connects" to the players body (a ship), so whenever the ship is moved the kinematic body (which i've named a rejector) will also be moved to the offset from the main body.

Now what i need is a way to check if the kinematic body is colliding/intersecting other objects, A good way would be if i can get 2 values, the direction matrix/angle of current intersections and the distance of intersection. Is there a way i can go about doing this? Or if you have a good idea/better solution? :)
Ziron Programming Language
Download the Assembler HERE
User avatar
Overhertz
 
Posts: 112
Joined: Mon Jul 06, 2009 11:19 am

Re: Hovering using only AddForce and SetForce

Postby Julio Jerez » Fri Nov 09, 2012 8:15 am

you cna use a funtion like this to get the contacts between the ground and the trigger

Code: Select all
void GetContactOnBody (NewtonBody* const body)
{
   for (NewtonJoint* joint = NewtonBodyGetFirstContactJoint (body); joint; joint = NewtonBodyGetNextContactJoint (body, joint)) {
      for (void* contact = NewtonContactJointGetFirstContact (joint); contact; contact = NewtonContactJointGetNextContact (joint, contact)) {

         NewtonBody* const body0 = NewtonJointGetBody0(joint);
         NewtonBody* const body1 = NewtonJointGetBody1(joint);
         _ASSERTE (body0 == body);

         if (body1 != crasftBody) {
            // do whatever you want with the force
            NewtonMaterial* material = NewtonContactGetMaterial (contact);
            NewtonMaterialGetContactPositionAndNormal (material, body1, &point.m_x, &normal.m_x);
         }
      }
   }
}
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Hovering using only AddForce and SetForce

Postby Overhertz » Fri Nov 09, 2012 12:49 pm

Hello Julio, OK i've been trying around with some code, but when trying to view the newton debug lines, it doesn't seem to be able to show any kind of output for kinematic bodies ?

Edit: never mind i think i found the issue

1 other thing, currently I am doing some internal routines to keep the kinematic body in place with the player body, is there a way to connect the kinematic body to the dynamic body so it will always be moving with the player body ? which could probably save a-lot of callbacks if there is. Any info is appreciated.

What would be really great is a function to just connect two bodies together, with no types of joint, just physically connected, so you could set the matrix of 2 cubes for example, and then call NewtonConnectBodies(body0, body1) which from then on would treat them as if they were glued together (of course even if they are not touching) - something like this would be fantastic and would allow quick prototyping of new ship designs etc
Ziron Programming Language
Download the Assembler HERE
User avatar
Overhertz
 
Posts: 112
Joined: Mon Jul 06, 2009 11:19 am

Re: Hovering using only AddForce and SetForce

Postby Julio Jerez » Fri Nov 09, 2012 5:57 pm

no way to link two bodies. Only joint can do that bu Kinamatioc bodies do no accept joint connetions.

you do no wnat that anyway, no need to make it more expenesive gratuitulislly./

why not simple set the traform matrix in the forces and torque call back o fteh hiover craft body?
Get the matrix, velocity and angular velocity and ste the to teh kinematic body.

anoteh way you coudl do this is by usin a compoind collision inestad of a kinamci body.
I do that for teh vehicle and player.
bascially you make a compoind collsion and add the collsion of teh ship as shapes. then you add teh extra collsion also as sushapenm bu you kabe this shaope not collidable.

now the body will carry all the shapes with it, then you call colldion collide to get the contacts genertaed form the trigger subshape.
I thonk this will be the most effiecient way.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Hovering using only AddForce and SetForce

Postby Overhertz » Sat Nov 10, 2012 10:59 am

Julio Jerez wrote:bascially you make a compoind collsion and add the collsion of teh ship as shapes. then you add teh extra collsion also as sushapenm bu you kabe this shaope not collidable.

now the body will carry all the shapes with it, then you call colldion collide to get the contacts genertaed form the trigger subshape.
I thonk this will be the most effiecient way.


This sounds exactly what I require, could the shape of the trigger subshape be changed without a big fuss?

For example if one of the subshapes is actually a cube that represents the flame/heat output (which will act as the ship repellent) lets say the cube is 5x5x5 could it be changed on the fly to 5x10x5.

EDIT forget that I have solved the issue using the kinematic bodies and is working fantastic, right now they are acting like pogo sticks on the test but that is kind of the idea, now i just need to tweak them to have a nice floating bobbing behaviour, Now i have 1 issue for my debug display that maybe you can help me with? :)

The issue is that because the debug display needs to draw for all objects takes a long time i would like to be able to draw newton debug lines for only the polygons that are close to the camera without the need to do alot of distance checks before drawing lines, is there a way to do a NewtonGetPolygonsFromAABB ?
Ziron Programming Language
Download the Assembler HERE
User avatar
Overhertz
 
Posts: 112
Joined: Mon Jul 06, 2009 11:19 am

Re: Hovering using only AddForce and SetForce

Postby Julio Jerez » Sat Nov 10, 2012 11:28 am

you can not change the dimesion of a shape or a subshape, but you cna chnage the position, orienation and scale

bascially you can hold to the subshape and apply a non unifirm scale and position that will make match what you want.


Debug disaplay do draw all objects, look at teh play controller demo, they playe are kinematic bodies with compound collitions shapes

plus debug disaply of static object you cna do exatly what you want,
for that you need to plug a debug callback to you static collsion shape. NewtonStaticCollisionSetDebugCallback

here is an example that is use in teh sanbox demos.
Code: Select all
 NewtonBody* CreateLevelMeshBody (NewtonWorld* const world, DemoEntity* const ent, bool optimization)
{
   // measure the time to build a collision tree
   unsigned64 timer0 = dGetTimeInMicrosenconds();

   // create the collision tree geometry
   NewtonCollision* const collision = NewtonCreateTreeCollision(world, 0);

   // set the application level callback
#ifdef USE_STATIC_MESHES_DEBUG_COLLISION
   NewtonStaticCollisionSetDebugCallback (collision, ShowMeshCollidingFaces);
#endif

...


the callback will be call with teh face taht are collected by teh AABB inetersection in the broadphase collsion, you cna save the face in a temorary buffer an dthen render then

her is an exampel of a collback tha do just that form teh sanbox demos
Code: Select all
void ShowMeshCollidingFaces (const NewtonBody* const staticCollisionBody, const NewtonBody* const body, int faceID, int vertexCount, const dFloat* const vertex, int vertexstrideInBytes)
{
#ifdef USE_STATIC_MESHES_DEBUG_COLLISION
   if (debugMode) {
      if ((debugDisplayCount + vertexCount * 2) < int (sizeof (debugDisplayCallback) / sizeof(debugDisplayCallback[0]))) {
         // we are coping data to and array of memory, another call back may be doing the same thing
         // here fore we need to avoid race conditions
         NewtonWorldCriticalSectionLock (NewtonBodyGetWorld (staticCollisionBody), 0);

         int stride = vertexstrideInBytes / sizeof (dFloat);
         dVector l0 (vertex[(vertexCount-1) * stride + 0], vertex[(vertexCount-1) * stride + 1], vertex[(vertexCount-1) * stride + 2], 0.0f);
         for (int j = 0; j < vertexCount; j ++) {
            dVector l1 (vertex[j * stride + 0], vertex[j * stride + 1] , vertex[j * stride + 2], 0.0f);
            debugDisplayCallback[debugDisplayCount + 0] = l0;
            debugDisplayCallback[debugDisplayCount + 1] = l1;
            debugDisplayCount  += 2;
            l0 = l1;
         }
   

         // unlock the critical section
         NewtonWorldCriticalSectionUnlock (NewtonBodyGetWorld (staticCollisionBody));
      }

   }
#endif
}



thne in you debug callback you only draw teh face for kinematic bodies, or dynamic bodies with non zero mass
here is an example, again form teh sanbox demos.
Code: Select all
static void DebugShowBodyCollision (const NewtonBody* const body, DEBUG_DRAW_MODE mode)
{
   dFloat mass;
   dFloat Ixx;
   dFloat Iyy;
   dFloat Izz;

   if (mode == m_lines) {
      glBegin(GL_LINES);
   } else {
      glBegin(GL_TRIANGLES);
   }

   NewtonBodyGetMassMatrix (body, &mass, &Ixx, &Iyy, &Izz);   
   if (mass > 0.0f) {
      int sleepState = NewtonBodyGetSleepState(body);
      if (sleepState == 1) {
         // indicate when body is sleeping
         glColor3f(0.42f, 0.73f, 0.98f);
      } else {
         // body is active
         glColor3f(1.0f, 1.0f, 1.0f);
      }

      dMatrix matrix;
      NewtonBodyGetMatrix(body, &matrix[0][0]);
      NewtonCollisionForEachPolygonDo (NewtonBodyGetCollision(body), &matrix[0][0], DebugShowGeometryCollision, (void*) mode);
   } else if (NewtonBodyGetType(body) == NEWTON_KINEMATIC_BODY) {
//   } else {
      dMatrix matrix;
      glColor3f(1.0f, 1.0f, 0.0f);
      NewtonBodyGetMatrix(body, &matrix[0][0]);
      NewtonCollisionForEachPolygonDo (NewtonBodyGetCollision(body), &matrix[0][0], DebugShowGeometryCollision, (void*) mode);
   }
   glEnd();
}
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

PreviousNext

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests