【TomoEngine】 第五讲 【MOBA制作日记一】 角色

来源:互联网 发布:美工刀片自动装盒机 编辑:程序博客网 时间:2024/04/29 12:36

      用TomoEngine制作一款MOBA是近期的一个计划,从一个简单的场景开始,逐步丰富场景内容。

        工程文件(VS2013)下载       工程bin 下载

        场景从一个角色开始,作者制作了一个角色动画模型 功夫熊猫,看上去有点简陋,以后会一点点完善它。

        正常运行结果如图:点击键盘 Z X C V 切换动画,点击 W A S D做简单移动

          

        程序架构解析

        01 main函数 App3DMoba类

#include "App3DMoba.h"void main(){App3DFramework* app = new App3DMoba_NS::App3DMoba;app->go();delete app;}


        02 场景元素创建 Player

void App3DMoba::LoadRes(){LOGINFO("load_res thread begin");ResourceGroupManager::GetSingleton().InitialiseResourceGroup("Popular");m_pPlayer = new Player(m_pCurrentScene);m_pPlayer->SetupBody("Jack", "panda.meshml");m_pActiveCamera->SetAutoTracking(true,m_pPlayer->GetPlayerNode());m_pCurrentScene->SetSkyBox(true, "SpaceSkyBox", 2000.f);//BuildTerrain();LOGINFO("load_res thread end");}

void Player::SetupBody(const string& playerName,const string& meshName){m_humanNode = m_sceneMgr->GetRootSceneNode()->CreateChildSceneNode(playerName);m_humanEnt = m_sceneMgr->CreateEntity(playerName, meshName);m_humanEnt->SetAnimationState("front_walk");Vector3 pos = Vector3(0.f, 0.f, -400.f);m_humanNode->SetPosition(pos);m_humanNode->AttachObject(m_humanEnt);Quaternion quat;Vector3 xaxis(1.f, 0.f, 0.f);Vector3 yaxis(0.f, 1.f, 0.f);quat.FromAngleAxis(-PI / 2, xaxis);m_humanNode->SetQuaternion(quat);}


        03 Player动画切换控制 (具体攻击行为相关的部分请期待下一讲)

bool Player::OnKeyReleased(const KeyEvent& arg){if (arg.key == KC_Z){AnimationState* m_pAnimState = m_humanEnt->GetAnimationState("idle");m_humanEnt->SetAnimationState(m_pAnimState);}else if(arg.key == KC_C){AnimationState* m_pAnimState = m_humanEnt->GetAnimationState("front_walk");m_humanEnt->SetAnimationState(m_pAnimState);}else if (arg.key == KC_V){AnimationState* m_pAnimState = m_humanEnt->GetAnimationState("attack");m_humanEnt->SetAnimationState(m_pAnimState);}m_BodyMove = false;return true;}bool Player::OnKeyPressed(const KeyEvent& arg){m_curKey = arg.key;m_BodyMove = true;return true;}void Player::Update(float frameTimeSinceLastFrame){if(m_Move){Vector3 dir = Vector3::UNIT_X;dir = m_Velocity*dir;m_attackNode->Translate(dir, Tomo::Node::TS_LOCAL);}if(m_BodyMove){float velocity = PI / 200.f;//LOGINFO(TOSTRING(m_humanNode->GetDerivedPosition()));if (m_curKey == KC_A){Vector3 dir = -Vector3::UNIT_X;dir = m_Velocity*dir;m_humanNode->Translate(dir);}else if (m_curKey == KC_D){Vector3 dir = Vector3::UNIT_X;dir = m_Velocity*dir;m_humanNode->Translate(dir);}else if (m_curKey == KC_W){Vector3 dir = -Vector3::UNIT_Z;dir = m_Velocity*dir;m_humanNode->Translate(dir);}else if (m_curKey == KC_S){Vector3 dir = Vector3::UNIT_Z;dir = m_Velocity*dir;m_humanNode->Translate(dir);}else if (m_curKey == KC_LEFT){if (m_humanNode){Quaternion quat;quat.FromAngleAxis(velocity, Vector3::UNIT_Y);m_humanNode->Rotate(quat);quat.FromAngleAxis(velocity, Vector3::UNIT_X);m_humanNode->Rotate(quat);}}else if (m_curKey == KC_RIGHT){if (m_humanNode){Quaternion quat;quat.FromAngleAxis(-velocity, Vector3::UNIT_Y);m_humanNode->Rotate(quat);quat.FromAngleAxis(-velocity, Vector3::UNIT_X);m_humanNode->Rotate(quat);}}}}



0 0
原创粉丝点击