|
各位大神好:
小弟最近在学习osg的fbx骨骼动画,遇到如下几个问题:
1. 导出的fbx人物在场景中是横躺着,通过实验知道几种解决方法(在osg程序了旋转模型,或者在导出的时候选择Z-up或者Y-up)前面一种实验成功,但是后面一种怎么弄都没反映,由于想在程序里控制人物行走,也需要矩阵计算,这样和前面的旋转人物的矩阵计算起了冲突,不知道有什么解决方法?
2. 关于动作分段的问题,听威哥大神说过可以用整个动作以关键帧时间分段,可惜小弟的程序功底不好,不知道怎么去实现,有没有类似的例子供参考呢? 还听说可以用Motionbuilder来制作带多个动作的fbx文件,不知道具体的步骤是?
3. 还有就是跟随摄像头的问题,怎么实现摄像头随着人的移动而移动,有没有实例?
4。控制人物前后左右移动怎么实现呢?通过实验,解决了左右旋转问题,但是前后走还解决不了,尝试了以下方法,但是只有左右旋转效果,没有前后移动效果。
class UseEventHandler : public osgGA::GUIEventHandler
{
public:
UseEventHandler(osg::MatrixTransform* tankPosistion)
{
trans=tankPosistion;
trans->setMatrix(osg::Matrix::translate(0,0,7));
//trans->setMatrix(osg::Matrix::rotate(osg:I_2,osg::Vec3(1,0,0)));
m_tankPosistion=osg::Vec3(0,0,7);
tankSpeed=0.2;
m_fAngle=0;
btnUP=false;
btnDOWN=false;
btnLEFT=false;
btnRIGHT=false;
}
virtual bool handle(const osgGA::GUIEventAdapter & ea,osgGA::GUIActionAdapter & aa)
{
switch (ea.getEventType())
{
case osgGA::GUIEventAdapter::KEYDOWN:
{
if (ea.getKey() == 0xFF52 || ea.getKey () == 0x57 || ea.getKey () == 0x77)//up
{
btnUP=true;
return true;
}
if (ea.getKey() == 0xFF54 || ea.getKey () == 0x53 || ea.getKey () == 0x73 )//down
{
btnDOWN=true;
return true;
}
if (ea.getKey () == 0x41||ea.getKey () == 0x61) //A
{
btnLEFT=true;
return true;
}
if (ea.getKey () == 0x44||ea.getKey () == 0x64)//D
{
btnRIGHT=true;
return true;
}
return false;
case osgGA::GUIEventAdapter::KEYUP:
if (ea.getKey() == 0xFF52 || ea.getKey () == 0x57 || ea.getKey () == 0x77)//up
{
btnUP=false;
return true;
}
if (ea.getKey() == 0xFF54 || ea.getKey () == 0x53 || ea.getKey () == 0x73 )//down
{
btnDOWN=false;
return true;
}
if (ea.getKey () == 0x41||ea.getKey () == 0x61) //A
{
btnLEFT=false;
return true;
}
if (ea.getKey () == 0x44||ea.getKey () == 0x64)//D
{
btnRIGHT=false;
return true;
}
}
break;
default:
break;
}
if (btnUP)
{
m_tankPosistion+=osg::Vec3(tankSpeed*cosf(osg:egreesToRadians(m_fAngle+90)),tankSpeed*sinf(osg::DegreesToRadians(m_fAngle+90)),0);
trans->setMatrix(osg::Matrix::rotate(osg::DegreesToRadians(m_fAngle),0,0,1)*osg::Matrix::translate(m_tankPosistion));
}
if (btnDOWN)
{
m_tankPosistion-=osg::Vec3(tankSpeed*cosf(osg::DegreesToRadians(m_fAngle+90)),tankSpeed*sinf(osg::DegreesToRadians(m_fAngle+90)),0);
trans->setMatrix(osg::Matrix::rotate(osg::DegreesToRadians(m_fAngle),0,0,1)*osg::Matrix::translate(m_tankPosistion));
}
if (btnLEFT) //A
{
m_fAngle -= 1 ;
trans->setMatrix(osg::Matrix::rotate(osg::DegreesToRadians(m_fAngle),0,0,1)*osg::Matrix::translate(m_tankPosistion));
return true;
}
if (btnRIGHT)//D
{
m_fAngle += 1 ;
trans->setMatrix(osg::Matrix::rotate(osg::DegreesToRadians(m_fAngle),0,0,1)*osg::Matrix::translate(m_tankPosistion));
return true;
}
return false;
}
private:
float tankSpeed;
osg::MatrixTransform* trans;
osg::Vec3 m_tankPosistion;
float m_fAngle;
private:
bool btnUP;
bool btnDOWN;
bool btnLEFT;
bool btnRIGHT;
};
|
|