Hi,

As Robert said, you can use an intersection to get the normal of the terrain,
after that you can use an osg::Quat, to save the rotation above the
terrain of the
tank. I Put here a simplified example:

class Tank {
  osg::Quat rotation;
  osg::Vec3d position;
  osg::Vec3d getUp();
  osg::Vec3d getHeading();
  ... other stuff...
}

after you hit the terrain, you can calculate the rotation
of the tank doing:
.... intersection stuff ...

osg::Vec3d up = tank->getUp();
osg::Vec3d normal = intersection.localIntersectionNormal;
osg::Quat rot;
rot.makeRotate(up, normal);
if(!rot.zeroRotation())
   tank->rotation*=rot;

.... other actions ....

so the last you need to know is how to get the UP of the tank
in every single step of calculation. The method I found was using
some useful helper math classes inside osg:

osg::Vec3d Tank::getUp() {
        osg::Matrix mat;
        mat.setRotate(this->rotation);
        osg::Vec3d v(0,0,1);
        osg::Vec3d up = osg::Matrix::transform3x3(v,mat);
        up.normalize();
        return up;
}

Using an osg::PositionAttitudeTransform, you can manage the
position of the tank, and the rotation of the tank.

Rafa.


On 5/22/07, Robert Osfield <[EMAIL PROTECTED]> wrote:
You could intersect the terrain using
osgUtil::LineSegmentIntersection/IntersectionVisitor.  Use three/four
intersections or just pick out the normal of the polygon from one
intersection.

On 5/22/07, HEMANTH <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
>         I want to simulate a vehicle on a terrain in OSG.but I am not able
> figure out how to simualte the pitch,yaw and roll of the vehicle according
> to the height of the terrain at a particular point.I mean the robot
> orientation should be changed according to the height of the terrain.
>
>         Is there any way of doing this ?
>
> --
> *************************************************************
> K.HEMANTH
> COMPUTER SCIENCE AND ENGINEERING(DUAL DEGREE)
> ROLL.NO# 200402017
> ROOM.NO# 399(OBH)
> CONTACT NO# 9849229262
> IIIT--HYDERABAD.
>
> EMAIL:
>         [EMAIL PROTECTED]
>         [EMAIL PROTECTED]
>         [EMAIL PROTECTED]
> **************************************************************
>
> --
> This message has been scanned for viruses and
> dangerous content by MailScanner, and is
> believed to be clean.
>
>
> --
> This message has been scanned for viruses and
> dangerous content by MailScanner, and is
> believed to be clean.
>
> _______________________________________________
> osg-users mailing list
> osg-users@openscenegraph.net
> http://openscenegraph.net/mailman/listinfo/osg-users
> http://www.openscenegraph.org/
>
_______________________________________________
osg-users mailing list
osg-users@openscenegraph.net
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/



--
Rafael Gaitán Linares
Instituto de Automática e Informática Industrial  http://www.ai2.upv.es
Ciudad Politécnica de la Innovación
Universidad Politécnica de Valencia
_______________________________________________
osg-users mailing list
osg-users@openscenegraph.net
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

Reply via email to