Chat Box

User Yang Sedang Online
Total 1 user online :: 0 Terdaftar, 0 Tersembunyi dan 1 Tamu

Tidak ada

[ View the whole list ]


User online terbanyak adalah 24 pada Mon Oct 04, 2010 10:03 am
Total Pengunjung
Website counter
Visitor

Pertemuan ke 3 praktikum Grafik Komputer 2 (Ogre)

Topik sebelumnya Topik selanjutnya Go down

default Pertemuan ke 3 praktikum Grafik Komputer 2 (Ogre)

Post by risdo on Sat Mar 31, 2012 3:56 am

Ini gw cantumin coding yang bs dibuat untuk referensi kalian.

Code:


/*
 * Translasi.cpp

 */

#include "ExampleApplication.h"

class Translater:public ExampleApplication{
public:
   Translater(){};
   ~Translater(){};

protected:
   virtual void createCamera(){
      //bikin camera, bernama Kamera, camrea adl tools utk memandang scene yg akan kt buat
      mCamera = mSceneMgr->createCamera("Kamera");

      //set posisi dan arah penyorotan kamere
      mCamera->setPosition(Vector3(0,10,500));
      //Points the camera at a location in worldspace
      mCamera->lookAt(Vector3(0,0,0));
      //set posisi dari area yg dikliping
      mCamera->setNearClipDistance(5);
   }

   virtual void createViewport(){
      //bikin viewport
      Viewport *vp = mWindow->addViewport(mCamera);
      //set viewport background dg par ColourValue
      vp->setBackgroundColour(ColourValue(0,0,0));
      //tetpin aspek rasio, agar camrea cocok dg viewport
      mCamera->setAspectRatio((Real(vp->getActualWidth()))/(Real(vp->getActualHeight())));

   }
   void createScene(){
      //mSceneMgr utk manage semua semua yg tampil pd screen
      mSceneMgr->setAmbientLight(ColourValue(1,1,1));
      //Entity ad objek yg bs dirender discene
      Entity *ent1 = mSceneMgr->createEntity("obj","barrel.mesh");
      Entity *nin1 = mSceneMgr->createEntity("ninja1","ninja.mesh");
      Entity *nin2 = mSceneMgr->createEntity("ninja2","ninja.mesh");
      Entity *nin3 = mSceneMgr->createEntity("ninja3","ninja.mesh");
      Entity *nin4 = mSceneMgr->createEntity("ninja4","ninja.mesh");

      //SceneNodes keep track of location and orientation for all of the objects attached to it.
      SceneNode *nor1 = mSceneMgr->getRootSceneNode()->createChildSceneNode("node1",Vector3(-50,0,0));
      SceneNode *nor2 = mSceneMgr->getRootSceneNode()->createChildSceneNode("node2",Vector3(0,0,50));
      SceneNode *nor3 = mSceneMgr->getRootSceneNode()->createChildSceneNode("node3",Vector3(50,0,0));
      SceneNode *nor4 = mSceneMgr->getRootSceneNode()->createChildSceneNode("node4",Vector3(0,0,-50));

      nor1->attachObject(nin1);
      nor2->attachObject(nin2);
      nor3->attachObject(nin3);
      nor4->attachObject(nin4);

      SceneNode *node1 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node",Vector3(0,40,0));
      SceneNode *node2 = mSceneMgr->getRootSceneNode()->createChildSceneNode("n2",Vector3(50,30,0));
      node1->attachObject(ent1);
      node1->scale(5,15,5);

      nor1->yaw(Degree(-90));
      nor3->yaw(Degree(90));
      nor4->yaw(Degree(180));

      Plane plane(Vector3::UNIT_Y,0);
      MeshManager::getSingleton().createPlane("ground",ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,plane,
                        1500,1500,20,20,true,1,5,5,Vector3::UNIT_Z);//plane selebar w=1500 h=1500

      Entity *lantai = mSceneMgr->createEntity("GroundEntity","ground");
      mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(lantai);

      lantai->setMaterialName("Examples/DarkMaterial");
      lantai->setCastShadows(false);

      //biar ga gelap dikasi lampu
      Light *light;
      light = mSceneMgr->createLight("Light1");

      //LT_POINT = Titik sumber cahaya memancarkan cahaya dari mereka di setiap arah.
      light->setType(Light::LT_POINT);
      light->setPosition(Vector3(0,150,250));//lampu dari depan atas

      //set warna diffuse n spekular
      light->setDiffuseColour(0.0,1.0,0.0);
      light->setSpecularColour(0.0,1.0,0.0);

      //directional light
      light = mSceneMgr->createLight("Light3");

      light->setType(Light::LT_DIRECTIONAL);
      light->setDiffuseColour(ColourValue(.2,.25,.5));
      light->setSpecularColour(ColourValue(.2,.25,.5));

      //We'll set the direction of the light to be in the positive z and negative y direction
      //(like it is coming from 45 degrees in front and above the ninja):
      light->setDirection(Vector3(0,-1,1));
      // Let's add a small amount of yellow directional light that is shining towards the front of his body
      light = mSceneMgr->createLight("Light2");

      light->setType(Light::LT_SPOTLIGHT);
      light->setDiffuseColour(0.8,0.5,0);
      light->setSpecularColour(0.8,0.5,0);

      light->setDirection(-1,-1,0);
      light->setPosition(Vector3(300,300,0));
      mSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, 8);
   }
};
#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
{
   //bikin objek aplikasi
   Translater app;
   try {
      app.go();
   } catch (Exception e) {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
      MessageBox(NULL,e.what(),"Terjadi Error!",MB_OK | MB_ICONERROR |MB_TASKMODAL);
#else
      fprintf(stderr,"Terjadi Error = %s\n",e.what());
#endif
   }
}

avatar
risdo
Admin
Admin

Posts : 209
Reputasi : 377
Cendol : 1
Join date : 26.10.09
Location : Bekasi

Lihat profil user http://c0b4d1b4c4.indonesianforum.net

Kembali Ke Atas Go down

Topik sebelumnya Topik selanjutnya Kembali Ke Atas


 
Permissions in this forum:
Anda tidak dapat menjawab topik