BasicTutorial2Source
Basic Tutorial 2 - source
Welcome to the new Ogre Wiki!
If you haven't done so already, be sure to visit the Wiki Portal to read about how the wiki works. Especially the Ogre Wiki Overview page.
If you haven't done so already, be sure to visit the Wiki Portal to read about how the wiki works. Especially the Ogre Wiki Overview page.
This is the full source code for Basic Tutorial 2.
Table of contents
BasicTutorial2.h
BasicTutorial.h
/* ----------------------------------------------------------------------------- Filename: BasicTutorial2.h ----------------------------------------------------------------------------- This source file is part of the ___ __ __ _ _ _ /___\__ _ _ __ ___ / / /\ \ (_) | _(_) // // _` | '__/ _ \ \ \/ \/ / | |/ / | / \_// (_| | | | __/ \ /\ /| | <| | \___/ \__, |_| \___| \/ \/ |_|_|\_\_| |___/ Tutorial Framework http://www.ogre3d.org/tikiwiki/ ----------------------------------------------------------------------------- */ #ifndef __BasicTutorial2_h_ #define __BasicTutorial2_h_ #include "BaseApplication.h" class BasicTutorial2 : public BaseApplication { public: BasicTutorial2(void); virtual ~BasicTutorial2(void); protected: virtual void createScene(void); virtual void createCamera(void); virtual void createViewports(void); }; #endif // #ifndef __BasicTutorial2_h_
BasicTutorial2.cpp
BasicTutorial2.cpp
/* ----------------------------------------------------------------------------- Filename: BasicTutorial2.cpp ----------------------------------------------------------------------------- This source file is part of the ___ __ __ _ _ _ /___\__ _ _ __ ___ / / /\ \ (_) | _(_) // // _` | '__/ _ \ \ \/ \/ / | |/ / | / \_// (_| | | | __/ \ /\ /| | <| | \___/ \__, |_| \___| \/ \/ |_|_|\_\_| |___/ Tutorial Framework http://www.ogre3d.org/tikiwiki/ ----------------------------------------------------------------------------- */ #include "BasicTutorial2.h" //------------------------------------------------------------------------------------- BasicTutorial2::BasicTutorial2(void) { } //------------------------------------------------------------------------------------- BasicTutorial2::~BasicTutorial2(void) { } //------------------------------------------------------------------------------------- void BasicTutorial2::createCamera(void) { // create the camera mCamera = mSceneMgr->createCamera("PlayerCam"); // set its position, direction mCamera->setPosition(Ogre::Vector3(0,10,500)); mCamera->lookAt(Ogre::Vector3(0,0,0)); // set the near clip distance mCamera->setNearClipDistance(5); mCameraMan = new OgreBites::SdkCameraMan(mCamera); // create a default camera controller } //------------------------------------------------------------------------------------- void BasicTutorial2::createViewports(void) { // Create one viewport, entire window Ogre::Viewport* vp = mWindow->addViewport(mCamera); vp->setBackgroundColour(Ogre::ColourValue(0,0,0)); // Alter the camera aspect ratio to match the viewport mCamera->setAspectRatio(Ogre::Real(vp->getActualWidth()) / Ogre::Real(vp->getActualHeight())); } //------------------------------------------------------------------------------------- void BasicTutorial2::createScene(void) { mSceneMgr->setAmbientLight(Ogre::ColourValue(0, 0, 0)); mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE); Ogre::Entity* entNinja = mSceneMgr->createEntity("Ninja", "ninja.mesh"); entNinja->setCastShadows(true); mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(entNinja); Ogre::Plane plane(Ogre::Vector3::UNIT_Y, 0); Ogre::MeshManager::getSingleton().createPlane("ground", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, 1500, 1500, 20, 20, true, 1, 5, 5, Ogre::Vector3::UNIT_Z); Ogre::Entity* entGround = mSceneMgr->createEntity("GroundEntity", "ground"); mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(entGround); entGround->setMaterialName("Examples/Rockwall"); entGround->setCastShadows(false); Ogre::Light* pointLight = mSceneMgr->createLight("pointLight"); pointLight->setType(Ogre::Light::LT_POINT); pointLight->setPosition(Ogre::Vector3(0, 150, 250)); pointLight->setDiffuseColour(1.0, 0.0, 0.0); pointLight->setSpecularColour(1.0, 0.0, 0.0); Ogre::Light* directionalLight = mSceneMgr->createLight("directionalLight"); directionalLight->setType(Ogre::Light::LT_DIRECTIONAL); directionalLight->setDiffuseColour(Ogre::ColourValue(.25, .25, 0)); directionalLight->setSpecularColour(Ogre::ColourValue(.25, .25, 0)); directionalLight->setDirection(Ogre::Vector3( 0, -1, 1 )); Ogre::Light* spotLight = mSceneMgr->createLight("spotLight"); spotLight->setType(Ogre::Light::LT_SPOTLIGHT); spotLight->setDiffuseColour(0, 0, 1.0); spotLight->setSpecularColour(0, 0, 1.0); spotLight->setDirection(-1, -1, 0); spotLight->setPosition(Ogre::Vector3(300, 300, 0)); spotLight->setSpotlightRange(Ogre::Degree(35), Ogre::Degree(50)); } #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 #define WIN32_LEAN_AND_MEAN #include "windows.h" #endif #ifdef __cplusplus extern "C" { #endif #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT ) #else int main(int argc, char *argv[]) #endif { // Create application object BasicTutorial2 app; try { app.go(); } catch( Ogre::Exception& e ) { #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL); #else std::cerr << "An exception has occured: " << e.getFullDescription().c_str() << std::endl; #endif } return 0; } #ifdef __cplusplus } #endif
Contributors to this page: jacmoe
,
peters
and
OgreWikiBot
.
Page last modified on Monday 21 of June, 2010 00:24:00 GMT by jacmoe
.
The content on this page is licensed under the terms of the Creative Commons Attribution-ShareAlike License.
As an exception, any source code contributed within the content is released into the Public Domain.
Sidebar
Search box
Online users
49
online users

