Using joints for "special" stuff

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Using joints for "special" stuff

Postby PJani » Wed Mar 10, 2010 6:56 pm

I am working currently on "realistic" petrol engine, but i came up with few other ideas and before i continue with development of petrol engine i need to redesign some stuff which extends custom joints.
I want to know if its good idea to use Custom Joint interface or doing update in outside callback.
SpringJoint(creating spring between two bodies),
ThrusterJoint(for "pushing" one attached body with some force),
AirLiftJoint(body acting as wing, with some coefs, direction vectors and aabb of body)

Thankyou.
| 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: Using joints for "special" stuff

Postby JernejL » Thu Mar 11, 2010 4:56 am

Whatever you use, the updates / calls always need to be within the forcetorque or customjoint callback intended for it.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: Using joints for "special" stuff

Postby PJani » Fri Mar 12, 2010 7:46 pm

Would this be the right code for thrusters, because i am getting some weird effects. Rocket which is tilt for 45 degrees will not change direction to the ground.

the m_locDir is local direction of thruster
the m_locPos is local position of thruster
the m_thrustForce is thrust force. :)

Code: Select all
   dMatrix mtrx;
   NewtonBodyGetMatrix(GetBody0(),&mtrx[0][0]);

   dVector com;
   NewtonBodyGetCentreOfMass(GetBody0(),&com[0]);

   dVector thrustMuzzleForce (mtrx.RotateVector(m_locDir).Scale (m_thrustForce));
   dVector thrustMuzzleTorque (mtrx.RotateVector(m_locPos - com) * thrustMuzzleForce);
   NewtonBodyAddForce (GetBody0(), &thrustMuzzleForce[0]);
   NewtonBodyAddTorque (GetBody0(), &thrustMuzzleTorque[0]);


And NewtonBodyAddForce is applied at center of mass or at center of object(local 0,0,0)?
| 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: Using joints for "special" stuff

Postby Dave Gravel » Fri Mar 12, 2010 9:50 pm

Maybe NewtonBodyAddImpulse is good for this, No ?
Do you have try ?
You search a nice physics solution, if you can read this message you're at the good place :wink:
OrionX3D Projects & Demos:
https://orionx3d.sytes.net
https://www.facebook.com/dave.gravel1
https://www.youtube.com/user/EvadLevarg/videos
User avatar
Dave Gravel
 
Posts: 801
Joined: Sat Apr 01, 2006 9:31 pm
Location: Quebec in Canada.

Re: Using joints for "special" stuff

Postby PJani » Fri Mar 12, 2010 10:02 pm

The NewtonBodyAddImpulse is too "explosive". I want to solve this by forces. Forces are soft vs impulse.
| 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: Using joints for "special" stuff

Postby PJani » Sat Mar 13, 2010 11:47 am

One thing the NewtonBodyAddForce is applied at center of object or at center of mass? :roll:
| 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: Using joints for "special" stuff

Postby JernejL » Sat Mar 13, 2010 12:32 pm

PJani wrote:One thing the NewtonBodyAddForce is applied at center of object or at center of mass? :roll:


Code: Select all
// adds force to body at a specified point in global space
procedure AddPointGlobalForce(const body: PNewtonBody; PrevBodyMatrix: pointer; Force, Point: Vector);
var
  GlobalForce: vector;
  bodymatrix:  Tmatrix4F;
  Torque:      vector;
begin

  if PrevBodyMatrix = nil then
    NewtonBodyGetMatrix(body, @bodymatrix)
  else
    move(PrevBodyMatrix^, bodymatrix, sizeof(Tmatrix4F));

  GlobalForce.x := Point.x - bodymatrix[3][0];
  GlobalForce.y := Point.y - bodymatrix[3][1];
  GlobalForce.z := Point.z - bodymatrix[3][2];

  Torque := CrossProduct(GlobalForce, Force);

  NewtonBodyAddForce(body, @Force.x);
  NewtonBodyAddTorque(body, @Torque.x);
end;

// adds force to body at a specified point in local space
procedure AddPointLocalForce(const body: PNewtonBody; Force, Point: Vector);
var
  GlobalForce, GlobalPoint: Vector;
  bodymatrix: Tmatrix4F;
