Tuesday, January 22, 2013

Listing Ogre3d membuat Skybox dan Particle

#include "ExampleApplication.h"

class TutorialApplication : public ExampleApplication
{
protected:
public:
    TutorialApplication()
    {
    }

    ~TutorialApplication()
    {
    }
protected:
    virtual void createCamera(void)
    {
      //membuat kamera
      mCamera = mSceneMgr->createCamera("PlayerCam");
      //posisi dan arah kamera
      mCamera->setPosition(Vector3(0,300,900));
      mCamera->lookAt(Vector3(0,0,0));
      //mengatur jarak kliping terdekat
      mCamera->setNearClipDistance(10);
    }

    virtual void createViewports(void)
    {
      //membuat satu viewport untuk seluruh window
      Viewport* vp = mWindow->addViewport(mCamera);
      //mengatur warna background viewport
      vp->setBackgroundColour(ColourValue(1.0,1.0,1.0));
      //mengatur rasio kamera
      mCamera->setAspectRatio(Real (vp->getActualWidth()) / Real (vp->getActualHeight()));

    }

void createScene(void)
    {
       Entity *ent;
       Entity *ent1;
       Entity *ent2;
       Entity *ent3;
       Entity *ent4;
       Entity *ent5;

      mSceneMgr->setAmbientLight(ColourValue(1,1,1));
      mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_ADDITIVE);

      ent = mSceneMgr->createEntity("Ninja", "ninja.mesh");
      ent->setCastShadows(true);
      SceneNode *node = mSceneMgr->getRootSceneNode()->createChildSceneNode ("Ninja", Vector3(250,0,0));
      node->attachObject( ent );
      node->yaw(Degree(-90));
      node->scale(0.5,0.5,0.5);

      ent1 = mSceneMgr->createEntity("Ninja2", "ninja.mesh");
      ent1->setCastShadows(true);
      SceneNode *node1 = mSceneMgr->getRootSceneNode()->createChildSceneNode ("Ninja2", Vector3(300,0,0));
      node1->attachObject( ent1 );
      node1->yaw(Degree(90));
      node1->scale(0.5,0.5,0.5);

      ent2 = mSceneMgr->createEntity("Rumah", "tudorhouse.mesh");
      ent2->setCastShadows(true);
      SceneNode *node2 = mSceneMgr->getRootSceneNode()->createChildSceneNode ("Rumah", Vector3(-450,280,-500));
      node2->attachObject( ent2 );
      node2->scale(0.5,0.5,0.5);

      ent3 = mSceneMgr->createEntity("Robot", "robot.mesh");
      ent3->setCastShadows(true);
      SceneNode *node3 = mSceneMgr->getRootSceneNode()->createChildSceneNode ("Robot", Vector3(-300,0,0));
      node3->attachObject( ent3 );
      node3->yaw(Degree(-90));
      node3->scale(1,1,1);

      ent4 = mSceneMgr->createEntity("Rumah1", "tudorhouse.mesh");
      ent4->setCastShadows(true);
      SceneNode *node4 = mSceneMgr->getRootSceneNode()->createChildSceneNode ("Rumah1", Vector3(-50,280,-500));
      node4->attachObject( ent4 );
      node4->scale(0.5,0.5,0.5);

      ent5 = mSceneMgr->createEntity("Rumah2", "tudorhouse.mesh");
      ent5->setCastShadows(true);
            SceneNode *node5 = mSceneMgr->getRootSceneNode()->createChildSceneNode ("Rumah2", Vector3(350,280,-500));
      node5->attachObject( ent5 );
      node5->scale(0.5,0.5,0.5);

      Plane plane(Vector3::UNIT_Y, 0);
          MeshManager::getSingleton().createPlane("ground1",ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,1500,1500,20,20,true,1,5,5,Vector3::UNIT_Z);
      //menciptakan objek tanah
            ent = mSceneMgr->createEntity("GroundEntity1", "ground1");
            mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
            ent->setMaterialName("Examples/GrassFloor");
            ent->setCastShadows(false);

      mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox", 5000, false);

      ParticleSystem* smokeParticle = mSceneMgr->createParticleSystem("Smoke", "Examples/Smoke");
      SceneNode* particleNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("Particle");
      particleNode->attachObject(smokeParticle);
      particleNode->setPosition(Vector3(370,0,-300));
      particleNode->scale(1000,1000,1000);

      ParticleSystem* AureolaParticle = mSceneMgr->createParticleSystem("Aureola", "Examples/Aureola");
      SceneNode* particle1Node = mSceneMgr->getRootSceneNode()->createChildSceneNode("Particle1");
            particle1Node->attachObject(AureolaParticle);
            particle1Node->setPosition(Vector3(-300,0,0));
          }
      };

      #if OGRE_PLATFORM == PLATFORM_WIN32 || 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
      {
          TutorialApplication app;

          try {
              app.go();
          } catch( Exception& e ) {
      #if OGRE_PLATFORM == PLATFORM_WIN32 || 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;
}

tampilan output :

No comments:

Post a Comment