//------------------------------------------------------------------------------------- void BasicTutorial2::createScene(void) { mSceneMgr->setAmbientLight(Ogre::ColourValue(0, 0, 0)); //mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE); //Create cube //Create a basic green color texture Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().create("BoxColor", "General", true ); Ogre::Technique* tech = mat->getTechnique(0); Ogre::Pass* pass = tech->getPass(0); Ogre::TextureUnitState* tex = pass->createTextureUnitState(); tex->setTextureName("grassTexture.png"); //tex->setNumMipmaps(4); tex->setTextureAnisotropy(1); tex->setTextureFiltering(Ogre::FO_POINT, Ogre::FO_POINT, Ogre::FO_POINT); //Create the one box and the supporting class objects Ogre::ManualObject* testBox = createCubeMesh("TestBox1", "BoxColor"); Ogre::SceneNode* headNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); Ogre::MeshPtr Mesh = testBox->convertToMesh("TestBox2"); Ogre::StaticGeometry* pGeom = new Ogre::StaticGeometry (mSceneMgr, "Boxes"); Ogre::Entity* pEnt = mSceneMgr->createEntity("TestBox2"); //testBox->triangle pGeom->setRegionDimensions(Ogre::Vector3(300, 300, 300)); World::Instance(); pGeom->build (); mSceneMgr->setAmbientLight(Ogre::ColourValue(0.5, 0.5, 0.5)); Ogre::Light* l = mSceneMgr->createLight("MainLight"); l->setPosition(20,80,50); //Create Cube /* Ogre::Entity* entNinja = mSceneMgr->createEntity("Ninja", "ninja.mesh"); entNinja->setCastShadows(true); mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(entNinja);*/ 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 )); }
void CubeWorld::createTexture (const TCHAR* pName, const TCHAR* pImageFilename) { Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().create(pName, "General", true ); Ogre::Technique* tech = mat->getTechnique(0); Ogre::Pass* pass = tech->getPass(0); Ogre::TextureUnitState* tex = pass->createTextureUnitState(); tex->setTextureName(pImageFilename); tex->setNumMipmaps(4); tex->setTextureAnisotropy(1); tex->setTextureFiltering(Ogre::FO_POINT, Ogre::FO_POINT, Ogre::FO_POINT); pass->setVertexColourTracking(Ogre::TVC_DIFFUSE); tex->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_DIFFUSE, Ogre::LBS_TEXTURE); tech->setLightingEnabled(false); }
void UniversePlanet::create() { Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().create("BoxColor", "General", true); Ogre::Technique* tech = mat->getTechnique(0); Ogre::Pass* pass = tech->getPass(0); Ogre::TextureUnitState* tex = pass->createTextureUnitState(); tex->setTextureName("materials/textures/grass.png"); tex->setNumMipmaps(4); tex->setTextureAnisotropy(1); tex->setTextureFiltering(Ogre::FO_POINT, Ogre::FO_POINT, Ogre::FO_POINT); ManualObject *meshChunk = new ManualObject("meshChunk_" + getName()); int iVertex = 0; block_t currentBlock; block_t nextBlock; Ogre::Vector3 v; meshChunk->begin("BoxColor"); for(int w = 0; w < 6; ++w) for(int z = 0; z < mWorldHeight; ++z) for(int y = 0; y < mWorldSize; ++y) for(int x = 0; x < mWorldSize; ++x) { currentBlock = getBlock(w, x, y, z); if(currentBlock == 0) continue; //x-1 nextBlock = 0; nextBlock = getBlock(w, x - 1, y, z); if(nextBlock == 0) { meshChunk->position(map(w, x, y, z + 1)); meshChunk->textureCoord(0, 1); meshChunk->position(map(w, x, y + 1, z + 1)); meshChunk->textureCoord(1, 1); meshChunk->position(map(w, x, y + 1, z)); meshChunk->textureCoord(1, 0); meshChunk->position(map(w, x, y, z)); meshChunk->textureCoord(0, 0); if(w == 0 || w == 3 || w == 5) meshChunk->quad(iVertex + 3, iVertex + 2, iVertex + 1, iVertex); else meshChunk->quad(iVertex, iVertex + 1, iVertex + 2, iVertex + 3); iVertex += 4; } //x+1 nextBlock = 0; nextBlock = getBlock(w, x + 1, y, z); if(nextBlock == 0) { meshChunk->position(map(w, x + 1, y, z)); meshChunk->textureCoord(0, 1); meshChunk->position(map(w, x + 1, y + 1, z)); meshChunk->textureCoord(1, 1); meshChunk->position(map(w, x + 1, y + 1, z + 1)); meshChunk->textureCoord(1, 0); meshChunk->position(map(w, x + 1, y, z + 1)); meshChunk->textureCoord(0, 0); if(w == 0 || w == 3 || w == 5) meshChunk->quad(iVertex + 3, iVertex + 2, iVertex + 1, iVertex); else meshChunk->quad(iVertex, iVertex + 1, iVertex + 2, iVertex + 3); iVertex += 4; } //y-1 nextBlock = 0; nextBlock = getBlock(w, x, y - 1, z); if(nextBlock == 0) { meshChunk->position(map(w, x, y, z)); meshChunk->textureCoord(0, 1); meshChunk->position(map(w, x + 1, y, z)); meshChunk->textureCoord(1, 1); meshChunk->position(map(w, x + 1, y, z + 1)); meshChunk->textureCoord(1, 0); meshChunk->position(map(w, x, y, z + 1)); meshChunk->textureCoord(0, 0); if(w == 0 || w == 3 || w == 5) meshChunk->quad(iVertex + 3, iVertex + 2, iVertex + 1, iVertex); else meshChunk->quad(iVertex, iVertex + 1, iVertex + 2, iVertex + 3); iVertex += 4; } //y+1 nextBlock = 0; nextBlock = getBlock(w, x, y + 1, z); if(nextBlock == 0) { meshChunk->position(map(w, x, y + 1, z + 1)); meshChunk->textureCoord(0, 1); meshChunk->position(map(w, x + 1, y + 1, z + 1)); meshChunk->textureCoord(1, 1); meshChunk->position(map(w, x + 1, y + 1, z)); meshChunk->textureCoord(1, 0); meshChunk->position(map(w, x, y + 1, z)); meshChunk->textureCoord(0, 0); if(w == 0 || w == 3 || w == 5) meshChunk->quad(iVertex + 3, iVertex + 2, iVertex + 1, iVertex); else meshChunk->quad(iVertex, iVertex + 1, iVertex + 2, iVertex + 3); iVertex += 4; } //z-1 ok nextBlock = 0; nextBlock = getBlock(w, x, y, z - 1); if(nextBlock == 0) { meshChunk->position(map(w, x, y + 1, z)); meshChunk->textureCoord(0, 1); meshChunk->position(map(w, x + 1, y + 1, z)); meshChunk->textureCoord(1, 1); meshChunk->position(map(w, x + 1, y, z)); meshChunk->textureCoord(1, 0); meshChunk->position(map(w, x, y, z)); meshChunk->textureCoord(0, 0); if(w == 0 || w == 3 || w == 5) meshChunk->quad(iVertex, iVertex + 1, iVertex + 2, iVertex + 3); else meshChunk->quad(iVertex + 3, iVertex + 2, iVertex + 1, iVertex); iVertex += 4; } //z+1 ok nextBlock = 0; nextBlock = getBlock(w, x, y, z + 1); if(nextBlock == 0) { meshChunk->position(map(w, x, y, z + 1)); meshChunk->textureCoord(0, 1); meshChunk->position(map(w, x + 1, y, z + 1)); meshChunk->textureCoord(1, 1); meshChunk->position(map(w, x + 1, y + 1, z + 1)); meshChunk->textureCoord(1, 0); meshChunk->position(map(w, x, y + 1, z + 1)); meshChunk->textureCoord(0, 0); if(w == 1 || w == 2 || w == 4) meshChunk->quad(iVertex, iVertex + 1, iVertex + 2, iVertex + 3); else meshChunk->quad(iVertex + 3, iVertex + 2, iVertex + 1, iVertex); iVertex += 4; } } meshChunk->end(); Application::getSceneMgr()->getRootSceneNode()->createChildSceneNode()->attachObject(meshChunk); Application::getSceneMgr()->setAmbientLight(Ogre::ColourValue(0.5, 0.5, 0.5)); Ogre::Light* l = Application::getSceneMgr()->createLight("MainLight"); l->setPosition(20, 80, 50); }