rotationogre

Blender Car Model Rotate wheel turn wheel together


I have imported a Benz car model from Blender to OGRE. I am trying to rotate the wheels.

I have 2 requirements. Rotate the wheel like the car is running and rotate the wheel left and right as it is turning based on the steering wheel. I can successfully do it separately but when I do it together, I am getting wrong results.

Before I imported the model from Blender, I made 4 local pivot points for the wheels based on the center(Using set Pivot point based on 3D point cursor option in Blender).

In OGRE, after I imported the model, I parsed the entire scene manager and found the 4 wheel nodes and named as left front, left back, right front and right back nodes. It is as below.

 void ogreWindow::makeNodes( )
  {
    Ogre::SceneNode::ChildNodeIterator it = mSceneMgr->getRootSceneNode()-  
    >getChildIterator();
     QString _name;
while (it.hasMoreElements())
{
    Ogre::Node* node_ = it.getNext();
    Ogre::String _name=node_->getName();
    QString ssss = QString::fromUtf8(_name.c_str());
    qDebug()<<"Entities are "<<ssss;
    if(ssss=="WheelRightBack_transform2")
    {
        rotateNodeBackWheel_Right =   mSceneMgr->getSceneNode("WheelRightBack_transform2");
        m_RotateWheeel = true;
    }
    if(ssss=="WheelleftBack_transform12")
    {
        rotateNodeBackWheel_Left =   mSceneMgr->getSceneNode("WheelleftBack_transform12");
        m_RotateWheeel = true;
    }
    if(ssss=="Wheel_LeftFront_transform15")
    {
        rotateNodeFrontWheel_Right =   mSceneMgr->getSceneNode("Wheel_LeftFront_transform15");
        turnNodeFrontWheel_Right =   mSceneMgr->getSceneNode("Wheel_LeftFront_transform15");

        m_RotateWheeel = true;
    }
    if(ssss=="WheelRightFront_transform3")
    {
        rotateNodeFrontWheel_Left =   mSceneMgr->getSceneNode("WheelRightFront_transform3");
        turnNodeFrontWheel_Left =   mSceneMgr->getSceneNode("WheelRightFront_transform3");
        m_RotateWheeel = true;
    } 
}

}

Then In framerenderingQueued funciton, I am indefenitely calling a rotate function as below:

bool ogreWindow::frameRenderingQueued(const Ogre::FrameEvent& fe)
{

                  if(m_RotateWheeel)
                          {
                         RotateWheel();
                          }
                      .......
                       .......
 }

Where the rotateWheel() is as below

void ogreWindow::RotateWheel()
{


//Working with Euler rotation

//Section 1
if(rotateNodeBackWheel_Left)
    rotateNodeBackWheel_Left->yaw(Ogre::Radian(0.01),Ogre::Node::TransformSpace::TS_LOCAL);
if(rotateNodeBackWheel_Right)
    rotateNodeBackWheel_Right->yaw(Ogre::Radian(0.01),Ogre::Node::TransformSpace::TS_LOCAL);
if(rotateNodeFrontWheel_Left)
    rotateNodeFrontWheel_Left->yaw(Ogre::Radian(0.01),Ogre::Node::TransformSpace::TS_LOCAL);
if(rotateNodeFrontWheel_Right)
    rotateNodeFrontWheel_Right->yaw(Ogre::Radian(0.01),Ogre::Node::TransformSpace::TS_LOCAL);

//Section 2
if(isTurning)
{
    if(rotateNodeFrontWheel_Right)
        rotateNodeFrontWheel_Right->roll(Ogre::Radian(turningRadius),Ogre::Node::TransformSpace::TS_LOCAL);

    if(rotateNodeFrontWheel_Right)
        rotateNodeFrontWheel_Right->roll(Ogre::Radian(turningRadius),Ogre::Node::TransformSpace::TS_LOCAL);
}    

isTurning = false;
}

So the problems I am facing is described below,

a) When I do section 1 alone, the wheel is rotating smoothly b) When I do section 2 alone, the wheel will be rendered as turned - OK fine c) When I do section 1 and section 2 together, OK it is rendering with the wheel rotating and wheel turned in "turnRadius" degree.(Image attached-A.png) enter image description here

d) But If I try to change the value of turnRadius at run time, it is getting crazy. enter image description here

The side view is as below enter image description here

I am changing the value of turnRadius as below. I call this function from 2 button clicks from UI.

 void ogreWindow::turnFrontWheelLeft(Ogre::Real radius)
{
//turningRadius-=0.1;
turningRadius = -0.1;
isTurning = true;

 }

 void ogreWindow::turnFrontWheelRight(Ogre::Real radius)
 {
  //turningRadius+=0.1;
  turningRadius = 0.1;
  isTurning = true;
 }

I understand the problem is the axis issue. How can I make it perfect? I want to do the turn and rotate "rotations" together.


Solution

  • It is working now. I created sub-nodes and did the transforms separately.

    http://www.ogre3d.org/forums/viewtopic.php?f=1&t=92364&sid=e21b8189a3defe7ae1c3c4c3b7c4cc57