중급 튜토리얼 1-1
중급 튜토리얼 1 (번역 : n_Sys)
애니메이션, 두 지점간 이동시키기, 사원수의 기초
이 튜토리얼 진행에 있어서 문제가 생긴다면 Help 포럼에 문의하세요.
목차 |
소개
이 튜토리얼에서는 엔티티를 어떻게 획득하고 움직이게 하며, 어떻게 미리 지정된 두 지점간을 걸을 수 있게 하는가를 다루게 될 것입니다. 엔티티가 걷는방향을 자연스럽게 유지시키기 위해서 사원수 회전의 기초내용도 다루게 됩니다. 이 내용을 스스로 천천히 진행하면서 완성되어지는 결과물을 직접 확인하세요.
이 튜토리얼의 최종결과물은 여기에 있습니다.
사전 요구사항
이 튜토리얼은 여러분이 Ogre project를 어떻게 설정하고 컴파일 하는지에 대해서 이미 알고있다고 가정합니다. 그리고 이번 튜토리얼에서는 STL 의 deque 자료구조를 사용합니다. Deque에 대한 지식은 필요 없습니다. 단지 어떻게 쓰는지만 알면 됩니다. STL에 대해서 익숙치 않다면 STL포켓레퍼런스[ISBN 0-596-00556-3]를 한권 구입하시길 권장합니다.
STL포켓레퍼런스의 첫 부분을 여기서 읽을 수 있습니다.
시작하기
데모를 만들기위해서 새로운 프로젝트를 생성합니다. “MoveDemo.cpp” 이름의 파일을 추가하고 다음 내용을 추가하세요 :
#include "ExampleApplication.h"
#include <deque>
using namespace std;
class MoveDemoListener : public ExampleFrameListener
{
public:
MoveDemoListener(RenderWindow* win, Camera* cam, SceneNode *sn,
Entity *ent, deque<Vector3> &walk)
: ExampleFrameListener(win, cam, false, false), mNode(sn), mEntity(ent), mWalkList(walk)
{
} // MoveDemoListener
/* This function is called to start the object moving to the next position
in mWalkList.
*/
bool nextLocation()
{
return true;
} // nextLocation()
bool frameStarted(const FrameEvent &evt)
{
return ExampleFrameListener::frameStarted(evt);
}
protected:
Real mDistance; // The distance the object has left to travel
Vector3 mDirection; // The direction the object is moving
Vector3 mDestination; // The destination the object is moving towards
AnimationState *mAnimationState; // The current animation state of the object
Entity *mEntity; // The Entity we are animating
SceneNode *mNode; // The SceneNode that the Entity is attached to
std::deque<Vector3> mWalkList; // The list of points we are walking to
Real mWalkSpeed; // The speed at which the object is moving
};
class MoveDemoApplication : public ExampleApplication
{
protected:
public:
MoveDemoApplication()
{
}
~MoveDemoApplication()
{
}
protected:
Entity *mEntity; // The entity of the object we are animating
SceneNode *mNode; // The SceneNode of the object we are moving
std::deque<Vector3> mWalkList; // A deque containing the waypoints
void createScene(void)
{
}
void createFrameListener(void)
{
mFrameListener= new MoveDemoListener(mWindow, mCamera, mNode, mEntity, mWalkList);
mFrameListener->showDebugOverlay(true);
mRoot->addFrameListener(mFrameListener);
}
};
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT)
#else
int main(int argc, char **argv)
#endif
{
// Create application object
MoveDemoApplication app;
try {
app.go();
} catch(Exception& e) {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
MessageBox(NULL, e.getFullDescription().c_str(), "An exception has occurred!",
MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
fprintf(stderr, "An exception has occurred: %s\n",
e.getFullDescription().c_str());
#endif
}
return 0;
}
컴파일이 제대로 되는지 확인하세요.