begin
  NewtonBodyGetMatrix(body, @bodymatrix);

  GlobalForce := MatrixRotateVector(Force, bodymatrix);
  GlobalPoint := MatrixTransformVector(Point, bodymatrix);

  AddPointGlobalForce(body, @bodymatrix, GlobalForce, GlobalPoint);
end;


does that make sense? scroll down, there's 2 functions there :)

I wish those two functions would eventually become part of newton itself some day.. along with GetPointGlobalVelocity and GetPointLocalVelocity.. Julio: would that be possible? i'm sure it would help a lot of people, as adding forces off-body centre is a very intiutive way to perform physics tasks and not everyone will immediately understand how to do it properly (the asociation with addtorque)..
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: Using joints for "special" stuff

Postby PJani » Sat Mar 13, 2010 1:15 pm

I will rewrite this two functions for c++. :D

Yep these two function could be great and useful feature in newton, even function call overhead could be reduced this way. So the calculations for global torque and global force can be optimized.
| 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: Using joints for "special" stuff

Postby PJani » Mon Mar 15, 2010 12:19 pm

Is mtrx.TransformVector(point); right in AddLocalForce? Is this code right?
Code: Select all
      static void NewtonBodyAddGlobalForce(const NewtonBody* bdy, const dVector& force, const dVector& point)
      {
         dMatrix mtrx;
         NewtonBodyGetMatrix(bdy,&mtrx[0][0]);

         dVector glbForce =  point - mtrx.m_posit;
         dVector glbTorque = glbForce * force;

         NewtonBodyAddForce(bdy, &force[0]);
         NewtonBodyAddTorque(bdy, &glbTorque[0]);
      }
      static void NewtonBodyAddLocalForce(const NewtonBody* bdy, const dVector& force, const dVector& point)
      {
         dMatrix mtrx;
         NewtonBodyGetMatrix(bdy,&mtrx[0][0]);

         dVector glbForce = mtrx.RotateVector(force);
         dVector glbPoint = mtrx.TransformVector(point);

         //NewtonBodyAddGlobalForce(bdy, glbForce, glbPoint);

         dVector newForce =  glbPoint - mtrx.m_posit;
         dVector newTorque = newForce * glbForce;

         NewtonBodyAddForce(bdy, &glbForce[0]);
         NewtonBodyAddTorque(bdy, &newTorque[0]);
      
      }
| 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: Using joints for "special" stuff

Postby JernejL » Mon Mar 15, 2010 4:48 pm

I have no idea how you implemented it, but here's my funcs to do that:

Code: Select all

function MatrixRotateVector(vec: Vector; m: Tmatrix4f): Vector; // tested, works.
begin
  result.x:= vec.x * m[0, 0] + vec.y * m[1, 0] + vec.z * m[2, 0];
  result.y:= vec.x * m[0, 1] + vec.y * m[1, 1] + vec.z * m[2, 1];
  result.z:= vec.x * m[0, 2] + vec.y * m[1, 2] + vec.z * m[2, 2];
end;

function MatrixTransformVector(vec: Vector; m: Tmatrix4f): Vector;
begin

   Result.x := vec.x * m[0][0] + vec.y * m[1][0] + vec.z * m[2][0] + m[3][0];
   Result.y := vec.x * m[0][1] + vec.y * m[1][1] + vec.z * m[2][1] + m[3][1];
   Result.z := vec.x * m[0][2] + vec.y * m[1][2] + vec.z * m[2][2] + m[3][2];
end;

Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: Using joints for "special" stuff

Postby PJani » Mon Mar 15, 2010 6:41 pm

I am using Julios dMath lib, because i am adding new joints in jointlibrary.
| 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: Using joints for "special" stuff

Postby PJani » Tue Mar 16, 2010 5:05 am

buahahaha, its Alive, its Alive! Joke, its all most nothing :)

| 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: Using joints for "special" stuff

Postby Julio Jerez » Tue Mar 16, 2010 1:09 pm

Hey that was cool.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
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