1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
// Fichier TutorialApplication.cpp
#include "TutorialApplication.h"
TutorialApplication::TutorialApplication(void)
{
}
TutorialApplication::~TutorialApplication(void)
{
}
void TutorialApplication::createScene(void)
{
mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE);
// Creation du fond Ciel
mSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, 8);
// Creation et parametrage d'une sphere
createSphere("mySphereMesh", 5, 64, 64);
Entity* sphereEntity = mSceneMgr->createEntity("mySphereEntity", "mySphereMesh");
SceneNode* sphereNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
sphereEntity->setMaterialName("material_name_goes_here");
sphereNode->attachObject(sphereEntity);
// Creation et parametrage d'une sphere
createSphere("mySphereMesh2", 20, 21, 53);
Entity* sphereEntity2 = mSceneMgr->createEntity("mySphereEntity2", "mySphereMesh2");
SceneNode* sphereNode2 = mSceneMgr->getRootSceneNode()->createChildSceneNode();
sphereEntity2->setMaterialName("material_name_goes_here");
sphereNode2->attachObject(sphereEntity2);
sphereNode2->translate(50.0, 50.0, 50.0);
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);
// Gestion lumiere et ombre
mSceneMgr->setAmbientLight(Ogre::ColourValue(0, 0, 0));
Ogre::Light* directionalLight = mSceneMgr->createLight("SunLight");
directionalLight->setType(Ogre::Light::LT_DIRECTIONAL);
// directionalLight->setDiffuseColour(Ogre::ColourValue(0, 0, 0));
// directionalLight->setSpecularColour(Ogre::ColourValue(0, 0, 0));
directionalLight->setDirection(Ogre::Vector3(0, -1, 1));
}
void TutorialApplication::createSphere(const std::string& strName, const float r, const int nRings = 16, const int nSegments = 16)
{
ManualObject * manual = mSceneMgr->createManualObject(strName);
manual->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_LIST);
float fDeltaRingAngle = (Math::PI / nRings);
float fDeltaSegAngle = (2 * Math::PI / nSegments);
unsigned short wVerticeIndex = 0;
for (int ring = 0; ring <= nRings; ring++) {
float r0 = r * sinf (ring * fDeltaRingAngle);
float y0 = r * cosf (ring * fDeltaRingAngle);
for (int seg = 0; seg <= nSegments; seg++) {
float x0 = r0 * sinf(seg * fDeltaSegAngle);
float z0 = r0 * cosf(seg * fDeltaSegAngle);
manual->position( x0, y0, z0);
manual->normal(Vector3(x0, y0, z0).normalisedCopy());
manual->textureCoord((float) seg / (float) nSegments, (float) ring / (float) nRings);
if (ring != nRings) {
manual->index(wVerticeIndex + nSegments + 1);
manual->index(wVerticeIndex);
manual->index(wVerticeIndex + nSegments);
manual->index(wVerticeIndex + nSegments + 1);
manual->index(wVerticeIndex + 1);
manual->index(wVerticeIndex);
wVerticeIndex ++;
}
};
}
manual->colour(ColourValue(0, 0, 0));
manual->end();
MeshPtr mesh = manual->convertToMesh(strName);
mesh->_setBounds( AxisAlignedBox( Vector3(-r, -r, -r), Vector3(r, r, r) ), false );
mesh->_setBoundingSphereRadius(r);
unsigned short src, dest;
if (!mesh->suggestTangentVectorBuildParams(VES_TANGENT, src, dest))
mesh->buildTangentVectors(VES_TANGENT, src, dest);
}
int main(int argc, char *argv[]){
TutorialApplication app;
try {
app.go();
} catch( Ogre::Exception& e ) {
std::cerr << "An exception has occured: " <<
e.getFullDescription().c_str() << std::endl;
}
} |
Partager