//this makes the cube mesh used to represent a voxel.
void OgreDisplay::createVoxelMesh()
{
	ManualObject* manual = sceneMgr->createManualObject("voxel");
	manual->begin("BaseWhite", RenderOperation::OT_TRIANGLE_LIST);

	manual->position(-0.5, -0.5, -0.5); //0
	manual->position(-0.5, -0.5, 0.5); //1
	manual->position(0.5, -0.5, 0.5); //2
	manual->position(0.5, -0.5, -0.5); //3
	manual->position(-0.5, 0.5, -0.5); //4
	manual->position(-0.5, 0.5, 0.5); //5
	manual->position(0.5, 0.5, 0.5); //6
	manual->position(0.5, 0.5, -0.5); //7

	manual->quad(0,1,2,3);
	manual->quad(4,5,6,7);
	manual->quad(0,1,4,5);
	manual->quad(2,3,6,7);
	manual->quad(1,2,5,6);
	manual->quad(0,3,4,7);

	manual->end();

	manual->convertToMesh("voxel");
}
void createMeshWithMaterial(String fileName)
{
    String matFileNameSuffix = ".material";
    String matName1 = "red";
    String matFileName1 = matName1 + matFileNameSuffix;
    MaterialPtr matPtr = MaterialManager::getSingleton().create(matName1, "General");
    Pass* pass = matPtr->getTechnique(0)->getPass(0);
    pass->setDiffuse(1.0, 0.1, 0.1, 0);

    String matName2 = "green";
    String matFileName2 = matName2 + matFileNameSuffix;
    matPtr = MaterialManager::getSingleton().create(matName2, "General");
    pass = matPtr->getTechnique(0)->getPass(0);
    pass->setDiffuse(0.1, 1.0, 0.1, 0);

    String matName3 = "blue";
    String matFileName3 = matName3 + matFileNameSuffix;
    matPtr = MaterialManager::getSingleton().create(matName3, "General");
    pass = matPtr->getTechnique(0)->getPass(0);
    pass->setDiffuse(0.1, 0.1, 1.0, 0);

    String matName4 = "yellow";
    String matFileName4 = matName4 + matFileNameSuffix;
    matPtr = MaterialManager::getSingleton().create(matName4, "General");
    pass = matPtr->getTechnique(0)->getPass(0);
    pass->setDiffuse(1.0, 1.0, 0.1, 0);

    ManualObject* manObj = OGRE_NEW ManualObject("mesh");
    manObj->begin(matName1, RenderOperation::OT_TRIANGLE_LIST);
    manObj->position(0, 50, 0);
    manObj->position(50, 50, 0);
    manObj->position(0, 100, 0);
    manObj->triangle(0, 1, 2);
    manObj->position(50, 100, 0);
    manObj->position(0, 100, 0);
    manObj->position(50, 50, 0);
    manObj->triangle(3, 4, 5);
    manObj->end();
    manObj->begin(matName2, RenderOperation::OT_LINE_LIST);
    manObj->position(0, 100, 0);
    manObj->position(-50, 50, 0);
    manObj->position(-50, 0, 0);
    manObj->position(-50, 50, 0);
    manObj->position(-100, 0, 0);
    manObj->position(-50, 0, 0);
    manObj->end();
    manObj->begin(matName3, RenderOperation::OT_LINE_STRIP);
    manObj->position(50, 100, 0);
    manObj->position(100, 50, 0);
    manObj->position(100, 0, 0);
    manObj->position(150, 0, 0);
    manObj->end();
    manObj->begin(matName4, RenderOperation::OT_POINT_LIST);
    manObj->position(50, 0, 0);
    manObj->position(0, 0, 0);
    manObj->end();
    manObj->convertToMesh(fileName);
    OGRE_DELETE manObj;

}
MeshPtr ShowNormalsGenerator::buildMesh(const std::string& name, const String& group) const
{
	SceneManager* sceneMgr = Ogre::Root::getSingleton().getSceneManagerIterator().begin()->second;
	ManualObject* mo = buildManualObject();
	Ogre::MeshPtr mesh = mo->convertToMesh(name, group);

	sceneMgr->destroyManualObject(mo);

	return mesh;
}
void OgreDisplay::createCylinderMesh(std::string name, std::string material)
{
	//make a cube mesh
	
	ManualObject* cylinderMesh = sceneMgr->createManualObject("cylinder");
	cylinderMesh->begin(material, RenderOperation::OT_TRIANGLE_LIST);
	
	for(double i = 0.0; i < Math::PI * 2; i += Math::PI / 5)
	{
		cylinderMesh->position(cos(i), 1, sin(i));
		cylinderMesh->textureCoord(i / (Math::PI * 2), 1.0);
		Ogre::Vector3 myNormal(cos(i), 0, sin(i));
		myNormal.normalise();
		cylinderMesh->normal(myNormal);
	}
	
	for(double i = 0.0; i < Math::PI * 2; i += Math::PI / 5)
	{
		cylinderMesh->position(cos(i), -1, sin(i));
		cylinderMesh->textureCoord(i / (Math::PI * 2), 0.0);
		Ogre::Vector3 myNormal(cos(i), 0, sin(i));
		myNormal.normalise();
		cylinderMesh->normal(myNormal);
	}
	
	for(int i = 0; i < 10; i++)
	{
		cylinderMesh->triangle(i, (i+1) % 10, ((i + 10) % 20));
	}
	
	for(int i = 10; i < 20; i++)
	{
		cylinderMesh->triangle(i, (i+1) % 10, (i+1) % 10 + 10);
	}
	
	cylinderMesh->position(0, 1, 0);
	cylinderMesh->textureCoord(0.5, 0.5);
	
	cylinderMesh->position(0, -1, 0);
	cylinderMesh->textureCoord(0.5, 0.5);
	
	for(int i = 0; i < 10; i++)
	{
		cylinderMesh->triangle(20, (i+1) % 10, i);
		cylinderMesh->triangle(21, ((i+10) % 10) + 10, ((i+ 11) % 10) + 10);
	}

	cylinderMesh->end();

	cylinderMesh->convertToMesh(name);
}
Beispiel #5
0
void OgreAppLogic::createScene(void)
{
	// setup some basic lighting for our scene
	mSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, 8);
	// make a cube to bounce around
	Entity *ent1;
	SceneNode *boxNode;
	
	ManualObject *cmo = createCubeMesh("manual", "");
	cmo->convertToMesh("cube");
	ent1 = mSceneMgr->createEntity("Cube", "cube.mesh");
	ent1->setCastShadows(true);
	boxNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
	boxNode->attachObject(ent1);
	boxNode->setScale(Vector3(0.1,0.1,0.1)); // for some reason converttomesh multiplied dimensions by 10
	
    mSceneMgr->setAmbientLight(ColourValue(0.3, 0.3, 0.3));
    mSceneMgr->createLight()->setPosition(20, 80, 50);
	// create a floor mesh resource
	MeshManager::getSingleton().createPlane("floor", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
	Plane(Vector3::UNIT_Y, -30), 1000, 1000, 10, 10, true, 1, 8, 8, Vector3::UNIT_Z);

	// create a floor entity, give it a material, and place it at the origin
    Entity* floor = mSceneMgr->createEntity("Floor", "floor");
    floor->setMaterialName("Examples/BumpyMetal");
    mSceneMgr->getRootSceneNode()->attachObject(floor);
	
	mSceneMgr->getRootSceneNode()->attachObject(mSceneMgr->createEntity("Head", "ogrehead.mesh"));
	mSceneMgr->setSkyBox(true, "Examples/GridSkyBox");
	
	Ogre::Entity* ent = mSceneMgr->createEntity("Sinbad.mesh");	//1x1_cube.mesh //Sinbad.mesh //axes.mesh

	mObjectNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("cube");	
	mObjectNode->setOrientation(Quaternion(Degree(90.f), Vector3::UNIT_X));
	Ogre::Real scale = 22;
	mObjectNode->setPosition(10, 10, 10*scale);
	mObjectNode->setScale(Ogre::Vector3::UNIT_SCALE*scale);
	mObjectNode->attachObject(ent);
	mObjectNode->setVisible(true);

	// create swords and attach them to sinbad
	Ogre::Entity* sword1 = mSceneMgr->createEntity("SinbadSword1", "Sword.mesh");
	Ogre::Entity* sword2 = mSceneMgr->createEntity("SinbadSword2", "Sword.mesh");
	ent->attachObjectToBone("Sheath.L", sword1);
	ent->attachObjectToBone("Sheath.R", sword2);
	mAnimState = ent->getAnimationState("Dance");
	mAnimState->setLoop(true);
	mAnimState->setEnabled(true);

}
    void setupScene()
    {
        mSceneMgr = mRoot->createSceneManager(ST_GENERIC, "Default SceneManager");
        Camera *cam = mSceneMgr->createCamera("Camera");
        Viewport *vp = mRoot->getAutoCreatedWindow()->addViewport(cam);

          Entity *ent;

        mSceneMgr->setAmbientLight(ColourValue(0.25, 0.25, 0.25));
        mSceneMgr->setShadowTechnique( SHADOWTYPE_STENCIL_ADDITIVE );

        // EN:: make a cube to bounce around
        // BR:: cria um cubo pra quicar
      ManualObject *cmo = createCubeMesh("manual", "");
      cmo->convertToMesh("cube");
      ent = mSceneMgr->createEntity("Cube", "cube.mesh");
      ent->setCastShadows(true);
      boxNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
      boxNode->attachObject(ent);
      boxNode->setScale(Vector3(0.1,0.1,0.1));


      // EN:: make a rock wall on the floor
      // BR:: adiciona piso de pedra no chão
        Plane plane(Vector3::UNIT_Y, 0);
        MeshManager::getSingleton().createPlane("ground",
               ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
               1500,1500,20,20,true,1,5,5,Vector3::UNIT_Z);
        ent = mSceneMgr->createEntity("GroundEntity", "ground");
        mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
      ent->setMaterialName("Examples/Rockwall");
      ent->setCastShadows(false);


      // EN:: make a light to see stuff with
      // BR:: adiciona uma iluminação
        Light *light = mSceneMgr->createLight("Light1");
        light->setType(Light::LT_POINT);
        light->setPosition(Vector3(250, 150, 250));
        light->setDiffuseColour(ColourValue::White);
        light->setSpecularColour(ColourValue::White);

        // EN:: Create the scene node
        // BR:: cria o SceneNode (nó da cena)
        SceneNode *node = mSceneMgr->getRootSceneNode()->createChildSceneNode("CamNode1", Vector3(-200, 100, 200));
        node->yaw(Degree(-45));
        node->attachObject(cam);
    }
