Building a airlift car

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Building a airlift car

Postby Auradrummer » Sun Aug 23, 2009 10:54 am

Hello guys,

I'm building an airlift car, like those ones used in Tattooine in Star Wars. I deduced that the lifting system should like a regular car suspension (with no course limits). I know how to do this but I think I didn't used the engine on the right way. Now, I want to use the full power of Newton Dynamics 2.0.
Let's see if I can tell you what exactly I'm asking...

My plan is:
- Build a function to cast down a ray from car with the distance I want it lift.
- Store the value got.
- Cast ray again.
- Store the value again.
- Compare the difference between the distances.
- Calculate the lifting force:
force = liftpower [the power of lifting] * height [second ray] - speed [(height first ray - height second ray) * time between the ray casts]
- Apply this to the body of the car.

I think this should work, but what intrigates me is that all the cars done in Newton uses the Submit Constraint function to apply the forces. All my tries were unstable and I never used Submit Constraint.

So, I want to ask the Darth Masters here if what I'm planning above needs to use Submit Constraint and how to use it.

Thanks a lot!
Developing a racing game.
Auradrummer
 
Posts: 132
Joined: Sat May 17, 2008 9:17 am

Re: Building a airlift car

Postby Julio Jerez » Mon Aug 24, 2009 1:16 pm

I would take a simpler aproach,
Get 2.08 and implement the ray cast car witout wheels, zero lateral friction, and very low damper coeficient.
then instead of applying a torque to the tires, just apply a truster force to eth vehicel body.

See teh wiki totorial for a code tah add a very basi skelton for a Ray cast car, (no text yet but it can help you to get started)
Post again when you get there.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Building a airlift car

Postby Auradrummer » Sat Aug 29, 2009 9:50 am

Hello Julio,

