A. INSTALASI OGRE & PEMBUATAN MODEL ROBOT
Langkah-langkah untuk menginstall Ogre pada komputer/laptop kita adalah sebagai berikut :
1. Unduh perlengkapan/software yang dibutuhkan untuk menginstall Ogre ini, seperrti yang telah disebutkan sebelumnya
2. Ekstrak Eclipse Ganymede dari rar-nya
3. Install MinGW, lalu kita setting terlebih dulu di environment Windows, setelah itu, cek di command prompt dengan cara mengetikkan gcc –v
1.
1. Setelah itu install MYSYS
Lalu masuk kembali ke environment di Windows, untuk menambahkan Path kembali. Jika sudah kita masukkan ke Path, kita jalankan salah satu perintah Linux, seperti uname –a, maka pasti akan muncul hasilnya.1. Lalu, install OgreSDK, setelah itu kita masukkan kembali ke Path di environment Windows.
1. Jalankan Eclipse Ganymede
2. Buat new C++ project
1. Pada bagian kanannya akan terlihat bahwa MinGW sudah terintegrasi
Jika berhasil maka pada bagian Project Explorer akan muncul sebuah hirarki
Tekan ctrl+F11, maka pada bagian console akan muncul output yang bertuliskan Hello World
1. Masuk ke bagian GCC C++ Compiler pada Tool Settings, selanjutnya ikutilah petunjuk table berikut ini untuk bagian-bagian properties pada pilihan Debug dan Release. Pastikan yang aktif adalah Release.
DEBUG | RELEASE |
Preprocessor | |
Defined Symbols (-D): · WIN32 · _WINDOWS · _DEBUG | Defined Symbols (-D): · WIN32 · _WINDOWS · NDEBUG |
Directories | |
Include Paths (-l): · "${OGRE_HOME}\include" · "${OGRE_HOME}\samples\include" Dengan kutip “ | Include Paths (-l): · "${OGRE_HOME}\include" · "${OGRE_HOME}\samples\include" Dengan kutip “ |
Miscellaneous | |
Bag. Other flags : -c -fmessage-length=0 -mthreads -fexceptions -fident | Bag. Other flags : -c -fmessage-length=0 -mthreads -fexceptions -fident |
1. Mash pada bagian Tool Setting, masuk ke bagian MinGW C++ Linker ikutilah petunjuk table berikut ini untuk bagian-bagian properties pada pilihan Debug dan Release. Pastikan yang aktif adalah Release.
DEBUG | RELEASE |
Libraries | |
Libraries (-l): · OgreMain_d · OIS_d | Libraries (-l): · OgreMain · OIS |
Library search path (-L): · "${OGRE_HOME}\bin\debug" Dengan kutip “ | Library search path (-L): · "${OGRE_HOME}\bin\release" Dengan kutip “ |
Miscellaneous | |
Bag. Other Options (-Xlinker[option]): · --enable-auto-image-base · --add-stdcall-alias | Bag. Other Options (-Xlinker[option]): · --enable-auto-image-base · --add-stdcall-alias |
Setelah itu, buat project C++ baru dengan nama robot berjalan, lalu buat class baru, dan isikan coding seperti yang terletak di bagian bawah ini (codingnya jika dilihat sama dengan ketika membuat grafik robot, hal ini memang karena penulisan ini memakai mesh robot seperti yang telah dijelaskan pada saat membuat grafik robot, dan ditambahkan coding untuk melakukan animasi gerak jalan).
Jika pada percobaan pembuatan grafik robot telah ada (saat praktikum), maka coding yang telah ada tersebut dapat diimport ke dalam project yang baru tadi.
1. Build project itu, maka akan dihasilkan exe, lalu masuk ke direktori OgreSDK untuk mengedit resource.cfg. Isilah bagian yang masih kosong menjadi seperti pada gambar di bawah ini (pada gambar di bawah direktori OgreSDK penulis berada di partisi C), pengisian ini dilakukan karena pada defaultnya, direktori yang terletak pada resource.cfg masih berupa titik-titik kosong.
B. PEMBUATAN ANIMASI ROBOT SEDERHANA
1.
#include "ExampleApplication.h"
#include
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)
{
// Set default values for variables
mWalkSpeed = 35.0f;
mDirection = Vector3::ZERO;
} // MoveDemoListener
/* This function is called to start the object moving to the next position
in mWalkList.
*/
bool nextLocation()
{
if (mWalkList.empty())
return false;
mDestination = mWalkList.front(); // this gets the front of the deque
mWalkList.pop_front(); // this removes the front of the deque
mDirection = mDestination - mNode->getPosition();
mDistance = mDirection.normalise();
Vector3 src = mNode->getOrientation() * Vector3::UNIT_X;
if ((1.0f + src.dotProduct(mDirection)) < 0.0001f)
{
mNode->yaw(Degree(180));
}
else
{
Ogre::Quaternion quat = src.getRotationTo(mDirection);
mNode->rotate(quat);
} // else
return true;
} // nextLocation()
else
{
mNode->translate(mDirection * move);
} // else
} // if
mAnimationState->addTime(evt.timeSinceLastFrame);
return ExampleFrameListener::frameStarted(evt);
}
bool frameStarted(const FrameEvent &evt)
{
if (mDirection == Vector3::ZERO)
{
if (nextLocation())
{
// Set walking animation
mAnimationState = mEntity->getAnimationState("Walk");
mAnimationState->setLoop(true);
mAnimationState->setEnabled(true);
}
}
else
{
Real move = mWalkSpeed * evt.timeSinceLastFrame;
mDistance -= move;
if (mDistance <= 0.0f)
{
mNode->setPosition(mDestination);
mDirection = Vector3::ZERO;
// Set animation based on if the robot has another point to walk to.
if (! nextLocation())
{
// Set Idle animation
mAnimationState = mEntity-getAnimationState("Idle");
mAnimationState->setLoop(true);
mAnimationState->setEnabled(true);
}
else
{
// Rotation Code will go here later
}
}
else
{
mNode->translate(mDirection * move);
} // else
} // if
mAnimationState->addTime(evt.timeSinceLastFrame);
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)
{
// Set the default lighting.
mSceneMgr->setAmbientLight(ColourValue(1.0f, 1.0f, 1.0f));
// Create the entity
mEntity = mSceneMgr->createEntity("Robot", "robot.mesh");
// Create the scene node
mNode = mSceneMgr->getRootSceneNode()->
createChildSceneNode("RobotNode", Vector3(0.0f, 0.0f, 25.0f));
mNode->attachObject(mEntity);
// Create the walking list
mWalkList.push_back(Vector3(550.0f, 0.0f, 50.0f));
mWalkList.push_back(Vector3(-100.0f, 0.0f, -200.0f));
// Create objects so we can see movement
Entity *ent;
SceneNode *node;
ent = mSceneMgr->createEntity("Knot1", "knot.mesh");
node = mSceneMgr->getRootSceneNode()->createChildSceneNode("Knot1Node",
Vector3(0.0f, -10.0f, 25.0f));
node->attachObject(ent);
node->setScale(0.1f, 0.1f, 0.1f);
ent = mSceneMgr->createEntity("Knot2", "knot.mesh");
node = mSceneMgr->getRootSceneNode()->createChildSceneNode("Knot2Node",
Vector3(550.0f, -10.0f, 50.0f));
node->attachObject(ent);
node->setScale(0.1f, 0.1f, 0.1f);
ent = mSceneMgr->createEntity("Knot3", "knot.mesh");
node = mSceneMgr->getRootSceneNode()->createChildSceneNode("Knot3Node",
Vector3(-100.0f, -10.0f,-200.0f));
node->attachObject(ent);
node->setScale(0.1f, 0.1f, 0.1f);
// Set the camera to look at our handiwork
mCamera->setPosition(90.0f, 280.0f, 535.0f);
mCamera->pitch(Degree(-30.0f));
mCamera->yaw(Degree(-15.0f));
}
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
MessageBoxA(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;
1. Setelah itu, save dan build coding program di atas.
2. Output dari hasil coding animasi robot di atas adalah sebagai berikut :
}
Tidak ada komentar:
Posting Komentar