1 / 18

Ogre 3D Animation

Ogre 3D Animation. Agung Toto Wibowo http://gameprogramming.blog.ittelkom.ac.id/blog/ Materi tutorial diambil dari wiki Ogre : http://www.ogre3d.org/wiki/index.php/Ogre_Tutorials. Pendahuluan.

jania
Download Presentation

Ogre 3D Animation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Ogre 3D Animation Agung Toto Wibowo http://gameprogramming.blog.ittelkom.ac.id/blog/ Materi tutorial diambil dari wiki Ogre : http://www.ogre3d.org/wiki/index.php/Ogre_Tutorials

  2. Pendahuluan • Di pelajaranini, padadasarnya Ogre tidakmembuatalgoritmauntukanimasidengansendirinya. • Animasidibuatdari 3D modelling tools yang lain seperti 3ds max, blender dlsb. • Yang dilakukanhanyamentranslasidanmerotasikanentitas yang memilikianimasi.

  3. PersiapanAnimasi 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. */ boolnextLocation() { return true; } // nextLocation() boolframeStarted(const FrameEvent &evt) { return ExampleFrameListener::frameStarted(evt); } protected: Real mDistance; // sisajarak yang masihharusditempuh Vector3 mDirection, mDestination; // vektorarahdanlokasitujuan AnimationState*mAnimationState; // State animasidariobjek Entity *mEntity; // Entitas yang dianimasikan SceneNode *mNode; // SceneNodetempat Entity diletakkan std::deque<Vector3> mWalkList; // list lokasi yang akandilalui Real mWalkSpeed; // kecepatanentitasberjalan }; • BuataplikasidengannamaOgre “MoveDemoApplication” Extend ExampleFrameListener Jalurpergerakananimasi

  4. Persiapan Animasi class MoveDemoApplication : public ExampleApplication { protected: public: MoveDemoApplication() { } ~MoveDemoApplication() { } protected: Entity *mEntity; // entitasdariobjek yang akandianimasikan SceneNode *mNode; // SceneNodedari object yang bergerak std::deque<Vector3> mWalkList; // deque yang berisititikpergerakan void createScene(void) { } void createFrameListener(void) { mFrameListener= new MoveDemoListener(mWindow, mCamera, mNode, mEntity, mWalkList); mFrameListener->showDebugOverlay(true); mRoot->addFrameListener(mFrameListener); } };

  5. Skenario • Kita letakkanobjek yang akanbergerak. • Kita letakkanobjek lain sebagaiacuan agar terlihatbahwaobjektelahbergerak. • Kita set list point pergerakanobjek. • Kita amatidengankameraberadadilokasi ideal.

  6. MeletakkanObjek Buatpencahayaanenvirontmentmenjaditerang • TambahkankodeberikutpadaMoveDemoApplication::createScene() // 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);

  7. Menambahkan list pergerakan • TambahkankodeberikutpadaMoveDemoApplication::createScene() // Create the walking list mWalkList.push_back(Vector3(550.0f, 0.0f, 50.0f )); mWalkList.push_back(Vector3(-100.0f, 0.0f, -200.0f)); // bisakitatambahkanlagisesukakita, ataudarihasilalgoritma A*

  8. MenambahkanObjek lain (acuan) • TambahkankodeberikutpadaMoveDemoApplication::createScene() // 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);

  9. MeletakkanKamera • TambahkankodeberikutpadaTutorialApplication:: createCamera() // 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));

  10. Animasi • TambahkankodeberikutpadakontructorMoveDemoListener // Set idle animation mAnimationState= ent->getAnimationState("Idle"); mAnimationState->setLoop(true); mAnimationState->setEnabled(true); • Kompiledanjalankanaplikasi. // perlukita update animationstatedenganevt.timeSinceLastFrame // padaMoveDemoListener::frameStarted mAnimationState->addTime(evt.timeSinceLastFrame);

  11. Menggerakkan Robot • Kita gantikonstruktorpadaMoveDemoListenerdengan // Set default values for variables mWalkSpeed= 35.0f; // kecepatanpergerakan mDirection= Vector3::ZERO; // untuk status tidakbergerakkemanapun. • SedangpadaMoveDemoListener::frameStartedkitatambahkandengankodeberikut (sebelumAnimationState::addTime) : if (mDirection == Vector3::ZERO) { if (nextLocation()) { // Set walking animation mAnimationState = mEntity->getAnimationState("Walk"); mAnimationState->setLoop(true); mAnimationState->setEnabled(true); } }

  12. MengimplementasikannextLocation() • nextLocationberfungsiuntukmengecekapakahobjekmasihmemiliki point untuktujuanpergerakanatautidak. • TambahkankodeberikutpadanextLocation() if (mWalkList.empty()) return false; mDestination= mWalkList.front(); // mengambilnilaiterdepandeque mWalkList.pop_front(); // membuang front darideque mDirection= mDestination - mNode->getPosition(); mDistance= mDirection.normalise(); // mengubaharahwajah robot Vector3 src = mNode->getOrientation() * Vector3::UNIT_X; Ogre::Quaternion quat = src.getRotationTo(mDirection); mNode->rotate(quat);

  13. Kembalikemenggerakkan Robot • Robot yang adabelumberjalan, meskianimasisudahberubah. Untukmembuat robot berjalan, kitatambahkankodeberikutpadaMoveDemoListener::frameStarted(); 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); }

  14. Kembalikemenggerakkan Robot • Lanjutan else { // Rotation Code will go here later } } else { mNode->translate(mDirection * move); } // else } // if if (mWalkList.empty()) return false;

  15. Blender dan Ogre 3D Agung Toto Wibowo http://gameprogramming.blog.ittelkom.ac.id/blog/ Materi tutorial diambil dari wiki Ogre : http://www.ogre3d.org/wiki/index.php/Ogre_Tutorials

  16. Blender dan Ogre • Objek yang dibuatdi blender dapatdiloadke Ogre. • Format pada ogre *.mesh, blender *.blend • Butuhkonversi (meshes exporter) http://www.ogre3d.org/wiki/index.php/Blender_Exporter • Download danintegrasikan Blender Exporter. • Copy ogremeshesexporter.py dan subfolders kelokasi ...\blender\.blender\scripts. • Install Python 2.5.4 (ataulebihtinggi) yang dibutuhkanoleh exporter.

  17. Blender Meshes Exporter

  18. Melihathasilkonversi • Aplikasiceguimeshviewer • Informasilebihlanjutpada link : http://www.ogre3d.org/forums/viewtopic.php?p=136714 • Mengintegrasikanlangsungkekode Ogre dengankode.

More Related