Newton + Ogre

Share with us how are you using the powerrrr of the force

Moderator: Alain

Postby Slick » Tue Nov 23, 2004 11:02 pm

Is there an actual released integrated version of ogrenewton to mess around with?
Slick
 
Posts: 330
Joined: Sat Feb 07, 2004 7:24 pm
Location: LA last and France now

Postby monster » Tue Nov 23, 2004 11:40 pm

If you need a name, I'd suggest either "Newtogre" or "Ogrewton".
:lol:

Maybe I'll resurrect my previous integration efforts. I've not had a chance to check out the latest SDK yet, but the "in progress" demos that were released were stupendous.
User avatar
monster
 
Posts: 9
Joined: Tue Apr 13, 2004 9:58 pm
Location: Melbourne, Australia

Postby walaber » Tue Nov 23, 2004 11:50 pm

I'm hoping to make a cool vehicle based demo/game to learn Ogre while integrating Newton at the same time.

unfortunately I'm still very much a beginner at OOP, so even after creating that game, I doubt I'll have something worth releasing...

I'm sure I'll be asking monster and other Ogre users lots of questions in the coming months :)

I kind of like "OgreNewt" :shock:
Independent game developer of (mostly) physics-based games. Creator of "JellyCar" and lead designer of "Where's My Water?"
User avatar
walaber
Moderator
Moderator
 
Posts: 393
Joined: Wed Mar 17, 2004 3:40 am
Location: California, USA

Postby Robert Lettan » Wed Nov 24, 2004 3:40 am

walaber wrote:I kind of like "OgreNewt" :shock:


Heh, that congures up a cool logo in my mind. :)
Ogre3D is pretty straight forward, used quite a bit within the nvidia community as it's a very quick way to get programs done for the nvBrowser.
User avatar
Robert Lettan
 
Posts: 8
Joined: Sat Nov 20, 2004 1:51 am
Location: England

Postby Van » Wed Nov 24, 2004 11:46 am

walaber,

Is the scale for newton to ogre 1:1?

In irrlicht, the scale was something like 1:32.

I am having a problem with collision. Although I show my object ouside the Ogre bounding boxes, newton still thinks I am in collision.

BTW, did you write a routine to draw the newton collision meshes in ogre? If so, would you please post it here for me?
Van
 
Posts: 17
Joined: Mon Nov 08, 2004 12:36 am

Postby Van » Wed Nov 24, 2004 3:42 pm

I think I figured out that the scale between netwon and ogre is 1:1.

However, my current problem is I can not figure how to apply force to an OgreNode. This Quaternion things really has me stumped.

This *sorta* works. Force is applied (in the Z) and the ship moves. However, it only moves in ONE direction. Even if I turn the ship to another heading the applied force vector is not changing.

Perhaps someone can see what I am doing wrong:

FYI: MySpaceShip->DirectionForce; is Ogre::Vector3

Code: Select all
vioid ThrottleUp()
{
   Ogre::Matrix3 m3;
   Ogre::Quaternion q;

   MySpaceShip->ThrottleSetting +=0.1;
   if (MySpaceShip->ThrottleSetting > 1.0f) MySpaceShip->ThrottleSetting = 1.0f;
   
   // get vector of ship and apply force

   // Get the current orientation of the ship.
   q = MySpaceShip->NodeShipControl->getOrientation();

   // Convert the Quaternion to a matrix3
   q.ToRotationMatrix(m3);

   // Apply the thrust
   MySpaceShip->DirectionalForce = m3 *
      Ogre::Vector3(0, 0, (MySpaceShip->ThrottleSetting * MySpaceShip->Thrust()));
} // ThrottleUp



SpaceShipApplyForceAndTorqueCallBack (const NewtonBody* nBody)
{
   float mass=0, Ixx=0, Iyy=0, Izz=0;
   Ogre::Vector3 Oforce(0,0,0), Otorque(0,0,0);
   Ogre::Vector3 Gravity = Ogre::Vector3 NEWTON_DEFAULT_GRAVITY;
   NewtonBodyGetMassMatrix (nBody, &mass, &Ixx, &Iyy, &Izz);
      
   // Apply force
   Oforce = SpaceShip->DirectionalForce;
   float Nforce[] = {(Gravity.x * mass) + Oforce.x,(Gravity.y * mass) + Oforce.y,(Gravity.z * mass) + Oforce.z};
   NewtonBodyAddForce(nBody,Nforce);

   // Apply Torque
   Otorque = SpaceShip->RotationalForce;
   float Ntorque[] = {Otorque.x, Otorque.y, Otorque.z};
   NewtonBodyAddTorque(nBody,Ntorque);

} // SpaceShipApplyForceAndTorqueCallBack





SpaceShipTransformCallback (const NewtonBody* nBody, const float* nMatrix)
{
     Ogre::Quaternion Oquat;
     Ogre::Vector3 Opos;
      ......(code cut out).....
     // Translate Newton Matrix to Ogre Quaternian and Vector 3
     MatrixToQuatPos(nMatrix, Oquat, Opos);
     // Position the node
     SpaceShip->NodeShipControl->setOrientation(Oquat);  // set Orientation (rotation)
     SpaceShip->NodeShipControl->setPosition(Opos); // set position

} // SpaceShipTransformCallback


