[英]Blender Car Model Rotate wheel turn wheel together
I have imported a Benz car model from Blender to OGRE.我已将奔驰汽车模型从 Blender 导入到 OGRE。 I am trying to rotate the wheels.
我正在尝试旋转轮子。
I have 2 requirements.我有2个要求。 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).在从 Blender 导入模型之前,我基于中心为车轮制作了 4 个局部枢轴点(使用基于 Blender 中的 3D 点光标选项设置枢轴点)。
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.在OGRE中,导入模型后,解析整个场景管理器,找到4个轮子节点,命名为左前、左后、右前、右后节点。 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:然后在 framerenderingQueued 函数中,我无限地调用一个旋转函数,如下所示:
bool ogreWindow::frameRenderingQueued(const Ogre::FrameEvent& fe)
{
if(m_RotateWheeel)
{
RotateWheel();
}
.......
.......
}
Where the rotateWheel() is as below其中rotateWheel()如下
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) a) 当我单独做第 1 部分时,轮子旋转顺畅 b) 当我单独做第 2 部分时,轮子将呈现为转动 - 好的 c) 当我一起做第 1 部分和第 2 部分时,可以渲染车轮旋转和车轮转动“turnRadius”度。(附图片-A.png)
d) But If I try to change the value of turnRadius at run time, it is getting crazy. d) 但是如果我尝试在运行时更改 turnRadius 的值,它会变得很疯狂。
The side view is as below侧视图如下
I am changing the value of turnRadius as below.我正在更改 turnRadius 的值,如下所示。 I call this function from 2 button clicks from UI.
我从用户界面的 2 次按钮点击中调用这个函数。
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.
我想转弯并一起旋转“旋转”。
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 http://www.ogre3d.org/forums/viewtopic.php?f=1&t=92364&sid=e21b8189a3defe7ae1c3c4c3b7c4cc57
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.