Hi,

I am attaching a screenshot of what I am trying to do. In the screenshot you 
can see 2 objects placed on a terrain. The lower one is rotated about Z axis 
and I use the keyboard UP and DOWN keys to move the object along the Y-axis in 
the terrain.

However even after I have rotated the object, I am not able to figure out how 
to get the new vector along which the object is now pointing. 

I figured I would find the angle I have rotated the object by using Quat and 
then depending on angle value 0-90, 90-180, 180-270 or 270-360, find the 
tangent of the angle and move it that way. But I'm sure im complicating things 
here.

The code I'm using to move the object and rotate is pasted below: (i've only 
copied the cases for Up and rotate right as down and left are identical)

else if ( ea.getKey()==osgGA::GUIEventAdapter::KEY_Up)
        {
                        std::cout << textBox->getText() << std::endl;           
        
                        positionArray = PATCurrent->getPosition();
                        //vector = PATCurrent->getAttitude().asVec3();
                        PATCurrent->getAttitude().getRotate(angle,vector);
                        angleDegrees = osg::RadiansToDegrees(angle);
                        y = positionArray.y();
                        x = positionArray.x();
                        x += vector.x();
                        y += 1;
                        positionArray.y()=y;
                        positionArray.x()=x;
                        PATCurrent->setPosition(positionArray);
                        return true;
                } 
                else if ( ea.getKey()==osgGA::GUIEventAdapter::KEY_Right)
        {
                        //use key right to rotate the object to the right
                        quat = PATCurrent->getAttitude();
                        quat.getRotate(angle, vector);
                        angleDegrees = osg::RadiansToDegrees(angle);
                        //if angle is 0 make it 360
                        if(angleDegrees <= 1)
                        {
                          angleDegrees = 360;
                        }
                        angleDegrees -= 1;
                        
quat.makeRotate(osg::DegreesToRadians(angleDegrees),vector);
                        PATCurrent->setAttitude(quat);
                        //PATCurrent->setPosition(vector);
                }

If you can tell me what I am missing out here I'd be very thankful.

Also, if there is some literature out there that deals with this, I'd be more 
than happy to study it.

Thanks,

Sincerely,

Sanat

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=29505#29505




Attachments: 
http://forum.openscenegraph.org//files/test_sc1_368.jpg


_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to