Last edited by Van on Wed Nov 24, 2004 3:51 pm, edited 1 time in total.
Van
 
Posts: 17
Joined: Mon Nov 08, 2004 12:36 am

Postby Julio Jerez » Wed Nov 24, 2004 3:50 pm

Try transposing the matrix before calling matrix to quaterion.
I think walaber posted some utility function for that already
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Postby monster » Wed Nov 24, 2004 9:47 pm

However, it only moves in ONE direction. Even if I turn the ship to another heading the applied force vector is not changing.

How are you turning the ship?

If you just manually do "MySpaceShip->NodeShipControl->setOrientation(...)" when the user presses the "turn" keys then that will set the orientation of the Ogre node (I'm guessing that's what "NodeShipControl" is) but not the Newton body that you're using to represent that node physically. So when Newton calls SpaceShipTransformCallback it'll pass the rotation part of the matrix as identity (since the actual body hasn't rotated) and hence set the NodeShipControl orientation back to the non-rotated position.

If you want the Ogre node to be under control of Newton then you need to change the rotation by rotating the NewtonBody, e.g. by adding a torque to it.

I think I figured out that the scale between netwon and ogre is 1:1

Ogre has no implicit "scale". A unit can represent whatever you like, a centimeter, an inch, a meter, or a light-year. If you have chosen that 1 Newton unit = 1 meter then you should build the models for display in Ogre according to that scale. Or, the scales could be entirely different, and you could handle the differences in your Newton->Ogre->Newton matrix conversion functions.

did you write a routine to draw the newton collision meshes in ogre?

I'm working on it.
User avatar
monster
 
Posts: 9
Joined: Tue Apr 13, 2004 9:58 pm
Location: Melbourne, Australia

Postby walaber » Sun Dec 05, 2004 6:23 am

I finally got around to start working on my OgreNewt implementation!

this time it's all class-based, and I think it's working very well so far. here's a quick screenshot to show my progress:

Image

I have the basic primitives all working, as well as a standard ForceAndTorque callback + TransformCallback...

my next goal is to add ConvexHull and CollisionTree functionality! I'll post an image when I get it working :D
Independent game developer of (mostly) physics-based games. Creator of "JellyCar" and lead designer of "Where's My Water?"
User avatar
walaber
Moderator
Moderator
 
Posts: 393
Joined: Wed Mar 17, 2004 3:40 am
Location: California, USA

Postby Slick » Sun Dec 05, 2004 3:58 pm

Very cool. A nice wrapper for OGRE would be fantastic.
Slick
 
Posts: 330
Joined: Sat Feb 07, 2004 7:24 pm
Location: LA last and France now

Postby walaber » Sun Dec 05, 2004 10:25 pm

had some trouble with the TreeCollision and ConvexHull stuff this morning... I seem to be making some kind of mistake when I try to access the Vertex/Index data of an Ogre Mesh... I'll keep trying though :P
Independent game developer of (mostly) physics-based games. Creator of "JellyCar" and lead designer of "Where's My Water?"
User avatar
walaber
Moderator
Moderator
 
Posts: 393
Joined: Wed Mar 17, 2004 3:40 am
Location: California, USA

Postby walaber » Mon Dec 06, 2004 10:53 am

ah, now it's working!!

Image


...and better yet, with convex hulls!

Image
Independent game developer of (mostly) physics-based games. Creator of "JellyCar" and lead designer of "Where's My Water?"
User avatar
walaber
Moderator
Moderator
 
Posts: 393
Joined: Wed Mar 17, 2004 3:40 am
Location: California, USA

Postby Slick » Mon Dec 06, 2004 11:58 pm

That rocks. I know what you say about OOP. The concepts are great but sometimes the nuances of putting it together in C++ still get me.
Slick
 
Posts: 330
Joined: Sat Feb 07, 2004 7:24 pm
Location: LA last and France now

Postby Alain » Tue Dec 07, 2004 12:39 am

Wow Walaber, that knot looks really nice over the terrain.
Are you using the new height map user collision or a collision tree?
Alain
Site Admin
Site Admin
 
Posts: 28
Joined: Sun Sep 28, 2003 2:33 am
Location: Miami

Postby walaber » Tue Dec 07, 2004 1:06 am

just a TreeCollision... I haven't ventured into the heightmap yet... however Ogre has a nice Terrain system built in that is based on heightmaps, I'd like to be able to implement collision on that in the future as well... but my Ogre knowledge is still very limited.

for my current project, I think I'll go with TreeCollisions for the background objects, as it's just simpler to get started. it will eventually be a small game featuring the Vehicle :D

now that I have all primitives + convex hulls + treecollisions working, I can start thinking about ways to improve my basic class structure, and how I want to implement a vehicle. I think it'll be a cool mini-game when it's done :D
Independent game developer of (mostly) physics-based games. Creator of "JellyCar" and lead designer of "Where's My Water?"
User avatar
walaber
Moderator
Moderator
 
Posts: 393
Joined: Wed Mar 17, 2004 3:40 am
Location: California, USA

PreviousNext

Return to User Gallery

Who is online

Users browsing this forum: No registered users and 11 guests