Skip to content

Commit

Permalink
getAstroChild and attachAstroParent created
Browse files Browse the repository at this point in the history
getAstroChild returns a pointer to the astronomical object, with the
specified name, attached to the current planet
attachAstroParent put a planet in the list of the parent astronomical
objects
  • Loading branch information
giogix2 committed Aug 27, 2016
1 parent 3ee096b commit e7d4d21
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions GeneratorFrameListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ bool GeneratorFrameListener::frameStarted(const Ogre::FrameEvent& evt)
//pSphere->getObserverDistanceToSurface();
pSphere->moveAstroChild("CustomMesh2", 0.0f, 0.03f, 0.03f);


return true;
}

Expand Down
18 changes: 18 additions & 0 deletions PSphere.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,18 @@ void PSphere::generateMeshData()
fixTextureSeam();
}

PSphere* PSphere::getAstroChild(const std::string &objectName)
{
for (vector<PSphere*>::iterator it = astroObjectsChild.begin() ; it != astroObjectsChild.end(); ++it)
{
if ((*it)->getMeshName().compare(objectName) == 0)
{
return (*it);
}
}
return NULL;
}

void PSphere::loadToBuffers(const std::string &meshName, const std::string &textureName)
{
this->meshName = meshName;
Expand Down Expand Up @@ -783,10 +795,16 @@ void PSphere::attachMeshOnGround(Ogre::SceneNode *node, Ogre::SceneManager *scen
objects.push_back(object);
}

void PSphere::attachAstroParent(PSphere *object)
{
astroObjectsParent.push_back(object);
}

void PSphere::attachAstroChild(PSphere *object, Ogre::Real x, Ogre::Real y, Ogre::Real z)
{
string objectMeshName = object->getMeshName();
astroObjectsChild.push_back(object);
object->attachAstroParent(this);
Ogre::Entity* entity = object->getEntity();

string secNodeName = "sec_node_";
Expand Down
4 changes: 4 additions & 0 deletions PSphere.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class PSphere
*Maybe later we need object in air or outer space, so I leave attachmesh() and create this function which could put the object on ground. */
void attachMeshOnGround(Ogre::SceneNode *node, Ogre::SceneManager *scene, const std::string &meshName, const std::string &objectName, Ogre::Real latitude, Ogre::Real longitude);

void attachAstroParent(PSphere *object);

/* Attach another astrological object (star, planet, satellite, etc.) to this one.
The astrological object attached will be connected to this one with a childNode
Two node are put between the actual planet and the astrological object*/
Expand Down Expand Up @@ -100,6 +102,8 @@ class PSphere

string getMeshName();

PSphere* getAstroChild(const std::string &objectName);

string getTextureName();

/* Figures which one of the cubefaces 3D-location lands, and what 2D-coordinates
Expand Down
14 changes: 14 additions & 0 deletions initOgre.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,24 +207,38 @@ void initOgre::setSceneAndRun(PSphere *planet){
std::string frequencyAmplitude = "1.0 0.02 0.3 0.008 0.1 0.005 0.06666 0.006666";
std::vector < std::pair < std::string, int > > meshlocs;
std::ResourceParameter *params2;
std::ResourceParameter *params3;
params2 = new std::ResourceParameter((std::string)"#00FF00",(std::string)"#FACD00",(std::string)"#32CDFF"
,(std::string)"#64FFFF",(std::string)"#B4B4B4",(std::string)"#FFFFFF",waterfraction,radius,seed,frequencyAmplitude, meshlocs);
params3 = new std::ResourceParameter((std::string)"#00FF00",(std::string)"#FACD00",(std::string)"#c88500"
,(std::string)"#d6c502",(std::string)"#874300",(std::string)"#FFFFFF",0.4, 4.5,70,frequencyAmplitude, meshlocs);

PSphere *mySphere2;
PSphere *mySphere3;
mySphere2 = new PSphere(100, 40, 1024, 512, *params2);
mySphere3 = new PSphere(100, 40, 1024, 512, *params3);
mySphere2->loadToBuffers("CustomMesh2", "sphereTex2");
mySphere3->loadToBuffers("CustomMesh3", "sphereTex3");

Ogre::Entity *entity2 = Scene->createEntity("CustomEntity2", "CustomMesh2");
Ogre::Entity *entity3 = Scene->createEntity("CustomEntity3", "CustomMesh3");
mySphere2->setEntity(entity2);
mySphere3->setEntity(entity3);

Ogre::MaterialPtr textureMap2 = Ogre::MaterialManager::getSingleton()
.create("TextureObject",Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
Ogre::MaterialPtr textureMap3 = Ogre::MaterialManager::getSingleton()
.create("TextureObject",Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
textureMap2->getTechnique(0)->getPass(0)->createTextureUnitState("sphereTex2");
textureMap3->getTechnique(0)->getPass(0)->createTextureUnitState("sphereTex3");
textureMap2->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
textureMap3->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
// Set texture for the sphere
entity2->setMaterial(textureMap2);
entity3->setMaterial(textureMap3);

planet->attachAstroChild(mySphere2, 40.0f, 0.0f, 0.0f);
mySphere2->attachAstroChild(mySphere3, 20.0f, 0.0f, 0.0f);

/*planet->attachMeshOnGround(sphere1, Scene, "ram.mesh", "Ramiro", 0.0, 270.0);*/
// planet->attachMesh(sphere1, Scene, "asteroid.mesh", "CK7", 0.0, 180.0);
Expand Down

0 comments on commit e7d4d21

Please sign in to comment.