Car model Wheel rotation not working - Wheeling and turning

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
Post Reply
Bincy
Gnoblar
Posts: 2
Joined: Thu Mar 16, 2017 11:07 am

Car model Wheel rotation not working - Wheeling and turning

Post by Bincy »

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.

Code: Select all

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:

Code: Select all

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

                  if(m_RotateWheeel)
                          {
                         RotateWheel();
                          }
                      .......
                       .......
 }
Where the rotateWheel() is as below

Code: Select all

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)
d) But If I try to change the value of turnRadius at run time, it is getting crazy.

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

Code: Select all

 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.
Attachments
another camera view
another camera view
One camera view
One camera view
Initial rendering
Initial rendering
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 168

Re: Car model Wheel rotation not working - Wheeling and turn

Post by xrgo »

Hello! (disclaimer: I am lazy so I just read your post really quickly so there's a chance I am talking nonsense)

the easiest way to achieve what you want is (out of my mind, havent tested it):

for the front wheels have 2 nested nodes, lets call them parentNode and childNode, add the Entity/Item to the childNode, attach de childNode to the parentNode and attach the parentNode to the chassis... so now its just a matter of apply the rotation of the steering (direction) to the parentNode, and the rotation of the advance (gaz) to the childNode, both in the corresponding axis respectively, and walla!

Good luck!
Bincy
Gnoblar
Posts: 2
Joined: Thu Mar 16, 2017 11:07 am

Re: Car model Wheel rotation not working - Wheeling and turn

Post by Bincy »

for the front wheels have 2 nested nodes, lets call them parentNode and childNode, add the Entity/Item to the childNode, attach de childNode to the parentNode and attach the parentNode to the chassis...
Thank you.

It's worked. For those friends, who need a hand in future, please see the sample code below.

Code: Select all

void ogreWindow::getTransformEntitiesFromScene(bool dummyflag )
{


    qDebug()<<"Now the size of list  is ***************************************"<<m_entities.size();
    for (int i=0;i<m_entities.size();i++)
    {
       qDebug() << "Entities are " << m_entities[i]->getName().c_str()<<m_entities[i]->getParentSceneNode()->getName().c_str();
       std::cout << "\n";
    }
    qDebug()<<"Now the size of list  is after ***************************************"<<m_entities.size();
    rotateNodeBackWheel_Right  = mSceneMgr->getEntity("S3_FRWHEEL_S3_FRWHEEL_000-mesh")->getParentSceneNode();
    rotateNodeBackWheel_Left   = mSceneMgr->getEntity("S3_FLWHEEL_S3_FLWHEEL_002-mesh")->getParentSceneNode();



    //For Left Wheel
    turnNodeFrontWheel_Left = mSceneMgr->getEntity("S3_FLWHEEL_S3_FLWHEEL_001-mesh")->getParentSceneNode();
    rotateNodeFrontWheel_Left = turnNodeFrontWheel_Left->createChildSceneNode("Nested1");
    Ogre::Entity *tyreEntity1 = mSceneMgr->getEntity("S3_FLWHEEL_S3_FLWHEEL_001-mesh");
    tyreEntity1->detachFromParent();
    rotateNodeFrontWheel_Left->attachObject(tyreEntity1);


    //For Right wheel
    turnNodeFrontWheel_Right = mSceneMgr->getEntity("S3_FRWHEEL_S3_FRWHEEL_001-mesh")->getParentSceneNode();
    rotateNodeFrontWheel_Right = turnNodeFrontWheel_Right->createChildSceneNode("Nested2");
    Ogre::Entity *tyreEntity2 = mSceneMgr->getEntity("S3_FRWHEEL_S3_FRWHEEL_001-mesh");
    tyreEntity2->detachFromParent();
    rotateNodeFrontWheel_Right->attachObject(tyreEntity2);


    Ogre::Light* light1 = mSceneMgr->createLight("Light2");
    light1->setType(Ogre::Light::LT_POINT);
    // Set Light Color
    light1->setDiffuseColour(1.0f, 1.0f, 1.0f);
    // Set Light Reflective Color
    light1->setSpecularColour(1.0f, 0.0f, 0.0f);
    // Set Light (Range, Brightness, Fade Speed, Rapid Fade Speed)
    light1->setAttenuation(10, 0.5, 0.045, 0.0);

    Ogre::SceneNode *lnode =  rotateNodeFrontWheel_Left->createChildSceneNode("RotateNodeLight");
    lnode->attachObject(light1);



    m_RotateWheeel = true;
    isTurning = true;
}
And for turning and rotating code is as below

Code: Select all

void ogreWindow::RotateWheel()
{
    //Working with Euler rotation
    //Section 1



    if(rotateNodeBackWheel_Left)
        rotateNodeBackWheel_Left->pitch(Ogre::Radian(-1*0.1),Ogre::Node::TransformSpace::TS_LOCAL);
    if(rotateNodeBackWheel_Right)
        rotateNodeBackWheel_Right->pitch(Ogre::Radian(-1*0.1),Ogre::Node::TransformSpace::TS_LOCAL);
    if(rotateNodeFrontWheel_Left)
        rotateNodeFrontWheel_Left->pitch(Ogre::Radian(-1*0.1),Ogre::Node::TransformSpace::TS_LOCAL);
    if(rotateNodeFrontWheel_Right)
        rotateNodeFrontWheel_Right->pitch(Ogre::Radian(-1*0.1),Ogre::Node::TransformSpace::TS_LOCAL);

    if(isTurning)
    {
        if(turnNodeFrontWheel_Right)
            turnNodeFrontWheel_Right->roll(Ogre::Radian(turningRadius),Ogre::Node::TransformSpace::TS_LOCAL);
        if(turnNodeFrontWheel_Left)
            turnNodeFrontWheel_Left->roll(Ogre::Radian(turningRadius),Ogre::Node::TransformSpace::TS_LOCAL);
    }

    isTurning = false;
}

Thank you xrgo.

:)
Post Reply