I'm sudying here, and the things are more clear than was before. But the SubmitConstrainst still bothers me. As I've noticed, all the physics calculations are applyed there. I think that this function avoids applying forces in different times, what can cause the system becomes unstable (I'm sure that was my problem). But, where this function is called? I didn't found any reference to it. If I create a function called "SubmitConstrainst" the engine will call it automatically? This is my problem. I'll keep reading.
Developing a racing game.
Auradrummer
 
Posts: 132
Joined: Sat May 17, 2008 9:17 am

Re: Building a airlift car

Postby JernejL » Sat Aug 29, 2009 11:14 am

You send newton a callback to SubmitConstrainst during joint creation, it's a callback, newton will call the function back.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: Building a airlift car

Postby Auradrummer » Mon Aug 31, 2009 9:29 am

Hi Delfi,

I seached in DGRayCastCar.cpp and RayCastCar.cpp and are no occurances of SubmitConstrainst. Only at the function declaration.

I is not to bother you too much, can you tell me where this function is called? Or when ...
Developing a racing game.
Auradrummer
 
Posts: 132
Joined: Sat May 17, 2008 9:17 am

Re: Building a airlift car

Postby Auradrummer » Wed Sep 02, 2009 4:58 pm

Hey guys,

My airlift car is going very well, I'm very happy with it.

I'm with some doubts about ray cast.

To make the car level follow the ground, I want to cast two rays from it, one from left and another from right.

Comparing the size of them I can inclinate the car following the ground, right?

But, I'm not succeeding casting two rays from the vehicle.
I'm using the system that David Gravel used in his RayCast car.
I'm storing the information returned by RayCasts in two structures, infoR and infoL, but only one of them is giving me the height of the car, another is returning 1.
As I read in WIKI, if the ray cast is returning 1 is that it aren't finding anything, or are not fired.

I wondering here if my problem is not the same as one man here that made a robot with four sensors ...

THanks in advance!
Developing a racing game.
Auradrummer
 
Posts: 132
Joined: Sat May 17, 2008 9:17 am

Re: Building a airlift car

Postby Auradrummer » Thu Sep 10, 2009 4:35 pm

Hello guys,

I'm very happy with my airlift car. I think I should try to do it a long time ago, instead be fighting with a common car (that have a far more complex physics).
Now, I'm understanding very better the raycast functions and matrixes and vectors calculations. The game is growing fast.

This time, I didn't came to ask you, but to show a sollution I found to cast any amount of rays at same time (this can be very useful for those, like me, that have too many experience with raycast).

This is the callback.
Code: Select all
dFloat callBackFilter (const NewtonBody * body, const dFloat * normal, int collisionID, void* userData, dFloat interset)
{
       dFloat bodyMass;
       dFloat bodyInertia[3];
       dFloat height;
       NewtonBodyGetMassMatrix (body, &bodyMass, &bodyInertia[0], &bodyInertia[1], &bodyInertia[2]);
       rayDir = (int)userData;
       if (bodyMass == 0) // to ensure that the hitbody is a CollisionTree (my track)
       {
          if (rayDir == 0)
              ship.lHeight = interset; // height of the 1st ray hit
          if (rayDir == 1)
             ship.rHeight = interset;  // height of the 1st ray hit
          if (rayDir == 2)
             ship.fHeight = interset;  // height of the 1st ray hit
       }
       else
           return 1.0f;
 };



This is the code in main
Code: Select all
       
rayDir = 0;
do
{
      if (rayDir == 0) // 1st ray, from right
      {                   
              rayOrigin = bodyMatrix.TransformVector(dVector(1.0f, 0.5f, -0.5f));
              rayDest = bodyMatrix.TransformVector (dVector (1.0f, -ship.liftMaxHeight, -0.5f));
      }
          else if (rayDir == 1) // 2nd ray, from left
      {
              rayOrigin = bodyMatrix.TransformVector(dVector(-1.0f, 0.5f, -0.5f));
              rayDest = bodyMatrix.TransformVector (dVector (-1.0f, -ship.liftMaxHeight, -0.5f));
      }
          else // 3rd ray, from front
      {
               rayOrigin = bodyMatrix.TransformVector(dVector(0.0f, 0.5f, 1.0f));
               rayDest = bodyMatrix.TransformVector (dVector (0.0f, -ship.liftMaxHeight, 1.0f));
      }
      userData = (int* )rayDir;
      NewtonWorldRayCast (nWorld, &rayOrigin[0], &rayDest[0], callBackFilter, userData, NULL);
      rayDir ++ ;
} while (rayDir < 3);


With this simple code, I cast three rays, and further in the code I make my airlift car autolevel. I think this work for a common car too.
Developing a racing game.
Auradrummer
 
Posts: 132
Joined: Sat May 17, 2008 9:17 am

Re: Building a airlift car

Postby Julio Jerez » Thu Sep 10, 2009 4:51 pm

Ok, cool, glad you start to understand the arithmetic :mrgreen:

It makes me feel sad that over and over again I fail to make demos that peopel undertand.
I try the make the Tutorials and simple as I could, yet people are still confused.
What I do not undertand is how it is that I see such enthusiasm for Open source code, when code I'd seen seem to be like a million time more complex than Physics demos in Newtpn SDK.
Just take a look at somethink like Collada.
In my openion is the worse more complex file format library I have even came across, yet it seems everyone but me find very eassy.
The older I get the less I udernstand people. :roll:

Anyway I am glad you are getting results using your own way, which is what I would prefer anyway.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Building a airlift car

Postby Auradrummer » Fri Sep 11, 2009 5:08 pm

Hi Master,

The main difficult I found in Newton is the physics and matrixes calculations (that have nothing with the engine itself). The engine, after we get some notions, is really awesome.

About your examples, I guess they are too fragmented. As the raycast car we have some functions that are in another code that uses functions that are in another code and so on. For newbies, like me, I complicated to follow the call's till the end.

Another suggestion is to separate some lines like this (this is mine, but the example is good)
instead doing this:
Code: Select all
// here we calculate the ship thrust according height
thrust = bodyMatrix.RotateVector(thrust.Scale(ship.thruster/2 * (ship.liftMaxHeight - ship.absHeight)));


do this:
Code: Select all
// here we calculate the thrust according height
dFloat thrustPower;
thrustPower = ship.thruster/2 * (ship.liftMaxHeight - ship.absHeight); //half of thrust power X how lower the ship are from maximum allowed height
thrust = thrust.Scale(thrustPower);
thrust = bodyMatrix.RotateVector(thrust); // allign the thrust with the ship orientation


If you want, I can send you my airlift car as an example. I think is a half way between raycast car and the simpler examples.
Developing a racing game.
Auradrummer
 
Posts: 132
Joined: Sat May 17, 2008 9:17 am


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron