Q4: Build a simple solar system out of textured spheres.
First, to make it easier, we can use the ProceduralSphereGenerator.h file to easily create a bunch of spheres.
#include "ProceduralSphereGenerator.h"
I got 24 errors after I include this thing... The way to solve it go to project properties and add these items:
Linker -> General -> Additional Library Directories:
$(TwoLoc_PATH)\lib\VS2008\$(ConfigurationName)\$(PlatformName)\OgreProcedural\
Linker -> Input -> Additional Dependencies:
OgreProcedural_$(ConfigurationName).lib
But...
This is for Visual Studio 2008!
Before we start, we need to know:
1) Ogre::SceneNode
2) Ogre::Entity
SceneNode is use for translating/rotating the object. Its basically the coordinates of an object.
Entity is the actual object, It can be a mesh, a fbx file, etc. we can only set the texture/material for an entity not the node.
First thing we need for this solar system is the sun. The sun is also the root node of the scene, it doesn't do anything(it's not spinning and no orbit). It's just a simple sphere, so we only need to create a sphere and attach the entity to the node.
//Declare the variables for the sun
Ogre::SceneNode *mRootNode;
Ogre::Entity *sun;
Since the sun is the root of this solar system and it does not spin and no orbit, we just make it the root node for the scene.
mRootNode = mMgr->getRootSceneNode();
Other than the sun, we have the earth spinning and rotating around the sun. For these kind of planet, we need to declare 3 scene nodes for each of them.
mEarthOrbitNode = mMgr->getRootSceneNode()->createChildSceneNode();
mEarthTranslateNode = mEarthOrbitNode->createChildSceneNode(Ogre::Vector3(5, 0, 0));
mEarthRotateNode = mEarthTranslateNode->createChildSceneNode();
mEarthOrbitNode represents the point it rotates around, mEarthTranslateNode represents it’s actual position while rotating around the root(the sun), mEarthRotateNode represents the point that the earth spins around/its local axis, and they are all attached in order.
Procedural::SphereGenerator().setRadius(1).realizeMesh(“earth”);
Ogre::Entity* earth= mMgr->createEntity(“earth”);
earth->getSubEntity(0)->setMaterial(Ogre::MaterialManager::getSingleton().getByName(“earthMat”));
mEarthRotateNode->attachObject(earth);
And then, we create entity called earth for the scene and set material for this entity. Finally attach it to the rotation node.
After creating the mesh, we still need to make it move and rotate as well. We can simply do this in the update function. First, declare variables control how the planet spin and its orbit. Then, use the setOrientation function to move the mesh.
mEarthSpin += 360.0f*dt * 5.0f; // every second is 5 days
mEarthOrbit = mEarthSpin/365.25f;
mEarthOrbitNode->setOrientation(Quaternion(Radian(Degree(mEarthOrbit)), Vector3::UNIT_Y));
mEarthRotateNode->setOrientation(Quaternion(Radian(Degree(mEarthSpin)), Vector3::UNIT_Y));
Then, we copy and paste a bunch of codes to get this:
Since the sun is the root of this solar system and it does not spin and no orbit, we just make it the root node for the scene.
mRootNode = mMgr->getRootSceneNode();
Other than the sun, we have the earth spinning and rotating around the sun. For these kind of planet, we need to declare 3 scene nodes for each of them.
mEarthOrbitNode = mMgr->getRootSceneNode()->createChildSceneNode();
mEarthTranslateNode = mEarthOrbitNode->createChildSceneNode(Ogre::Vector3(5, 0, 0));
mEarthRotateNode = mEarthTranslateNode->createChildSceneNode();
mEarthOrbitNode represents the point it rotates around, mEarthTranslateNode represents it’s actual position while rotating around the root(the sun), mEarthRotateNode represents the point that the earth spins around/its local axis, and they are all attached in order.
Procedural::SphereGenerator().setRadius(1).realizeMesh(“earth”);
Ogre::Entity* earth= mMgr->createEntity(“earth”);
earth->getSubEntity(0)->setMaterial(Ogre::MaterialManager::getSingleton().getByName(“earthMat”));
mEarthRotateNode->attachObject(earth);
And then, we create entity called earth for the scene and set material for this entity. Finally attach it to the rotation node.
After creating the mesh, we still need to make it move and rotate as well. We can simply do this in the update function. First, declare variables control how the planet spin and its orbit. Then, use the setOrientation function to move the mesh.
mEarthSpin += 360.0f*dt * 5.0f; // every second is 5 days
mEarthOrbit = mEarthSpin/365.25f;
mEarthOrbitNode->setOrientation(Quaternion(Radian(Degree(mEarthOrbit)), Vector3::UNIT_Y));
mEarthRotateNode->setOrientation(Quaternion(Radian(Degree(mEarthSpin)), Vector3::UNIT_Y));
Then, we copy and paste a bunch of codes to get this:

No comments:
Post a Comment