OGRE Wiki
Support and community documentation for Ogre3D
Ogre Forums
ogre3d.org
Log in
Username:
Password:
CapsLock is on.
Remember me (for 1 year)
Log in
Home
Tutorials
Tutorials Home
Basic Tutorials
Intermediate Tutorials
Mad Marx Tutorials
In Depth Tutorials
Older Tutorials
External Tutorials
Cookbook
Cookbook Home
CodeBank
Snippets
Experiences
Ogre Articles
Libraries
Libraries Home
Alternative Languages
Assembling A Toolset
Development Tools
OGRE Libraries
List of Libraries
Tools
Tools Home
DCC Tools
DCC Tutorials
DCC Articles
DCC Resources
Assembling a production pipeline
Development
Development Home
Roadmap
Building Ogre
Installing the Ogre SDK
Setting Up An Application
Ogre Wiki Tutorial Framework
Frequently Asked Questions
Google Summer Of Code
Help Requested
Ogre Core Articles
Community
Community Home
Projects Using Ogre
Recommended Reading
Contractors
Wiki
Immediate Wiki Tasklist
Wiki Ideas
Wiki Guidelines
Article Writing Guidelines
Wiki Styles
Wiki Page Tracker
Ogre Wiki Help
Ogre Wiki Help Overview
Help - Basic Syntax
Help - Images
Help - Pages and Structures
Help - Wiki Plugins
Toolbox
Freetags
Categories
List Pages
Structures
Trackers
Statistics
Rankings
List Galleries
Ogre Lexicon
Comments
History: Tutorial 10
View page
Source of version: 4
(current)
!!Splish Splash I was taking a bath Figured I would add one last thing into this tutorial set. Go to the bottom of the TutorialApplication::createScene method. Now add the following code: {CODE(wrap="1", colors="c++")}// Water Entity *pWaterEntity; Plane nWaterPlane; // create a water plane/scene node nWaterPlane.normal = Vector3::UNIT_Y; nWaterPlane.d = -1.5; MeshManager::getSingleton().createPlane( "WaterPlane", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, nWaterPlane, 8000, 8000, 20, 20, true, 1, 10, 10, Vector3::UNIT_Z);{CODE} To simulate water, we want to create a flat plane with a texture. Here we make a plane that is 8000 units by 8000 units. Each side of the plane has 20 control points. Now we have to add the water to the scene. We do that like this: {CODE(wrap="1", colors="c++")}pWaterEntity = mSceneMgr->createEntity("water", "WaterPlane"); pWaterEntity->setMaterialName("Examples/TextureEffect4"); SceneNode *waterNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("WaterNode"); waterNode->attachObject(pWaterEntity); waterNode->translate(4000, 50, 4000);{CODE} The material -+Examples/TextureEffect4+- requires a light before you can see it. So we have to add a light as well. {CODE(wrap="1", colors="c++")}// Create a light Light* pLight = mSceneMgr->createLight("MainLight"); pLight->setType( Light::LT_DIRECTIONAL ); pLight->setDirection( 0, -100, 0 );{CODE} So we create a light and projects parallel rays of light in the downward direction. Now go to the -+TutorialFrameListner.cpp+- and add the following two lines before the constructor. {CODE(wrap="1", colors="c++")}#define FLOW_SPEED 0.4 #define FLOW_HEIGHT 10{CODE} Last bit of code. YEH! Go to the bottom of the -+TutorialFrameListener::frameStarted()+- method. Enter the following code before the return true. {CODE(wrap="1", colors="c++")}float fWaterFlow = FLOW_SPEED * evt.timeSinceLastFrame; static float fFlowAmount = 0.0f; static bool fFlowUp = true; SceneNode *pWaterNode = static_cast<SceneNode*>( mCamera->getSceneManager()->getRootSceneNode()->getChild("WaterNode")); if(pWaterNode) { if(fFlowUp) fFlowAmount += fWaterFlow; else fFlowAmount -= fWaterFlow; if(fFlowAmount >= FLOW_HEIGHT) fFlowUp = false; else if(fFlowAmount <= 0.0f) fFlowUp = true; pWaterNode->translate(0, (fFlowUp ? fWaterFlow : -fWaterFlow), 0); }{CODE} Some explanation is required here. Basically what this code does is gently moves the water up and down. Giving the illusion of a tide, or swell. The other bit of interesting code, is how we get the Water SceneNode. Instead of passing the node in, you can query the scene manager for the node with a specific name. In this case ‘WaterNode’. I would not suggest doing it this way. If you had passed the SceneNode in, then you don’t have to run the query each frame, thus speeding up the frames. So Compile and Run the code, you should see a screen something like: {img fileId="1633" thumb="y" alt="xorekis10_1.png" rel="box[g]"} This completes this pack of tutorials. I have lots in mind I still want to cover. Anyway, play with what we have created. If you do something interesting, I would be interested in adding it to the tutorials. Until next tutorial.... (:wink:) '__Xorekis'__
Search by Tags
Search Wiki by Freetags
Latest Changes
Minimal Ogre Collision
Artifex Terra
OpenMB
Advanced Mogre Framework
MogreSocks
Critter AI
Mogre Add-ons
MOGRE
Mogre MyGUI wrapper
MOGRE Editable Terrain Manager
...more
Search
Find
Advanced
Search Help
Online Users
53 online users