핚국산업기술대학교 제 9 강캐릭터컨트롤러 이대현교수
학습안내 학습목표 씬노드의구성및회전방법을응용하여, 구면카메라및캐릭터컨트롤을구현해본다. 학습내용 구면카메라구현을위한씬노드구성및회전캐릭터컨트롤을위한씬노구구성및회전
카메라및캐릭터컨트롤구현목표 카메라컨트롤 WOW의카메라컨트롤 ( 구면카메라 ) 마우스를이용한좌우패닝, 상하피칭. 휠스크롤을이용한줌인및줌아웃. 캐릭터를중심으로회전됨. 카메라를회전시킬때, 캐릭터는자신의상태유지. 캐릭터컨트롤 WASD 를이용한캐릭터의전후진이동, 좌우이동, 대각선이동
실습 Control(2) 구면카메라구현
bool mousemoved( const OIS::MouseEvent &evt ) myaw->yaw(degree(-evt.state.x.rel)); mpitch->pitch(degree(-evt.state.y.rel)); 실습 mholder->translate(ogre::vector3(0, 0, -evt.state.z.rel * 0.1f)); return true;
class LectureApp void go(void)... 중략... SceneNode* camerayaw = professorroot->createchildscenenode("yaw",vector3(0.0f,120.0f,0.0f)); SceneNode* camerapitch = camerayaw->createchildscenenode("pitch"); 실습 SceneNode* cameraholder = camerapitch->createchildscenenode("holder",vector3(0.0f,80.0f,500.0f));... 중략...
실행결과 마우스를이용핚구면카메라컨트롤
카메라컨트롤및홀더노드설정 SceneNode* camerayaw = professorroot->createchildscenenode("yaw",vector3(0.0f,120.0f,0.0f)); SceneNode* camerapitch = camerayaw->createchildscenenode("pitch"); SceneNode* cameraholder = camerapitch->createchildscenenode("holder",vector3(0.0f,80.0f,500.0f)); Y Yaw Pitch Holder Professor Root X Z
Yaw Control Y myaw->yaw(degree(-evt.state.x.rel)); Yaw Pitch Holder Professor Root Holder X Z
Pitch Control Y Holder mpitch->pitch(degree(-evt.state.y.rel)); Yaw Pitch Holder Professor Root X Z
Zoom Control Y Yaw Pitch Holder Holder Professor Root X mholder->translate(ogre::vector3(0, 0, -evt.state.z.rel * 0.1f)); Z
실습 CharacterController 방향키와마우스를이용한캐릭터이동구현
실습 bool framestarted(const FrameEvent &evt)... 중략... if (mcharacterdirection!= Vector3::ZERO) mcharacterroot->setorientation(myaw->getorientation()); Quaternion quat = Vector3(Vector3::UNIT_Z).getRotationTo(mCharacterDirection); mcharacteryaw->setorientation(quat); mcharacterroot->translate(mcharacterdirection.normalisedcopy() * 111 * evt.timesincelastframe, Node::TransformSpace::TS_LOCAL); if (!mwalkstate->getenabled()) mwalkstate->setenabled(true); midlestate->setenabled(false); mwalkstate->addtime(evt.timesincelastframe); else if (!midlestate->getenabled()) midlestate->setenabled(true); mwalkstate->setenabled(false); midlestate->addtime(evt.timesincelastframe);... 중략...
bool keypressed( const OIS::KeyEvent &evt ) switch(evt.key) case OIS::KC_W: case OIS::KC_UP: mcharacterdirection.z += -1.0f; break; case OIS::KC_S: case OIS::KC_DOWN: mcharacterdirection.z += 1.0f; break; case OIS::KC_A: case OIS::KC_LEFT: mcharacterdirection.x += -1.0f; break; case OIS::KC_D: case OIS::KC_RIGHT: mcharacterdirection.x += 1.0f; break; case OIS::KC_ESCAPE: mcontinue = false; break; return true; bool keyreleased( const OIS::KeyEvent &evt ) switch(evt.key) case OIS::KC_W: case OIS::KC_UP: mcharacterdirection.z -= -1.0f; break; case OIS::KC_S: case OIS::KC_DOWN: mcharacterdirection.z -= 1.0f; break; case OIS::KC_A: case OIS::KC_LEFT: mcharacterdirection.x -= -1.0f; break; case OIS::KC_D: case OIS::KC_RIGHT: mcharacterdirection.x -= 1.0f; break; case OIS::KC_ESCAPE: mcontinue = false; break; return true; 실습
class LectureApp void go(void)... 중략... 실습 SceneNode* professorroot = mscenemgr->getrootscenenode()->createchildscenenode("professorroot"); SceneNode* professoryaw = professorroot->createchildscenenode("professoryaw"); SceneNode* camerayaw = professorroot->createchildscenenode("yaw", Vector3(0.0f, 120.0f, 0.0f)); SceneNode* camerapitch = camerayaw->createchildscenenode("pitch"); SceneNode* cameraholder = camerapitch->createchildscenenode("holder", Vector3(0.0f, 80.0f, 500.0f)); camerayaw->setinheritorientation(false);... 중략...
실행결과 WASD 캐릭터이동 + 마우스카메라조정
캐릭터와카메라의회전연결차단 SceneNode* professorroot = mscenemgr->getrootscenenode()->createchildscenenode("professorroot"); SceneNode* professoryaw = professorroot->createchildscenenode("professoryaw"); Y SceneNode* camerayaw = professorroot->createchildscenenode("yaw", Vector3(0.0f, 120.0f, 0.0f)); SceneNode* camerapitch = camerayaw->createchildscenenode("pitch"); SceneNode* cameraholder = camerapitch->createchildscenenode("holder", Vector3(0.0f, 80.0f, 500. 0f)); camerayaw->setinheritorientation(false); mpitch->pitch(degree(-evt.state.y.rel)); Yaw Pitch Holder Professor Root X Z
카메라방향과캐릭터방향의조정 if (mcharacterdirection!= Vector3::ZERO) // 방향전환운동이시작될때, 캐릭터의축을카메라축과 align mcharacterroot->setorientation(myaw->getorientation()); // 캐릭터의바라보는방향을전환 Quaternion quat = Vector3(Vector3::UNIT_Z).getRotationTo(mCharacterDirection); mcharacteryaw->setorientation(quat); // 캐릭터축을기준으로하여, 캐릭터이동 ( 속도 : 111cm / sec = 약 4km / sec) // Character Root 의 local space 를기준으로이동 mcharacterroot->translate(mcharacterdirection.normalisedcopy() * 111 * evt.times incelastframe, Node::TransformSpace::TS_LOCAL);
학습정리 구면카메라컨트롤 카메라의 Yaw, Pitch 및 Zoom 을위한씬노드를각각따로둠. 캐릭터컨트롤 캐릭터와카메라의회전을분리함 독립적으로회전설정. Yaw Control 을이용하여자체에서회전.