void MeshWithoutIndexDataTests::testCreateLineWithMaterial()
{
    String matName = "lineMat";
    MaterialPtr matPtr = MaterialManager::getSingleton().create(matName, "General");
    Pass* pass = matPtr->getTechnique(0)->getPass(0);
    pass->setDiffuse(1.0, 0.1, 0.1, 0);

    ManualObject* line = OGRE_NEW ManualObject("line");
    line->begin(matName, RenderOperation::OT_LINE_LIST);
    line->position(0, 50, 0);
    line->position(50, 100, 0);
    line->end();
    String fileName = "lineWithMat.mesh";
    MeshPtr lineMesh = line->convertToMesh(fileName);
    OGRE_DELETE line;

    CPPUNIT_ASSERT(lineMesh->getNumSubMeshes() == 1);
    CPPUNIT_ASSERT(lineMesh->getSubMesh(0)->indexData->indexCount == 0);
    RenderOperation rop;
    lineMesh->getSubMesh(0)->_getRenderOperation(rop);
    CPPUNIT_ASSERT(rop.useIndexes == false);
    CPPUNIT_ASSERT(lineMesh->getSubMesh(0)->vertexData->vertexCount == 2);

    MeshSerializer meshWriter;
    meshWriter.exportMesh(lineMesh.get(), fileName);
    MaterialSerializer matWriter;
    matWriter.exportMaterial(
        MaterialManager::getSingleton().getByName(matName), 
        matName + ".material"
        );

    mMeshMgr->remove( fileName );

    ResourceGroupManager::getSingleton().addResourceLocation(".", "FileSystem");
    MeshPtr loadedLine = mMeshMgr->load(fileName, "General");

    remove(fileName.c_str());
    remove((matName + ".material").c_str());

    CPPUNIT_ASSERT(loadedLine->getNumSubMeshes() == 1);
    CPPUNIT_ASSERT(loadedLine->getSubMesh(0)->indexData->indexCount == 0);
    loadedLine->getSubMesh(0)->_getRenderOperation(rop);
    CPPUNIT_ASSERT(rop.useIndexes == false);
    CPPUNIT_ASSERT(lineMesh->getSubMesh(0)->vertexData->vertexCount == 2);

    mMeshMgr->remove( fileName );
}
Beispiel #8
0
void Application::createScene()
{
    //mSceneMgr = mRoot->createSceneManager(ST_GENERIC, "Default SceneManager");    In create cameras and viewports
    //Camera *cam = mSceneMgr->createCamera("Camera");
    //Viewport *vp = mRoot->getAutoCreatedWindow()->addViewport(cam);
//
    Entity *ent;

    mSceneMgr->setAmbientLight(ColourValue(0.25, 0.25, 0.25));
    mSceneMgr->setShadowTechnique( SHADOWTYPE_STENCIL_ADDITIVE );

    // make a cube to bounce around
    ManualObject *cmo = createCubeMesh("manual", "");
    cmo->convertToMesh("cube");
    ent = mSceneMgr->createEntity("Cube", "cube.mesh");
    ent->setCastShadows(true);
    boxNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
    boxNode->attachObject(ent);
    boxNode->setScale(Vector3(0.1,0.1,0.1)); // for some reason converttomesh multiplied dimensions by 10
//
//
    // make a rock wall on the floor
    Plane plane(Vector3::UNIT_Y, 0);
    MeshManager::getSingleton().createPlane("ground",
                                            ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
                                            1500,1500,20,20,true,1,5,5,Vector3::UNIT_Z);
    ent = mSceneMgr->createEntity("GroundEntity", "ground");
    mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
    ent->setMaterialName("Examples/Rockwall");
    ent->setCastShadows(false);

//
//      // make a light to see stuff with
    Light *light = mSceneMgr->createLight("Light1");
    light->setType(Light::LT_POINT);
    light->setPosition(Vector3(250, 150, 250));
    light->setDiffuseColour(ColourValue::White);
    light->setSpecularColour(ColourValue::White);
//
//        // Create the scene node
    SceneNode *node = mSceneMgr->getRootSceneNode()->createChildSceneNode("CamNode1", Vector3(-200, 100, 200));
    node->yaw(Degree(-45));
    //node->attachObject(cam);
    //node->attachObject(mCamera);
}
 Entity* OctreeNode::getOctreeGrid(SceneManager *sceneManager)
 {
     if (!mOctreeGrid)
     {
         mGridPositionCount = 0;
         mNodeI++;
         ManualObject* manual = sceneManager->createManualObject();
         manual->begin("BaseWhiteNoLighting", RenderOperation::OT_LINE_LIST);
         manual->colour((Real)1.0, (Real)0.0, (Real)0.0);
         buildOctreeGridLines(manual); 
         manual->end();
     
         StringUtil::StrStreamType meshName;
         meshName << "VolumeOctreeGridMesh" << mNodeI;
         manual->convertToMesh(meshName.str());
         StringUtil::StrStreamType entityName;
         entityName << "VolumeOctreeGrid" << mNodeI;
         mOctreeGrid = sceneManager->createEntity(entityName.str(), meshName.str());
     }
     return mOctreeGrid;
 }
void MeshWithoutIndexDataTests::testCreateLineList()
{
    ManualObject* lineList = OGRE_NEW ManualObject("line");
    lineList->begin("BaseWhiteNoLighting", RenderOperation::OT_LINE_LIST);
    lineList->position(0, 50, 0);
    lineList->position(50, 100, 0);
    lineList->position(50, 50, 0);
    lineList->position(100, 100, 0);
    lineList->position(0, 50, 0);
    lineList->position(50, 50, 0);
    lineList->end();
    String fileName = "lineList.mesh";
    MeshPtr lineListMesh = lineList->convertToMesh(fileName);
    OGRE_DELETE lineList;

    CPPUNIT_ASSERT(lineListMesh->getNumSubMeshes() == 1);
    CPPUNIT_ASSERT(lineListMesh->getSubMesh(0)->indexData->indexCount == 0);
    RenderOperation rop;
    lineListMesh->getSubMesh(0)->_getRenderOperation(rop);
    CPPUNIT_ASSERT(rop.useIndexes == false);
    CPPUNIT_ASSERT(lineListMesh->getSubMesh(0)->vertexData->vertexCount == 6);

    MeshSerializer meshWriter;
    meshWriter.exportMesh(lineListMesh.get(), fileName);

    mMeshMgr->remove( fileName );

    ResourceGroupManager::getSingleton().addResourceLocation(".", "FileSystem");
    MeshPtr loadedLineList = mMeshMgr->load(fileName, "General");

    remove(fileName.c_str());

    CPPUNIT_ASSERT(loadedLineList->getNumSubMeshes() == 1);
    CPPUNIT_ASSERT(loadedLineList->getSubMesh(0)->indexData->indexCount == 0);
    loadedLineList->getSubMesh(0)->_getRenderOperation(rop);
    CPPUNIT_ASSERT(rop.useIndexes == false);
    CPPUNIT_ASSERT(loadedLineList->getSubMesh(0)->vertexData->vertexCount == 6);

    mMeshMgr->remove( fileName );
}
    Entity* MeshBuilder::generateWithManualObject(SceneManager *sceneManager, const String &name, const String &material)
    {
            ManualObject* manual = sceneManager->createManualObject();
            manual->begin(material, RenderOperation::OT_TRIANGLE_LIST);
        
            for (VecVertex::const_iterator iter = mVertices.begin(); iter != mVertices.end(); ++iter)
            {
                manual->position(Vector3(iter->x, iter->y, iter->z));
                manual->normal(Vector3(iter->nX, iter->nY, iter->nZ));
            }
            for (VecIndices::const_iterator iter = mIndices.begin(); iter != mIndices.end(); ++iter)
            {
                manual->index(*iter);
            }

            manual->end();
            StringUtil::StrStreamType meshName;
            meshName << name << "ManualObject";
            MeshManager::getSingleton().remove(meshName.str());
            manual->convertToMesh(meshName.str());
            return sceneManager->createEntity(name, meshName.str());
    }
    Entity* DualGridGenerator::getDualGrid(SceneManager *sceneManager)
    {
        if (!mDualGrid && mDualCells.size() > 0)
        {
            ManualObject* manual = sceneManager->createManualObject();
            manual->begin("BaseWhiteNoLighting", RenderOperation::OT_LINE_LIST);
            manual->colour((Real)0.0, (Real)1.0, (Real)0.0);
            manual->estimateVertexCount(mDualCells.size() * 8);
            manual->estimateIndexCount(mDualCells.size() * 24);

            uint32 baseIndex = 0;
            for (VecDualCell::iterator it = mDualCells.begin(); it != mDualCells.end(); ++it)
            {
                MeshBuilder::addCubeToManualObject(
                    manual,
                    it->mC0,
                    it->mC1,
                    it->mC2,
                    it->mC3,
                    it->mC4,
                    it->mC5,
                    it->mC6,
                    it->mC7,
                    baseIndex);
            }

            manual->end();
            mDualGridI++;
            StringUtil::StrStreamType meshName;
            meshName << "VolumeDualGridGridMesh" << mDualGridI;
            manual->convertToMesh(meshName.str());
            StringUtil::StrStreamType entityName;
            entityName << "VolumeDualGrid" << mDualGridI;
            mDualGrid = sceneManager->createEntity(entityName.str(), meshName.str());
        }
        return mDualGrid;
    }
void MeshWithoutIndexDataTests::testEdgeList()
{
    String fileName = "testEdgeList.mesh";
    ManualObject* line = OGRE_NEW ManualObject("line");
    line->begin("BaseWhiteNoLighting", RenderOperation::OT_LINE_LIST);
    line->position(0, 50, 0);
    line->position(50, 100, 0);
    line->end();
    MeshPtr mesh = line->convertToMesh(fileName);
    OGRE_DELETE line;

    // whole mesh must not contain index data, for this test
    CPPUNIT_ASSERT(mesh->getNumSubMeshes() == 1);
    CPPUNIT_ASSERT(mesh->getSubMesh(0)->indexData->indexCount == 0);

    mesh->buildEdgeList();
    MeshSerializer meshWriter;
    // if it does not crash here, test is passed
    meshWriter.exportMesh(mesh.get(), fileName);

    remove(fileName.c_str());

    mMeshMgr->remove( fileName );
}
Beispiel #14
0
void App::CreateVdrTrack(std::string strack, TRACK* pTrack)
{	
	//  materials  -------------
	std::vector<OGRE_MESH>& meshes = pTrack->ogre_meshes;
	std::string sMatCache = strack + ".matdef", sMatOrig = "_" + sMatCache,
		sPathCache = PATHMANAGER::ShaderDir() + "/" + sMatCache, sPathOrig = gcom->TrkDir() +"objects/"+ sMatOrig;
	bool hasMatOrig = boost::filesystem::exists(sPathOrig), hasMatCache = boost::filesystem::exists(sPathCache);
	bool bGenerate = 0, gen = !hasMatOrig && !hasMatCache || bGenerate;  // set 1 to force generate for new vdrift tracks


	//TODO .mat ..rewrite this code for new system
#if 0
	if (gen)
	{
		String sMtrs;
		for (int i=0; i < meshes.size(); i++)
		{
			OGRE_MESH& msh = meshes[i];
			if (msh.sky /*&& ownSky*/)  continue;
			if (!msh.newMtr)  continue;  //  create material if new

			bool found = true;
			TexturePtr tex = TextureManager::getSingleton().getByName(msh.material);
			if (tex.isNull())
			try{
				tex = TextureManager::getSingleton().load(msh.material, rgDef);  }
			catch(...){
				found = false;  }
			msh.found = found;  // dont create meshes for not found textures, test
			if (!found)  continue;

			#if 0  // use 0 for some tracks (eg.zandvoort) - have alpha textures for all!
			if (!tex.isNull() && tex->hasAlpha())
				msh.alpha = true;  // for textures that have alpha
			#endif

			if (msh.alpha)
				sMtrs += "["+msh.material+"]\n"+
					"	parent = 0vdrAlpha\n"+
					"	diffuseMap_512 = "+msh.material+"\n";
			else
				sMtrs += "["+msh.material+"]\n"+
					"	parent = 0vdrTrk\n"+
					"	diffuseMap_512 = "+msh.material+"\n";
		}

		std::ofstream fileout(sPathCache.c_str());
		if (!fileout)  LogO("Error: Can't save vdrift track matdef!");
		fileout.write(sMtrs.c_str(), sMtrs.size());
		fileout.close();
		hasMatCache = true;
	}
#endif
	

	//  meshes  -------------
	std::vector<Entity*> ents;
	static int ii = 0;  int i;
	for (i=0; i < meshes.size(); ++i)
	{
		OGRE_MESH& msh = meshes[i];
		if (msh.sky /*&& ownSky*/)  continue;
		if (!msh.found)  continue;

		//if (strstr(msh.material.c_str(), "tree")!=0)  continue;

		//LogO( String("---  model: ") + msh.name + " mtr:" + msh.material +
		//" v:" + toStr(msh.mesh->vertices.size()) + " f:" + toStr(msh.mesh->faces.size()) );

		//if (ownSky && msh.sky)
		if (!msh.sky)
		{
		ManualObject* m = CreateModel(mSceneMgr, msh.material, msh.mesh, Vector3(0,0,0), false, true);
		//if (!m)  continue;
		if (msh.sky)
			m->setCastShadows(false);
		
		MeshPtr mp = m->convertToMesh("m"+toStr(ii+i));
		Entity* e = mSceneMgr->createEntity(mp);

		ents.push_back(e);
		}
	}
	ii += i;

	//  static geom  -------------
	scn->vdrTrack = mSceneMgr->createStaticGeometry("track");
	scn->vdrTrack->setRegionDimensions(Vector3::UNIT_SCALE * 1000);  // 1000
	scn->vdrTrack->setOrigin(Vector3::ZERO);
	scn->vdrTrack->setCastShadows(true);

	for (std::vector<Entity*>::iterator it = ents.begin(); it != ents.end(); ++it)
		scn->vdrTrack->addEntity(*it, Vector3::ZERO);

	scn->vdrTrack->build();
	//mStaticGeom->dump("_track-sg.txt");
}
Beispiel #15
0
void GameState::createScene()
{
	mSceneMgr->setSkyBox(true, "SkyBox");
    mDebugDrawer = new BtOgre::DebugDrawer(mSceneMgr->getRootSceneNode(), mWorld);
	mDebugDrawer->setDebugMode(btIDebugDraw::DBG_DrawWireframe);
	mWorld->setDebugDrawer(mDebugDrawer);
	//player = new Viper( mSceneMgr, mWorld);
	
	team1 = new TeamManager("red",this, mSceneMgr, mWorld,  "Team01");
	team1->addViper(Ogre::Vector3(-20, 5, 0), "Player");
	player = team1->getViperByName("Player");
	Ogre::SceneNode * playerSceneNode = player->getSceneNode();
	mCameraNode = playerSceneNode->createChildSceneNode("CameraNode", Ogre::Vector3(-4, 5, 0));
	mCameraNode->attachObject(mCamera);
	//Viper * player2 = new Viper(mSceneMgr, mWorld, Ogre::Vector3(100, 0,0));
	//player2->setDirection(Ogre::Vector3(10,0,0));
	//player2->setSpeed(50);
	//player2->transform(Ogre::Quaternion::IDENTITY, Ogre::Vector3::ZERO);
	team2 = new TeamManager("blue",this,  mSceneMgr, mWorld,"Team02");
	team2->addViper(Ogre::Vector3(100, 0,0));
	OgreFramework::getSingleton().mSoundManager->createSound("GameBackgroundMusic", "background_music.ogg", false, true, true) ;
	OgreFramework::getSingleton().mSoundManager->getSound("GameBackgroundMusic")->play();
	CEGUI::WindowManager &wmgr = CEGUI::WindowManager::getSingleton();
	CEGUI::Window *guiRoot = wmgr.loadWindowLayout("game.layout"); 
	CEGUI::System::getSingleton().setGUISheet(guiRoot);
	CEGUI::ProgressBar * bar = (CEGUI::ProgressBar *)wmgr.getWindow("GameState/Life");
	bar->setProgress(1.0f);
	generateEnvironment();
	// create ManualObject which will be the Viper bullet placeholder
	Ogre::ManualObject mo("BulletObject");
	const float width = 0.2;
	const float height = 0.5;
	Ogre::Vector3 vec(width/2, 0, 0);
	Ogre::Quaternion rot;
	rot.FromAngleAxis(Ogre::Degree(90), Ogre::Vector3::UNIT_Y);
	mo.begin("blue", Ogre::RenderOperation::OT_TRIANGLE_LIST);
	for (int i = 0; i < 2; ++i)
	{
		mo.position(-vec.x, height, -vec.z);
		mo.textureCoord(0, 0);

		mo.position(vec.x, height, vec.z);
		mo.textureCoord(1, 0);

		mo.position(-vec.x, 0, -vec.z);
		mo.textureCoord(0, 1);

		mo.position(vec.x, 0, vec.z);
		mo.textureCoord(1, 1);
		int offset = i * 4;
		mo.triangle(offset, offset+3, offset+1);
		mo.triangle(offset, offset+2, offset+3);
		vec = rot * vec;
	}
	mo.end();
	mo.convertToMesh("ViperBulletMesh");
	Ogre::Entity * ent123 = mSceneMgr->createEntity("ViperBulletMesh");
	Ogre::Quaternion quat;
	quat.FromAngleAxis(Ogre::Degree(90), Ogre::Vector3(0,0,1));
#ifndef DEBUG
	wmgr.destroyWindow("GameState/Debug");
#endif
			ManualObject* myManualObject =  mSceneMgr->createManualObject("manual1"); 
		//SceneNode* myManualObjectNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("manual1_node"); 
		 
		MaterialPtr myManualObjectMaterial = MaterialManager::getSingleton().create("manual1Material", "General"); 
		myManualObjectMaterial->setReceiveShadows(false); 
		myManualObjectMaterial->getTechnique(0)->setLightingEnabled(true); 
		myManualObjectMaterial->getTechnique(0)->getPass(0)->setDiffuse(0,0,1,0); 
		myManualObjectMaterial->getTechnique(0)->getPass(0)->setAmbient(0,0,1); 
		myManualObjectMaterial->getTechnique(0)->getPass(0)->setSelfIllumination(0,0,1); 
//		myManualObjectMaterial->dispose();  // dispose pointer, not the material
		myManualObject->begin("manual1Material", Ogre::RenderOperation::OT_LINE_LIST); 
		myManualObject->position(-10, 0, 0); 
		myManualObject->position(1000, 0, 0); 
		// etc 
		myManualObject->end();
		myManualObject->convertToMesh("line");
		Ogre::Entity *lineLeft = mSceneMgr->createEntity("line");;
		Ogre::SceneNode * mNodeLeft = (Ogre::SceneNode *)player->getSceneNode()->getChild(player->getName()+"leftCanon");
		mNodeLeft->attachObject(lineLeft);
		Ogre::Entity *lineRight = mSceneMgr->createEntity("line");;
		Ogre::SceneNode * mNodeRight = (Ogre::SceneNode *)player->getSceneNode()->getChild(player->getName()+"rightCanon");
		mNodeRight->attachObject(lineRight);
}
Beispiel #16
0
void TunnelSlice::connect(TunnelSlice* next)
{
	float wallLength1 = getWallLength();
	float wallLength2 = next->getWallLength();
    
    int tempID = intermediateMeshID;
    entireIntermediate = parentNode->createChildSceneNode("intermediateSegmentNode" + Util::toStringInt(intermediateMeshID));
    
    std::string meshName = "intermediateMesh" + Util::toStringInt(intermediateMeshID);
    ManualObject* manual = parentNode->getCreator()->createManualObject(meshName);
    
    Quaternion q1 = getQuaternion();
    Quaternion q2 = next->getQuaternion();
    
    Vector3 start = center + getForward() * (depth / 2);
    Vector3 end = next->center - next->getForward() * (next->depth / 2);
    
    Vector3 move;
    Vector3 p1;
    Vector3 p2;
    Vector3 p3;
    Vector3 p4;
    Vector3 bl = Vector3(Ogre::Math::POS_INFINITY, Ogre::Math::POS_INFINITY, Ogre::Math::POS_INFINITY);
    Vector3 tr = Vector3(Ogre::Math::NEG_INFINITY, Ogre::Math::NEG_INFINITY, Ogre::Math::NEG_INFINITY);
    
    move = Vector3(-wallLength1 * (0.5 + Math::Cos(Ogre::Radian(Math::PI) / 4)), wallLength1 / 2, 0);
    move = q1 * move;
    p1 = start + move;
    move = Vector3(-wallLength2 * (0.5 + Math::Cos(Ogre::Radian(Math::PI) / 4)), wallLength2 / 2, 0);
    move = q2 * move;
    p2 = end + move;
    move = Vector3(-wallLength2 / 2, wallLength2 * (0.5 + Math::Sin(Ogre::Radian(Math::PI) / 4)), 0);
    move = q2 * move;
    p3 = end + move;
    move = Vector3(-wallLength1 / 2, wallLength1 * (0.5 + Math::Sin(Ogre::Radian(Math::PI) / 4)), 0);
    move = q1 * move;
    p4 = start + move;
    if (sidesUsed[NORTHWEST])
        setIntermediateWall(entireIntermediate, NORTHWEST, manual, p1, p2, p3, p4, bl, tr);
    
    p1 = p4;
    p2 = p3;
    move = Vector3(wallLength2 / 2, wallLength2 * (0.5 + Math::Sin(Ogre::Radian(Math::PI) / 4)), 0);
    move = q2 * move;
    p3 = end + move;
    move = Vector3(wallLength1 / 2, wallLength1 * (0.5 + Math::Sin(Ogre::Radian(Math::PI) / 4)), 0);
    move = q1 * move;
    p4 = start + move;
    if (sidesUsed[NORTH])
        setIntermediateWall(entireIntermediate, NORTH, manual, p1, p2, p3, p4, bl, tr);
    
    p1 = p4;
    p2 = p3;
    move = Vector3(wallLength2 * (0.5 + Math::Cos(Ogre::Radian(Math::PI) / 4)), wallLength2 / 2, 0);
    move = q2 * move;
    p3 = end + move;
    move = Vector3(wallLength1 * (0.5 + Math::Cos(Ogre::Radian(Math::PI) / 4)), wallLength1 / 2, 0);
    move = q1 * move;
    p4 = start + move;
    if (sidesUsed[NORTHEAST])
        setIntermediateWall(entireIntermediate, NORTHEAST, manual, p1, p2, p3, p4, bl, tr);
    
    p1 = p4;
    p2 = p3;
    move = Vector3(wallLength2 * (0.5 + Math::Cos(Ogre::Radian(Math::PI) / 4)), -wallLength2 / 2, 0);
    move = q2 * move;
    p3 = end + move;
    move = Vector3(wallLength1 * (0.5 + Math::Cos(Ogre::Radian(Math::PI) / 4)), -wallLength1 / 2, 0);
    move = q1 * move;
    p4 = start + move;
    if (sidesUsed[EAST])
        setIntermediateWall(entireIntermediate, EAST, manual, p1, p2, p3, p4, bl, tr);
    
    p1 = p4;
    p2 = p3;
    move = Vector3(wallLength2 / 2, -wallLength2 * (0.5 + Math::Sin(Ogre::Radian(Math::PI) / 4)), 0);
    move = q2 * move;
    p3 = end + move;
    move = Vector3(wallLength1 / 2, -wallLength1 * (0.5 + Math::Sin(Ogre::Radian(Math::PI) / 4)), 0);
    move = q1 * move;
    p4 = start + move;
    if (sidesUsed[SOUTHEAST])
        setIntermediateWall(entireIntermediate, SOUTHEAST, manual, p1, p2, p3, p4, bl, tr);
    
    p1 = p4;
    p2 = p3;
    move = Vector3(-wallLength2 / 2, -wallLength2 * (0.5 + Math::Sin(Ogre::Radian(Math::PI) / 4)), 0);
    move = q2 * move;
    p3 = end + move;
    move = Vector3(-wallLength1 / 2, -wallLength1 * (0.5 + Math::Sin(Ogre::Radian(Math::PI) / 4)), 0);
    move = q1 * move;
    p4 = start + move;
    if (sidesUsed[SOUTH])
        setIntermediateWall(entireIntermediate, SOUTH, manual, p1, p2, p3, p4, bl, tr);
    
    p1 = p4;
    p2 = p3;
    move = Vector3(-wallLength2 * (0.5 + Math::Cos(Ogre::Radian(Math::PI) / 4)), -wallLength2 / 2, 0);
    move = q2 * move;
    p3 = end + move;
    move = Vector3(-wallLength1 * (0.5 + Math::Cos(Ogre::Radian(Math::PI) / 4)), -wallLength1 / 2, 0);
    move = q1 * move;
    p4 = start + move;
    if (sidesUsed[SOUTHWEST])
        setIntermediateWall(entireIntermediate, SOUTHWEST, manual, p1, p2, p3, p4, bl, tr);
    
    p1 = p4;
    p2 = p3;
    move = Vector3(-wallLength1 * (0.5 + Math::Cos(Ogre::Radian(Math::PI) / 4)), wallLength1 / 2, 0);
    move = q2 * move;
    p3 = end + move;
    move = Vector3(-wallLength2 * (0.5 + Math::Cos(Ogre::Radian(Math::PI) / 4)), wallLength2 / 2, 0);
    move = q1 * move;
    p4 = start + move;
    if (sidesUsed[WEST])
        setIntermediateWall(entireIntermediate, WEST, manual, p1, p2, p3, p4, bl, tr);
    
    MeshPtr mesh = manual->convertToMesh(meshName);
    mesh->_setBounds( AxisAlignedBox( bl, tr ), true );
    
    float l = (tr - bl).length() / 2;
    mesh->_setBoundingSphereRadius(l);
    unsigned short src, dest;
    if (!mesh->suggestTangentVectorBuildParams(VES_TANGENT, src, dest))
    {
        mesh->buildTangentVectors(VES_TANGENT, src, dest);
    }
    
    Entity* intermediateSegmentEntity = entireIntermediate->getCreator()->createEntity("intermediateSegmentEntity" + Util::toStringInt(intermediateMeshID), meshName);
    //intermediateSegmentEntity->setMaterialName(getMaterialName());
    for (int i = 0; i < intermediateSegmentEntity->getNumSubEntities(); ++i)
        intermediateSegmentEntity->getSubEntity(i)->setMaterialName(getMaterialName());
    entireIntermediate->attachObject(intermediateSegmentEntity);
    
    meshes.push_back(mesh);
    intermediateMeshID++;
    parentNode->getCreator()->destroyManualObject(manual);
}
void OgreDisplay::createCubeMesh(std::string name, std::string material)
{
	//make a cube mesh
	
	ManualObject* cubeMesh = sceneMgr->createManualObject("cube");
	cubeMesh->begin(material, RenderOperation::OT_TRIANGLE_LIST);
	
	cubeMesh->position(-0.5, -0.5, -0.5); //0
	cubeMesh->normal(0,-1,0);
	cubeMesh->textureCoord(0,0);
	cubeMesh->position(-0.5, -0.5, 0.5); //1
	cubeMesh->normal(0,-1,0);
	cubeMesh->textureCoord(0,1);
	cubeMesh->position(0.5, -0.5, 0.5); //2
	cubeMesh->normal(0,-1,0);
	cubeMesh->textureCoord(1,1);
	cubeMesh->position(0.5, -0.5, -0.5); //3
	cubeMesh->normal(0,-1,0);
	cubeMesh->textureCoord(1,0);
	cubeMesh->position(-0.5, 0.5, -0.5); //4
	cubeMesh->normal(0,1,0);
	cubeMesh->textureCoord(0,0);
	cubeMesh->position(-0.5, 0.5, 0.5); //5
	cubeMesh->normal(0,1,0);
	cubeMesh->textureCoord(0,1);
	cubeMesh->position(0.5, 0.5, 0.5); //6
	cubeMesh->normal(0,1,0);
	cubeMesh->textureCoord(1,1);
	cubeMesh->position(0.5, 0.5, -0.5); //7
	cubeMesh->normal(0,1,0);
	cubeMesh->textureCoord(1,0);

	cubeMesh->position(-0.5, -0.5, -0.5); //8
	cubeMesh->normal(0,0,-1);
	cubeMesh->textureCoord(0,0);
	cubeMesh->position(-0.5, -0.5, 0.5); //9
	cubeMesh->normal(0,0,1);
	cubeMesh->textureCoord(0,0);
	cubeMesh->position(0.5, -0.5, 0.5); //10
	cubeMesh->normal(0,0,1);
	cubeMesh->textureCoord(1,0);
	cubeMesh->position(0.5, -0.5, -0.5); //11
	cubeMesh->normal(0,0,-1);
	cubeMesh->textureCoord(1,0);
	cubeMesh->position(-0.5, 0.5, -0.5); //12
	cubeMesh->normal(0,0,-1);
	cubeMesh->textureCoord(0,1);
	cubeMesh->position(-0.5, 0.5, 0.5); //13
	cubeMesh->normal(0,0,1);
	cubeMesh->textureCoord(0,1);
	cubeMesh->position(0.5, 0.5, 0.5); //14
	cubeMesh->normal(0,0,1);
	cubeMesh->textureCoord(1,1);
	cubeMesh->position(0.5, 0.5, -0.5); //15
	cubeMesh->normal(0,0,-1);
	cubeMesh->textureCoord(1,1);

	cubeMesh->position(-0.5, -0.5, -0.5); //16
	cubeMesh->normal(-1,0,0);
	cubeMesh->textureCoord(0,0);
	cubeMesh->position(-0.5, -0.5, 0.5); //17
	cubeMesh->normal(-1,0,0);
	cubeMesh->textureCoord(0,1);
	cubeMesh->position(0.5, -0.5, 0.5); //18
	cubeMesh->normal(1,0,0);
	cubeMesh->textureCoord(0,1);
	cubeMesh->position(0.5, -0.5, -0.5); //19
	cubeMesh->normal(1,0,0);
	cubeMesh->textureCoord(0,0);
	cubeMesh->position(-0.5, 0.5, -0.5); //20
	cubeMesh->normal(-1,0,0);
	cubeMesh->textureCoord(1,0);
	cubeMesh->position(-0.5, 0.5, 0.5); //21
	cubeMesh->normal(-1,0,0);
	cubeMesh->textureCoord(1,1);
	cubeMesh->position(0.5, 0.5, 0.5); //22
	cubeMesh->normal(1,0,0);
	cubeMesh->textureCoord(1,1);
	cubeMesh->position(0.5, 0.5, -0.5); //23
	cubeMesh->normal(1,0,0);
	cubeMesh->textureCoord(1,0);
	
	//bottom
	cubeMesh->quad(3,2,1,0);
	//top
	cubeMesh->quad(4,5,6,7);
	//front
	cubeMesh->quad(10,14,13,9);
	//back
	cubeMesh->quad(8,12,15,11);
	//left
	cubeMesh->quad(16,17,21,20);
	//right
	cubeMesh->quad(23,22,18,19);

	cubeMesh->end();

	cubeMesh->convertToMesh(name);
}