Controlling vehicle

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Controlling vehicle

Postby Matic » Mon Apr 25, 2011 3:45 am

Hello,

how can I control vehicle in Newton 2.33. I have noticed that functions like NewtonVehicleSetTireSteerAngle are not present in new versions of NGE. How can I steer the car and accelerate?

Thanks!
Matic
 
Posts: 15
Joined: Fri Apr 08, 2011 8:23 am
Location: Ljubljana, Slovenia

Re: Controlling vehicle

Postby PJani » Mon Apr 25, 2011 5:09 am

Look at CustomMultiBodyJoint.
| i7-5930k@4.2Ghz, EVGA 980Ti FTW, 32GB RAM@3000 |
| Dell XPS 13 9370, i7-8550U, 16GB RAM |
| Ogre 1.7.4 | VC++ 9 | custom OgreNewt, Newton 300 |
| C/C++, C# |
User avatar
PJani
 
Posts: 448
Joined: Mon Feb 02, 2009 7:18 pm
Location: Slovenia

Re: Controlling vehicle

Postby Matic » Mon Apr 25, 2011 5:34 am

Little more help please? Cant find anything in Wiki.
Matic
 
Posts: 15
Joined: Fri Apr 08, 2011 8:23 am
Location: Ljubljana, Slovenia

Re: Controlling vehicle

Postby Matic » Mon Apr 25, 2011 6:44 am

I have created Vehicle from tutorial on this site: http://newtondynamics.com/wiki/index.ph ... controller (it is missing but I have used source code from this tutorial).
Code: Select all
void TireTransformCallback (iNewtonUserJoint *car);
struct iNewtonUserJoint* CreateRayCastCast (iNewtonBody* body, SceneManager* sceneManager, float tirePosit[4][3]);
void AddTire (iNewtonUserJoint* joint, const char* fileName, struct dVector position, SceneManager* sceneManager);


This functions work and I have a moving vehicle. If I understand correctly I have to add tourque to wheels and turn them in direction I want the car to drive? How can I do that? Thanks!
Matic
 
Posts: 15
Joined: Fri Apr 08, 2011 8:23 am
Location: Ljubljana, Slovenia

Re: Controlling vehicle

Postby Matic » Mon Apr 25, 2011 2:43 pm

Anyone?
Matic
 
Posts: 15
Joined: Fri Apr 08, 2011 8:23 am
Location: Ljubljana, Slovenia

Re: Controlling vehicle

Postby Matic » Wed Apr 27, 2011 1:36 pm

How can I add torque to tire entites (look code below)? Can I iterate over NewtonBodies and select tireBody somehow?
Code: Select all
void TireTransformCallback (iNewtonUserJoint *car)
{
   int count;
   
    iNewton* world;
   
   world = GetWorld();
   
   // the tire geometry is not aligned with the collision shape,
   // we can use a local rotation matrix to algn the tires correctly.
   struct dMatrix tireYawMatrix =dYawMatrix(3.1416f * 0.5f);
   
   // iterate over all tire and calculate the location of the Visual Matrix
   count = [world DGRaycastVehicleGetTiresCount:car];
   
   for (int i = 0; i < count; i ++) {
      Entity* tireEnt;
      struct dMatrix tireMatrix;
       
      // get THe tie entity.
      tireEnt = (Entity*) [world DGRaycastVehicleGetTiresUserData:car :i];
       
      // Get the tire matrix form the joint and calculate the final visual matrix
        [world DGRaycastVehicleGetTireMatrix:car :i :&tireMatrix.m_front.m_x];
      tireMatrix = MultiplyMatrix(&tireYawMatrix , &tireMatrix);
       
      // we need to convert the matrix into a quaternion rotation because our entity used quaternion to express rotations
      struct dQuaternion rotation = QuaternionFromMatrix(tireMatrix);//Vprasljiva pretvorba!!!!!!
        struct dQuaternion m_curRotation = tireEnt.m_curRotation;
      // make sure the rotation spinning tire around the shortest path.
      if (dQuatDotProduct(&rotation, &m_curRotation) < 0.0f) {
         dQuatScale(&rotation, -1.0f);

      }
       
      // move current rotation and position to previews rotation and position, and save the New rotation and position
      tireEnt.m_prevRotation = tireEnt.m_curRotation;
      tireEnt.m_curRotation = rotation;
      tireEnt.m_prevPosition = tireEnt.m_curPosition;
      tireEnt.m_curPosition = tireMatrix.m_posit;
   }
}
Matic
 
Posts: 15
Joined: Fri Apr 08, 2011 8:23 am
Location: Ljubljana, Slovenia


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron