Ejemplo n.º 1
0
void OgreApplication::CreateWall(Ogre::String material_name){
	    
	try {

		/* Create two rectangles */

        /* Retrieve scene manager and root scene node */
        Ogre::SceneManager* scene_manager = ogre_root_->getSceneManager("MySceneManager");
        Ogre::SceneNode* root_scene_node = scene_manager->getRootSceneNode();

        /* Create the 3D object */
        Ogre::ManualObject* object = NULL;
        Ogre::String object_name = "Wall";
        object = scene_manager->createManualObject(object_name);
        object->setDynamic(false);

        /* Create triangle list for the object */
        object->begin(material_name, Ogre::RenderOperation::OT_TRIANGLE_LIST);

		/* Add vertices */
		/* One side of the "wall" */
		object->position(-1.0,-1.0,0.0);
		object->normal(0.0, 0.0, -1.0);
		object->tangent(-1.0, 0.0, 0.0);
		object->textureCoord(1.0, 0.0);

        object->position(-1.0,1.0,0.0);
		object->normal(0.0, 0.0, -1.0);
		object->tangent(-1.0, 0.0, 0.0);
		object->textureCoord(1.0, 1.0);

        object->position(1.0,1.0,0.0);
		object->normal(0.0, 0.0, -1.0);
		object->tangent(-1.0, 0.0, 0.0);
		object->textureCoord(0.0, 1.0);

        object->position(1.0,-1.0,0.0);
		object->normal(0.0, 0.0, -1.0);
		object->tangent(-1.0, 0.0, 0.0);
		object->textureCoord(0.0, 0.0);

		/* The other side of the "wall" */
        object->position(-1.0,-1.0,0.0);
		object->normal(0.0, 0.0, 1.0);
		object->tangent(1.0, 0.0, 0.0);
		object->textureCoord(0.0, 0.0);

        object->position(-1.0,1.0,0.0);
		object->normal(0.0, 0.0, 1.0);
		object->tangent(1.0, 0.0, 0.0);
		object->textureCoord(0.0, 1.0);

        object->position(1.0,1.0,0.0);
		object->normal(0.0, 0.0, 1.0);
		object->tangent(1.0, 0.0, 0.0);
		object->textureCoord(1.0, 1.0);

        object->position(1.0,-1.0,0.0);
		object->normal(0.0, 0.0, 1.0);
		object->tangent(1.0, 0.0, 0.0);
		object->textureCoord(1.0, 0.0);
        
		/* Add triangles */
		/* One side */
		object->triangle(0, 1, 2);
        object->triangle(0, 2, 3);
		/* The other side */
        object->triangle(4, 7, 6);
        object->triangle(4, 6, 5);
        
		/* We finished the object */
        object->end();
		
        /* Convert triangle list to a mesh */
        Ogre::String mesh_name = "Wall";
        object->convertToMesh(mesh_name);

        /* Create one instance of the sphere (one entity) */
		/* The same object can have multiple instances or entities */
        Ogre::Entity* entity = scene_manager->createEntity(mesh_name);

		/* Apply a material to the entity to give it color */
		/* We already did that above, so we comment it out here */
		/* entity->setMaterialName(material_name); */
		/* But, this call is useful if we have multiple entities with different materials */

		/* Create a scene node for the entity */
		/* The scene node keeps track of the entity's position */
        Ogre::SceneNode* scene_node = root_scene_node->createChildSceneNode(mesh_name);
        scene_node->attachObject(entity);

        /* Position and rotate the entity with the scene node */
		//scene_node->rotate(Ogre::Vector3(0, 1, 0), Ogre::Degree(60));
		//scene_node->rotate(Ogre::Vector3(1, 0, 0), Ogre::Degree(30));
		//scene_node->rotate(Ogre::Vector3(1, 0, 0), Ogre::Degree(-90));
        //scene_node->translate(0.0, 0.0, 0.0);
		scene_node->scale(0.5, 0.5, 0.5);
    }
    catch (Ogre::Exception &e){
        throw(OgreAppException(std::string("Ogre::Exception: ") + std::string(e.what())));
    }
    catch(std::exception &e){
        throw(OgreAppException(std::string("std::Exception: ") + std::string(e.what())));
    }
}