Exemplo n.º 1
0
//[NOTE] In addition to some Ogre setup, this function configures PagedGeometry in the scene.
void World::load()
{
	//-------------------------------------- LOAD TERRAIN --------------------------------------
	//Setup the fog up to 500 units away
	sceneMgr->setFog(FOG_LINEAR, viewport->getBackgroundColour(), 0, 100, 700);

	//Load the terrain
	sceneMgr->setWorldGeometry("terrain.cfg");

	//Start off with the camera at the center of the terrain
	camera->setPosition(700, 100, 700);

	//-------------------------------------- LOAD TREES --------------------------------------
	//Create and configure a new PagedGeometry instance
	trees = new PagedGeometry();
	trees->setCamera(camera);	//Set the camera so PagedGeometry knows how to calculate LODs
	trees->setPageSize(80);	//Set the size of each page of geometry
	trees->setInfinite();		//Use infinite paging mode
	trees->addDetailLevel<BatchPage>(150, 50);		//Use batches up to 150 units away, and fade for 30 more units
	trees->addDetailLevel<ImpostorPage>(500, 50);	//Use impostors up to 400 units, and for for 50 more units

	//Create a new TreeLoader2D object
	TreeLoader2D *treeLoader = new TreeLoader2D(trees, TBounds(0, 0, 1500, 1500));
	trees->setPageLoader(treeLoader);	//Assign the "treeLoader" to be used to load geometry for the PagedGeometry instance

	//Supply a height function to TreeLoader2D so it can calculate tree Y values
	HeightFunction::initialize(sceneMgr);
	treeLoader->setHeightFunction(&HeightFunction::getTerrainHeight);

	//Load a tree entity
	Entity *myEntity = sceneMgr->createEntity("Tree", "tree2.mesh");

	//Randomly place 20,000 copies of the tree on the terrain
	Vector3 position = Vector3::ZERO;
	Radian yaw;
	Real scale;
	for (int i = 0; i < 20000; i++){
		yaw = Degree(Math::RangeRandom(0, 360));

		position.x = Math::RangeRandom(0, 1500);
		position.z = Math::RangeRandom(0, 1500);

		scale = Math::RangeRandom(0.5f, 0.6f);

		//[NOTE] Unlike TreeLoader3D, TreeLoader2D's addTree() function accepts a Vector2D position (x/z)
		//The Y value is calculated during runtime (to save memory) from the height function supplied (above)
		treeLoader->addTree(myEntity, position, yaw, scale);
	}
}
Exemplo n.º 2
0
	void createScene()
	{
		Plane plane(Ogre::Vector3::UNIT_Y, -5);

		MeshManager::getSingleton().createPlane("plane", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, 1500, 1500, 200, 200, true, 1, 5, 5, Ogre::Vector3::UNIT_Z);
		
		Entity *ent = _sceneManager->createEntity("Sinbad.mesh");
		Entity *ground = _sceneManager->createEntity("LightPlaneEntity", "plane");
		
		_sceneManager->getRootSceneNode()->attachObject(ent);
		_sceneManager->getRootSceneNode()->attachObject(ground);

		// create light
		Light* light = _sceneManager->createLight("Light1");
		light->setType(Light::LT_DIRECTIONAL);
		light->setDirection(Ogre::Vector3(1, -1, 0));

		// some shadows would be nice
		_sceneManager->setShadowTechnique(SHADOWTYPE_STENCIL_ADDITIVE);

		ground->setMaterialName("Examples/BeachStones");

		_sceneManager->setAmbientLight(ColourValue(0.3f, 0.3f, 0.3f));
	}
Exemplo n.º 3
0
int main()
{
  Root *root = new Root(StringUtil::BLANK, StringUtil::BLANK);
  GLPlugin *glPlugin = new GLPlugin();
  root->installPlugin(glPlugin);
  RenderSystem *renderSystem = root->getAvailableRenderers().at(0);
  renderSystem->setConfigOption("Fixed Pipeline Enabled", "No");
  root->setRenderSystem(renderSystem);
  root->initialise(false);
  RenderWindow *window = root->createRenderWindow("Hello, OGRE", 800, 600, false);
  SceneManager *sceneManager = root->createSceneManager(ST_GENERIC);
  ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
  RTShader::ShaderGenerator::initialize();
  RTShader::ShaderGenerator::getSingleton().addSceneManager(sceneManager);

  createSphereMesh("SphereMesh", 10.f, 16, 16);
  ResourceGroupManager::getSingleton().addResourceLocation("shader", "FileSystem");
  createSphereMaterial("SphereMaterial", 1.f, 0.f, 0.f);

  Camera *camera = sceneManager->createCamera("Camera");
  camera->setPosition(0.f, 0.f, 80.f);
  camera->lookAt(0.f, 0.f, 0.f);
  camera->setNearClipDistance(5.f);
  Viewport *viewport = window->addViewport(camera);
  viewport->setBackgroundColour(ColourValue(0.f, 0.f, 0.f));
  viewport->setMaterialScheme(RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME);
  camera->setAspectRatio((Real)(viewport->getActualWidth()) / (Real)(viewport->getActualHeight()));

  sceneManager->setAmbientLight(ColourValue(0.5f, 0.5f, 0.5f));
  Light *light = sceneManager->createLight("Light");
  light->setPosition(50.f, 50.f, 50.f);

  Entity *sphereEntity = sceneManager->createEntity("SphereEntity", "SphereMesh");
  sphereEntity->setMaterialName("SphereMaterial");
  SceneNode *sphereNode = sceneManager->getRootSceneNode()->createChildSceneNode();
  sphereNode->attachObject(sphereEntity);

  HelloOgreFrameListener *frameListener = new HelloOgreFrameListener(window);
  root->addFrameListener(frameListener);
  root->startRendering();

  delete frameListener;
  delete root;
  delete glPlugin;

  return 0;
}
Exemplo n.º 4
0
void MeshCombiner::consoleMeshCombiner()
{
    StringVector vec = m_MeshCombinerConfig->getMultiSetting( "Mesh" );
    if( vec.empty() )
        return;

    MergeMesh* mm = new MergeMesh();
    SkeletonPtr skel = SkeletonPtr();

    for( StringVector::iterator it = vec.begin();
            it != vec.end(); ++it )
    {
        log( "Loading: " + *it );
        try
        {
            MeshPtr mesh = MeshManager::getSingleton().load(
                               *it, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME );

            if( !mesh.isNull() )
                mm->addMesh( mesh );
        }
        catch( ... )
        {
        }
    }

    // save
    MeshPtr mesh = mm->bake();

    MeshSerializer* meshSerializer = new MeshSerializer();
    meshSerializer->exportMesh( mesh.getPointer(), "./media/merged.mesh" );

    MeshManager::getSingleton().remove( mesh->getHandle() );

    // try to load...
    mesh = MeshManager::getSingleton().load(
               "merged.mesh", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME );

    SceneManager* sm = Root::getSingleton().createSceneManager( ST_GENERIC );

    // try to place...
    sm->getRootSceneNode()->attachObject( sm->createEntity( "test", "merged.mesh" ) );

    delete meshSerializer;
    delete mm;
}
Exemplo n.º 5
0
    void createScene(void){
        //making a plane
        Plane plane(Vector3::UNIT_Y, 0);//plane data type with plane paramters: at 0 distance from origin

        //using the mesh manager, we will create a plane, call it "groud", with an area of 1500 by 1500
        MeshManager::getSingleton().createPlane("ground", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, 1500,1500,20,20,true,1,5,5,Vector3::UNIT_Z);

        //tying the ground mesh to an entity and calling it Groundentity
        ent = mSceneMgr->createEntity("GroundEntity", "ground");
        //attaching a scene node to ent which is now holding the GroundEntity mesh
        node = mSceneMgr->getRootSceneNode()->createChildSceneNode("GroundNode");
        node->attachObject(ent);

        //adding a texture to the GroundEntity
        ent->setMaterialName("Examples/Rockwall");
        //we don't want the ground to cast a shadow since we are already casting a shadow on it...
        ent->setCastShadows(false);
    }
Exemplo n.º 6
0
    void SetUp() {
        RootWithoutRenderSystemFixture::SetUp();

        mSceneMgr = mRoot->createSceneManager();
        mCamera = mSceneMgr->createCamera("Camera");
        mCameraNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
        mCameraNode->attachObject(mCamera);
        mCameraNode->setPosition(0,0,500);
        mCameraNode->lookAt(Vector3(0, 0, 0), Node::TS_PARENT);

        // Create a set of random balls
        Entity* ent = mSceneMgr->createEntity("501", "sphere.mesh", "General");

        // stick one at the origin so one will always be hit by ray
        mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
        createRandomEntityClones(ent, 500, Vector3(-2500,-2500,-2500), Vector3(2500,2500,2500), mSceneMgr);

        mSceneMgr->_updateSceneGraph(mCamera);
    }
Exemplo n.º 7
0
TEST_F(Instancing, Bounds) {
    SceneManager* sceneMgr = SceneManagerEnumerator::getSingleton().createSceneManager(ST_GENERIC);
    Entity* entity = sceneMgr->createEntity("robot.mesh");

    MeshPtr mesh = entity->getMesh();
    InstanceBatchShader batch(NULL, mesh, entity->getSubEntity(0)->getMaterial(), 1, NULL, "");
    InstancedEntity instanced_entity(&batch, 0);

    SceneNode* node = sceneMgr->createSceneNode();
    node->attachObject(&instanced_entity);
    node->attachObject(entity);
    node->translate(Vector3::UNIT_X);
    node->setScale(Vector3(2, 2, 2));

    EXPECT_EQ(instanced_entity.getBoundingBox(), entity->getBoundingBox());
    EXPECT_EQ(instanced_entity.getBoundingRadius(), entity->getBoundingRadius());

    sceneMgr->destroyEntity(entity);
    MeshManager::getSingleton().remove(mesh->getHandle());
}
Exemplo n.º 8
0
//这个函数会在初始化调用
void FighterBase::doEnable(void)
{
	Orz::FCMovable::doEnable();
	using namespace Ogre;
	static int num = 0;
	//从系统中得到Ogre的场景管理器
	SceneManager * sm = OgreGraphicsManager::getSingleton().getSceneManager();
	int query = 1<<num;
	_bulletManager.reset(new BulletManager(sm, 20,  ~query));
	_node = sm->getRootSceneNode()->createChildSceneNode();
	_entity = sm->createEntity("FighterBase"+ Ogre::StringConverter::toString(num++), "ogrehead.mesh");
	_entity->setQueryFlags(query);
	_node->attachObject(_entity);
	_node->scale(0.5f,0.5f,0.5f);
	resetPosition();//_node->setPosition(_x *32.f - 240.f, 0.f, _y *32 - 240.f);


	patherSolve(15, 15);
	 _start = false;
	enableUpdate();
	_logic_initiate();


	FCMap * map = FCMap::getActiveMap();
	if(map)
	{
		map->setFighter(_fighterID, this);
	
	}
	
	_power = 50.f;
	_maxPower = 100.f;
	_fired = false;
	_fireTime = 0.f;

	_health = 500.f;
	
	_moved = false;
	_moveTime = 1.f;
	_moveAllTime = 1.f;
}
Exemplo n.º 9
0
bool WorldLoader::CreateTestWorld(Game *pGame)
{
	SceneManager * pSceneMgr = pGame->getRenderer()->getSceneManager();
 // PC: Note, ogre likes the shadow setup to happen first, because it affects the model loading?? weird.. check the manual
      // setup the shadow technique to use.. stencil does nice self-shadowing but its a bit slow.
      pSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_MODULATIVE);
      //mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_ADDITIVE);
      //pSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_MODULATIVE);
      //mSceneMgr->setShadowTextureSelfShadow(true);
      //pSceneMgr->setShadowTextureSize(1024);
      //mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_ADDITIVE);
      /*
      LiSPSMShadowCameraSetup* lispsm = new LiSPSMShadowCameraSetup();
		lispsm->setOptimalAdjustFactor(0.3);
		mSceneMgr->setShadowCameraSetup(ShadowCameraSetupPtr(lispsm));
		mSceneMgr->setShadowColour(ColourValue(0.5, 0.5, 0.5));
      */
	  srand(1027);
#ifdef _DEBUG
	  for(int i = 0; i < 20; i++)
#else
	  for(int i = 0; i < 2000; i++)
#endif
	  {
		CreateRandomRobot(pGame);
	  }
	  for(int i = 0; i < 4; i++)
	  {
		//CreateRandomBox(pGame);
	  }
		//CreateArena(pGame);
		//CreateCameraBox(pGame);
/*
		for(int i = 0; i < 40; i++)
	  {
		CreateRandomHouse(pGame);
	  }

		for(int i = 0; i < 40; i++)
	  {
		CreateRandomBarrel(pGame);
	  }
*/

#ifndef _TERRAIN_
      

      Plane plane(Vector3::UNIT_Y,0);
      MeshManager::getSingleton().createPlane("ground",ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
         plane,150000,150000,20,20,true,1,500,500,Vector3::UNIT_Z);

      Entity *ent = pSceneMgr->createEntity("GroundEntity", "ground");
      SceneNode* planeNode = pSceneMgr->getRootSceneNode()->createChildSceneNode();
      planeNode->attachObject(ent);
      //ent->setMaterialName("Examples/GrassFloor");
		ent->setMaterialName("PAC/Floor");
	  //ent->setMaterialName("PAC/Floor");
      ent->setCastShadows(false);
     
#else
      pSceneMgr->setWorldGeometry("terrain.cfg");
#endif


	  Viewport * pView  = pGame->getRenderer()->getRenderWindow()->getViewport(0);
      pView->setBackgroundColour(ColourValue(0.3f,0.3f,0.3f,1.0f));

      //pSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, 8);
      //pSceneMgr->setSkyBox(true,"Examples/CloudyNoonSkyBox",50);
      



      // Set ambient light
      pSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));

      // Create a light
      Light* l = pSceneMgr->createLight("MainLight");
      l->setType(Light::LightTypes::LT_DIRECTIONAL);
      Vector3 lightpos(20,140,50);
      Vector3 lightspot(0,0,0);
      Vector3 lightdir = lightspot - lightpos;
      l->setDirection(lightdir);
      l->setPosition(lightpos);

	return true;
};
Exemplo n.º 10
0
	void go(void)
	{
		// OGRE의 메인 루트 오브젝트 생성
#if !defined(_DEBUG)
		mRoot = new Root("plugins.cfg", "ogre.cfg", "ogre.log");
#else
		mRoot = new Root("plugins_d.cfg", "ogre.cfg", "ogre.log");
#endif


		// 초기 시작의 컨피규레이션 설정 - ogre.cfg 이용
		if (!mRoot->restoreConfig()) {
			if (!mRoot->showConfigDialog()) return;
		}

		mWindow = mRoot->initialise(true, "Walking Around Professor : Copyleft by Dae-Hyun Lee");


		// ESC key를 눌렀을 경우, 오우거 메인 렌더링 루프의 탈출을 처리
		size_t windowHnd = 0;
		std::ostringstream windowHndStr;
		OIS::ParamList pl;
		mWindow->getCustomAttribute("WINDOW", &windowHnd);
		windowHndStr << windowHnd;
		pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
		mInputManager = OIS::InputManager::createInputSystem(pl);
		mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject(OIS::OISKeyboard, false));


		mSceneMgr = mRoot->createSceneManager(ST_GENERIC, "main");
		mCamera = mSceneMgr->createCamera("main");


		mCamera->setPosition(0.0f, 100.0f, 500.0f);
		mCamera->lookAt(0.0f, 100.0f, 0.0f);

		mCamera->setNearClipDistance(5.0f);

		mViewport = mWindow->addViewport(mCamera);
		mViewport->setBackgroundColour(ColourValue(0.0f, 0.0f, 0.5f));
		mCamera->setAspectRatio(Real(mViewport->getActualWidth()) / Real(mViewport->getActualHeight()));


		ResourceGroupManager::getSingleton().addResourceLocation("resource.zip", "Zip");
		ResourceGroupManager::getSingleton().initialiseAllResourceGroups();

		mSceneMgr->setAmbientLight(ColourValue(1.0f, 1.0f, 1.0f));

		// 좌표축 표시
		Ogre::Entity* mAxesEntity = mSceneMgr->createEntity("Axes", "axes.mesh");
		mSceneMgr->getRootSceneNode()->createChildSceneNode("AxesNode", Ogre::Vector3(0, 0, 0))->attachObject(mAxesEntity);
		mSceneMgr->getSceneNode("AxesNode")->setScale(5, 5, 5);

		_drawGridPlane();


		Entity* entity1 = mSceneMgr->createEntity("Professor", "DustinBody.mesh");
		SceneNode* node1 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Professor", Vector3(0.0f, 0.0f, 0.0f));
		node1->attachObject(entity1);

		mESCListener = new ESCListener(mKeyboard);
		mRoot->addFrameListener(mESCListener);

		mMainListener = new MainListener(mRoot, mKeyboard);
		mRoot->addFrameListener(mMainListener);


		mRoot->startRendering();

		mInputManager->destroyInputObject(mKeyboard);
		OIS::InputManager::destroyInputSystem(mInputManager);

		delete mRoot;
	}
Exemplo n.º 11
0
//[NOTE] In addition to some Ogre setup, this function configures PagedGeometry in the scene.
void World::load()
{
	//-------------------------------------- LOAD TERRAIN --------------------------------------
	//Setup the fog up to 500 units away
	sceneMgr->setFog(FOG_LINEAR, viewport->getBackgroundColour(), 0, 100, 700);

	//Load the terrain
	sceneMgr->setWorldGeometry("terrain.cfg");

	//Start off with the camera at the center of the terrain
	camera->setPosition(700, 100, 700);
	
	//-------------------------------------- LOAD TREES --------------------------------------
	//Create and configure a new PagedGeometry instance for trees
	trees = new PagedGeometry(camera, 80);
	trees->addDetailLevel<BatchPage>(150, 50);
	trees->addDetailLevel<ImpostorPage>(500, 50);

	//Create a new TreeLoader2D object
	TreeLoader2D *treeLoader = new TreeLoader2D(trees, TBounds(0, 0, 1500, 1500));
	trees->setPageLoader(treeLoader);

	//Supply the height function to TreeLoader2D so it can calculate tree Y values
	HeightFunction::initialize(sceneMgr);
	treeLoader->setHeightFunction(&HeightFunction::getTerrainHeight);

	//Load a tree entity
	Entity *myTree = sceneMgr->createEntity("Tree", "tree2.mesh");

	//Randomly place 10,000 copies of the tree on the terrain
	Vector3 position = Vector3::ZERO;
	Radian yaw;
	Real scale;
	for (int i = 0; i < 10000; i++){
		yaw = Degree(Math::RangeRandom(0, 360));
		position.x = Math::RangeRandom(0, 1500);
		position.z = Math::RangeRandom(0, 1500);
		scale = Math::RangeRandom(0.5f, 0.6f);

		treeLoader->addTree(myTree, position, yaw, scale);
	}

	//-------------------------------------- LOAD BUSHES --------------------------------------
	//Create and configure a new PagedGeometry instance for bushes
	bushes = new PagedGeometry(camera, 50);
	bushes->addDetailLevel<BatchPage>(80, 50);

	//Create a new TreeLoader2D object for the bushes
	TreeLoader2D *bushLoader = new TreeLoader2D(bushes, TBounds(0, 0, 1500, 1500));
	bushes->setPageLoader(bushLoader);

	//Supply the height function to TreeLoader2D so it can calculate tree Y values
	HeightFunction::initialize(sceneMgr);
	bushLoader->setHeightFunction(&HeightFunction::getTerrainHeight);

	//Load a bush entity
	Entity *myBush = sceneMgr->createEntity("Bush", "Bush.mesh");

	//Randomly place 30,000 copies of the bush on the terrain
	for (int i = 0; i < 30000; i++){
		yaw = Degree(Math::RangeRandom(0, 360));
		position.x = Math::RangeRandom(0, 1500);
		position.z = Math::RangeRandom(0, 1500);
		scale = Math::RangeRandom(0.7f, 0.8f);

		bushLoader->addTree(myBush, position, yaw, scale);
	}
}
Exemplo n.º 12
0
//[NOTE] In addition to some Ogre setup, this function configures PagedGeometry in the scene.
void World::load()
{
	//-------------------------------------- LOAD TERRAIN --------------------------------------
	//Setup the fog up to 1500 units away
	sceneMgr->setFog(FOG_LINEAR, viewport->getBackgroundColour(), 0, 100, 900);

	//Load the terrain
	sceneMgr->setWorldGeometry("terrain2.cfg");

	//Start off with the camera at the center of the terrain
	camera->setPosition(700, 100, 700);

	//Setup a skybox
	sceneMgr->setSkyBox(true, "3D-Diggers/SkyBox", 2000);

	//-------------------------------------- LOAD GRASS --------------------------------------
	//Create and configure a new PagedGeometry instance for grass
	grass = new PagedGeometry(camera, 30);
	grass->addDetailLevel<GrassPage>(60);

	//Create a GrassLoader object
	grassLoader = new GrassLoader(grass);
	grass->setPageLoader(grassLoader);	//Assign the "treeLoader" to be used to load geometry for the PagedGeometry instance

	//Supply a height function to GrassLoader so it can calculate grass Y values
	HeightFunction::initialize(sceneMgr);
	grassLoader->setHeightFunction(&HeightFunction::getTerrainHeight);

	//Add some grass to the scene with GrassLoader::addLayer()
	GrassLayer *l = grassLoader->addLayer("3D-Diggers/plant1sprite");

	//Configure the grass layer properties (size, density, animation properties, fade settings, etc.)
	l->setMinimumSize(0.7f, 0.7f);
	l->setMaximumSize(0.9f, 0.9f);
	l->setAnimationEnabled(true);		//Enable animations
	l->setSwayDistribution(7.0f);		//Sway fairly unsynchronized
	l->setSwayLength(0.1f);				//Sway back and forth 0.5 units in length
	l->setSwaySpeed(0.4f);				//Sway 1/2 a cycle every second
	l->setDensity(3.0f);				//Relatively dense grass
	l->setRenderTechnique(GRASSTECH_SPRITE);
	l->setFadeTechnique(FADETECH_GROW);	//Distant grass should slowly raise out of the ground when coming in range

	//[NOTE] This sets the color map, or lightmap to be used for grass. All grass will be colored according
	//to this texture. In this case, the colors of the terrain is used so grass will be shadowed/colored
	//just as the terrain is (this usually makes the grass fit in very well).
	l->setColorMap("terrain_texture2.jpg");

	//This sets the density map that will be used to determine the density levels of grass all over the
	//terrain. This can be used to make grass grow anywhere you want to; in this case it's used to make
	//grass grow only on fairly level ground (see densitymap.png to see how this works).
	l->setDensityMap("densitymap.png");

	//setMapBounds() must be called for the density and color maps to work (otherwise GrassLoader wouldn't
	//have any knowledge of where you want the maps to be applied). In this case, the maps are applied
	//to the same boundaries as the terrain.
	l->setMapBounds(TBounds(0, 0, 1500, 1500));	//(0,0)-(1500,1500) is the full boundaries of the terrain

	//-------------------------------------- LOAD TREES --------------------------------------
	//Create and configure a new PagedGeometry instance
	trees = new PagedGeometry();
	trees->setCamera(camera);	//Set the camera so PagedGeometry knows how to calculate LODs
	trees->setPageSize(50);	//Set the size of each page of geometry
	trees->setInfinite();		//Use infinite paging mode

#ifdef WIND
	//WindBatchPage is a variation of BatchPage which includes a wind animation shader
	trees->addDetailLevel<WindBatchPage>(90, 30);		//Use batches up to 150 units away, and fade for 30 more units
#else
	trees->addDetailLevel<BatchPage>(90, 30);		//Use batches up to 150 units away, and fade for 30 more units
#endif
	trees->addDetailLevel<ImpostorPage>(700, 50);	//Use impostors up to 400 units, and for for 50 more units

	//Create a new TreeLoader2D object
	TreeLoader2D *treeLoader = new TreeLoader2D(trees, TBounds(0, 0, 1500, 1500));
	trees->setPageLoader(treeLoader);	//Assign the "treeLoader" to be used to load geometry for the PagedGeometry instance

	//Supply a height function to TreeLoader2D so it can calculate tree Y values
	HeightFunction::initialize(sceneMgr);
	treeLoader->setHeightFunction(&HeightFunction::getTerrainHeight);

	//[NOTE] This sets the color map, or lightmap to be used for trees. All trees will be colored according
	//to this texture. In this case, the shading of the terrain is used so trees will be shadowed
	//just as the terrain is (this should appear like the terrain is casting shadows on the trees).
	//You may notice that TreeLoader2D / TreeLoader3D doesn't have a setMapBounds() function as GrassLoader
	//does. This is because the bounds you specify in the TreeLoader2D constructor are used to apply
	//the color map.
	treeLoader->setColorMap("terrain_lightmap.jpg");

	//Load a tree entity
	Entity *tree1 = sceneMgr->createEntity("Tree1", "fir05_30.mesh");

	Entity *tree2 = sceneMgr->createEntity("Tree2", "fir14_25.mesh");

#ifdef WIND
	trees->setCustomParam(tree1->getName(), "windFactorX", 15);
	trees->setCustomParam(tree1->getName(), "windFactorY", 0.01);
	trees->setCustomParam(tree2->getName(), "windFactorX", 22);
	trees->setCustomParam(tree2->getName(), "windFactorY", 0.013);
#endif

	//Randomly place 10000 copies of the tree on the terrain
	Ogre::Vector3 position = Ogre::Vector3::ZERO;
	Radian yaw;
	Real scale;
	for (int i = 0; i < 10000; i++){
		yaw = Degree(Math::RangeRandom(0, 360));

		position.x = Math::RangeRandom(0, 1500);
		position.z = Math::RangeRandom(0, 1500);

		scale = Math::RangeRandom(0.07f, 0.12f);

		float rnd = Math::UnitRandom();
		if (rnd < 0.5f)
		{
		//[NOTE] Unlike TreeLoader3D, TreeLoader2D's addTree() function accepts a Vector2D position (x/z)
		//The Y value is calculated during runtime (to save memory) from the height function supplied (above)
		if (Math::UnitRandom() < 0.5f)
			treeLoader->addTree(tree1, position, yaw, scale);
		//else
		//	treeLoader->addTree(tree2, position, yaw, scale);
		}
		else
			treeLoader->addTree(tree2, position, yaw, scale);
	}

	//-------------------------------------- LOAD BUSHES --------------------------------------
	//Create and configure a new PagedGeometry instance for bushes
	bushes = new PagedGeometry(camera, 50);

#ifdef WIND
	bushes->addDetailLevel<WindBatchPage>(80, 50);
#else
	bushes->addDetailLevel<BatchPage>(80, 50);
#endif

	//Create a new TreeLoader2D object for the bushes
	TreeLoader2D *bushLoader = new TreeLoader2D(bushes, TBounds(0, 0, 1500, 1500));
	bushes->setPageLoader(bushLoader);

	//Supply the height function to TreeLoader2D so it can calculate tree Y values
	HeightFunction::initialize(sceneMgr);
	bushLoader->setHeightFunction(&HeightFunction::getTerrainHeight);

	bushLoader->setColorMap("terrain_lightmap.jpg");

	//Load a bush entity
	Entity *fern = sceneMgr->createEntity("Fern", "farn1.mesh");

	Entity *plant = sceneMgr->createEntity("Plant", "plant2.mesh");

	Entity *mushroom = sceneMgr->createEntity("Mushroom", "shroom1_1.mesh");

#ifdef WIND
	bushes->setCustomParam(fern->getName(), "factorX", 1);
	bushes->setCustomParam(fern->getName(), "factorY", 0.01);

	bushes->setCustomParam(plant->getName(), "factorX", 0.6);
	bushes->setCustomParam(plant->getName(), "factorY", 0.02);
#endif

	//Randomly place 20,000 bushes on the terrain
	for (int i = 0; i < 20000; i++){
		yaw = Degree(Math::RangeRandom(0, 360));
		position.x = Math::RangeRandom(0, 1500);
		position.z = Math::RangeRandom(0, 1500);

		float rnd = Math::UnitRandom();
		if (rnd < 0.8f) {
			scale = Math::RangeRandom(0.3f, 0.4f);
			bushLoader->addTree(fern, position, yaw, scale);
		} else if (rnd < 0.9) {
			scale = Math::RangeRandom(0.2f, 0.6f);
			bushLoader->addTree(mushroom, position, yaw, scale);
		} else {
			scale = Math::RangeRandom(0.3f, 0.5f);
			bushLoader->addTree(plant, position, yaw, scale);
		}
	}

}
Exemplo n.º 13
0
//这个函数会在初始化调用
void FCScene::doEnable(void)
{
	
	_map->active();
	using namespace Ogre;
	//从系统中得到Ogre的场景管理器
	SceneManager * sm = OgreGraphicsManager::getSingleton().getSceneManager();

	//把其场景清空
	sm->clearScene();
	
	
	Plane plane;
	plane.normal = Vector3::UNIT_Y;
	plane.d = 100;
	FCKnowledge::getSingleton().mapInfo().setGround(-plane.d);
	FCKnowledge::getSingleton().mapInfo().enable();
	MeshManager::getSingleton().createPlane("Myplane",
		ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
		512, 512,20,20,true,1,60,60,Vector3::UNIT_Z);
	Ogre::Entity* pPlaneEnt = sm->createEntity( "plane", "Myplane" );
	pPlaneEnt->setMaterialName("Examples/Rockwall");
	pPlaneEnt->setQueryFlags(0);
	sm->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);

	//设置环境光
	sm->setAmbientLight(ColourValue(0.5, 0.5, 0.5));

	//创建天空盒
	//sm->setSkyBox(true, "Examples/SpaceSkyBox", 50 );

	// 创建一个光源
	Light* l = sm->createLight("MainLight");

	//设置光源位置
	l->setPosition(20,80,50);


	//下面代码随机 放置砖块
	NameValueList par;
	for(int i = 1; i< 16 *16; ++i)
	{
		if(rand()%2 == 0)
		{
			par["pos"] = i;
			ActorPtr wall = Orz::GameFactories::getInstance().createActor("FCWall",IDManager::BLANK, &par );
			getWorld()->comeIn(wall);
			_walls.push_back(wall);
		}
	}

	//在这里我们通过XML文件FighteingClub.xml 得到两个格斗者的名字,然后创建他们 并给他们位置和ID
	XMLFighterLoader loader;
	if(loader.load("FighteingClub.xml"))
	{
		{
			par["pos"] = 10;
			par["id"] = 0;
			ActorPtr fighter = Orz::GameFactories::getInstance().createActor(loader.getFighter1(),IDManager::BLANK, &par );
			getWorld()->comeIn(fighter);
			_enemies.push_back(fighter);
			
		}
		{
			par["pos"] = 20;
			
			par["id"] = 1;
			ActorPtr fighter = Orz::GameFactories::getInstance().createActor(loader.getFighter2(),IDManager::BLANK, &par );
			getWorld()->comeIn(fighter);
		_enemies.push_back(fighter);
		}
	}
	else//如果XML读取失败 那么就采用默认的 "FCFighter"
	{
		for(int i =0; i<2; ++i)
		{
			
			par["id"] = i;
			par["pos"] = i*10;
			ActorPtr fighter = Orz::GameFactories::getInstance().createActor("FCFighter",IDManager::BLANK, &par );
			getWorld()->comeIn(fighter);
			_enemies.push_back(fighter);
		}
	}
}
Exemplo n.º 14
0
	//-----------------------------------------------------------------------
	void Shadows::createTestScene(bool useOgreMaterials)
	{		
		Ogre::String planeMatName, knotMatName;
		
		if(useOgreMaterials)
		{
			planeMatName = "PSSM/Plane";
			knotMatName  = "PSSM/Knot";
		}
		else 
		{
			planeMatName = "PSSMPlane";
			knotMatName  = "PSSMKnot";
		}		
		
        // temp 
        planeMatName = "ESM/Plane";
        knotMatName  = "ESM/Knot";
        
        SceneManager* sceneMgr = getSceneManager();		

        
        
        /*
		sceneMgr->setAmbientLight(ColourValue(0.3, 0.3, 0.3));
		Light* l = sceneMgr->createLight("Spot");
		l->setType(Light::LT_SPOTLIGHT);
		Vector3 dir(0.3, -1, 0.2);
		dir.normalise();
		l->setDirection(dir);
		l->setDiffuseColour(ColourValue(1.0, 1.0, 0.0, 1));
        l->setPosition(0, 25.0, 2.0);
        l->setSpotlightRange((Radian) 0.104, (Radian) 1.40, 1);
        l->setAttenuation(50, 1.0, 0.009, 0.0032);
        */
        


		// Create a basic plane to have something in the scene to look at
		Plane plane;
		plane.normal = Vector3::UNIT_Y;
		plane.d = 100;
		MeshPtr msh = MeshManager::getSingleton().createPlane("Myplane",
															  ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
															  4500,4500,100,100,true,1,40,40,Vector3::UNIT_Z);
		msh->buildTangentVectors(VES_TANGENT);
		Entity* pPlaneEnt;
		pPlaneEnt = sceneMgr->createEntity( "plane", "Myplane" );
		pPlaneEnt->setMaterialName(planeMatName);
		sceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);


		Entity* ent = sceneMgr->createEntity("knot", "knot.mesh");
        ent->setMaterialName(knotMatName);
		createRandomEntityClones(ent, 20, Vector3(-100,0,-100), Vector3(100,0,100));

        SceneNode* node = sceneMgr->getRootSceneNode()->createChildSceneNode();
        node->attachObject(ent);
        //node->setPosition(Vector3(0, 0, 0));
        
        for(int i=0; i<sceneMgr->getRootSceneNode()->numChildren(); i++)
        {
            Node* node = sceneMgr->getRootSceneNode()->getChild(i);
            node->setScale(0.05f, 0.05f, 0.05f);
        }
	}
Exemplo n.º 15
0
	void go(void)
	{
		// OGRE의 메인 루트 오브젝트 생성
#if !defined(_DEBUG)
		mRoot = new Root("plugins.cfg", "ogre.cfg", "ogre.log");
#else
		mRoot = new Root("plugins_d.cfg", "ogre.cfg", "ogre.log");
#endif


		// 초기 시작의 컨피규레이션 설정 - ogre.cfg 이용
		if (!mRoot->restoreConfig()) {
			if (!mRoot->showConfigDialog()) return;
		}

		mWindow = mRoot->initialise(true, CLIENT_DESCRIPTION " : Copyleft by Dae-Hyun Lee");

		mSceneMgr = mRoot->createSceneManager(ST_GENERIC, "main");
		mCamera = mSceneMgr->createCamera("main");


		mCamera->setPosition(0.0f, 150.0f, 1000.0f);
		mCamera->lookAt(0.0f, 100.0f, 0.0f);

		mViewport = mWindow->addViewport(mCamera);
		mViewport->setBackgroundColour(ColourValue(0.0f, 0.0f, 0.5f));
		mCamera->setAspectRatio(Real(mViewport->getActualWidth()) / Real(mViewport->getActualHeight()));


		ResourceGroupManager::getSingleton().addResourceLocation("resource.zip", "Zip");
		ResourceGroupManager::getSingleton().initialiseAllResourceGroups();

		mSceneMgr->setAmbientLight(ColourValue(1.0f, 1.0f, 1.0f));

		// 좌표축 표시
		Ogre::Entity* mAxesEntity = mSceneMgr->createEntity("Axes", "axes.mesh");
		mSceneMgr->getRootSceneNode()->createChildSceneNode("AxesNode", Ogre::Vector3(0, 0, 0))->attachObject(mAxesEntity);
		mSceneMgr->getSceneNode("AxesNode")->setScale(5, 5, 5);

		_drawGridPlane();


		Entity* entity1 = mSceneMgr->createEntity("Ninja", "ninja.mesh");
		SceneNode* node1 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Ninja", Vector3(-100.0f, 0.0f, 0.0f));
		node1->attachObject(entity1);

		Entity* entity2 = mSceneMgr->createEntity("Professor", "DustinBody.mesh");
		SceneNode* node2 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Professor", Vector3(200.0f, 0.0f, 200.0f));
		node2->attachObject(entity2);


#if 0
		Entity* entity2 = mSceneMgr->createEntity("Ninja", "ninja.mesh");
		SceneNode* node2 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Ninja", Vector3(0.0f, 0.0f, 0.0f));
		node2->attachObject(entity2);
		node2->setOrientation(Ogre::Quaternion(Ogre::Degree(180), Ogre::Vector3::UNIT_Y));
#endif

		size_t windowHnd = 0;
		std::ostringstream windowHndStr;
		OIS::ParamList pl;
		mWindow->getCustomAttribute("WINDOW", &windowHnd);
		windowHndStr << windowHnd;
		pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
		pl.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_FOREGROUND")));
		pl.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_NONEXCLUSIVE")));
		pl.insert(std::make_pair(std::string("w32_keyboard"), std::string("DISCL_FOREGROUND")));
		pl.insert(std::make_pair(std::string("w32_keyboard"), std::string("DISCL_NONEXCLUSIVE")));
		mInputManager = OIS::InputManager::createInputSystem(pl);


		mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject(OIS::OISKeyboard, true));
		mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject(OIS::OISMouse, true));

		InputController* inputController = new InputController(mRoot, mKeyboard, mMouse);
		mRoot->addFrameListener(inputController);


		ProfessorController* professorController = new ProfessorController(mRoot);
		mRoot->addFrameListener(professorController);

		mRoot->startRendering();

		mInputManager->destroyInputObject(mKeyboard);
		mInputManager->destroyInputObject(mMouse);
		OIS::InputManager::destroyInputSystem(mInputManager);

		delete professorController;
		delete inputController;

		delete mRoot;
	}
Exemplo n.º 16
0
//[NOTE] In addition to some Ogre setup, this function configures PagedGeometry in the scene.
void World::load()
{
	//-------------------------------------- LOAD TERRAIN --------------------------------------
	//Setup the fog up to 500 units away
	sceneMgr->setFog(FOG_LINEAR, viewport->getBackgroundColour(), 0, 100, 700);

	//Load the terrain
	auto terrain = loadLegacyTerrain("terrain2.cfg", sceneMgr);

	//Start off with the camera at the center of the terrain
	cameraNode->setPosition(700, 100, 700);

	//-------------------------------------- LOAD GRASS --------------------------------------
	//Create and configure a new PagedGeometry instance for grass
	grass = new PagedGeometry(camera, 50);
	grass->addDetailLevel<GrassPage>(100);

	//Create a GrassLoader object
	grassLoader = new GrassLoader(grass);
	grass->setPageLoader(grassLoader);	//Assign the "treeLoader" to be used to load geometry for the PagedGeometry instance

	//Supply a height function to GrassLoader so it can calculate grass Y values
	HeightFunction::initialize(terrain);
	grassLoader->setHeightFunction(&HeightFunction::getTerrainHeight);

	//Add some grass to the scene with GrassLoader::addLayer()
	GrassLayer *l = grassLoader->addLayer("grass");

	//Configure the grass layer properties (size, density, animation properties, fade settings, etc.)
	l->setMinimumSize(2.0f, 1.5f);
	l->setMaximumSize(2.5f, 1.9f);
	l->setAnimationEnabled(true);		//Enable animations
	l->setSwayDistribution(10.0f);		//Sway fairly unsynchronized
	l->setSwayLength(0.5f);				//Sway back and forth 0.5 units in length
	l->setSwaySpeed(0.5f);				//Sway 1/2 a cycle every second
	l->setDensity(2.0f);				//Relatively dense grass
	l->setFadeTechnique(FADETECH_GROW);	//Distant grass should slowly raise out of the ground when coming in range

	//[NOTE] This sets the color map, or lightmap to be used for grass. All grass will be colored according
	//to this texture. In this case, the colors of the terrain is used so grass will be shadowed/colored
	//just as the terrain is (this usually makes the grass fit in very well).
	l->setColorMap("terrain_texture2.jpg");

	//This sets the density map that will be used to determine the density levels of grass all over the
	//terrain. This can be used to make grass grow anywhere you want to; in this case it's used to make
	//grass grow only on fairly level ground (see densitymap.png to see how this works).
	l->setDensityMap("densitymap.png");

	//setMapBounds() must be called for the density and color maps to work (otherwise GrassLoader wouldn't
	//have any knowledge of where you want the maps to be applied). In this case, the maps are applied
	//to the same boundaries as the terrain.
	l->setMapBounds(TBounds(0, 0, 1500, 1500));	//(0,0)-(1500,1500) is the full boundaries of the terrain

	//-------------------------------------- LOAD TREES --------------------------------------
	//Create and configure a new PagedGeometry instance
	trees = new PagedGeometry();
	trees->setCamera(camera);	//Set the camera so PagedGeometry knows how to calculate LODs
	trees->setPageSize(80);	//Set the size of each page of geometry
	trees->setInfinite();		//Use infinite paging mode
	trees->addDetailLevel<BatchPage>(150, 50);		//Use batches up to 150 units away, and fade for 30 more units
	trees->addDetailLevel<ImpostorPage>(500, 50);	//Use impostors up to 400 units, and for for 50 more units

	//Create a new TreeLoader2D object
	TreeLoader2D *treeLoader = new TreeLoader2D(trees, TBounds(0, 0, 1500, 1500));
	trees->setPageLoader(treeLoader);	//Assign the "treeLoader" to be used to load geometry for the PagedGeometry instance

	//Supply a height function to TreeLoader2D so it can calculate tree Y values
	treeLoader->setHeightFunction(&HeightFunction::getTerrainHeight);

	//[NOTE] This sets the color map, or lightmap to be used for trees. All trees will be colored according
	//to this texture. In this case, the shading of the terrain is used so trees will be shadowed
	//just as the terrain is (this should appear like the terrain is casting shadows on the trees).
	//You may notice that TreeLoader2D / TreeLoader3D doesn't have a setMapBounds() function as GrassLoader
	//does. This is because the bounds you specify in the TreeLoader2D constructor are used to apply
	//the color map.
	treeLoader->setColorMap("terrain_lightmap.jpg");

	//Load a tree entity
	Entity *myEntity = sceneMgr->createEntity("Tree", "tree2.mesh");

	//Randomly place 20,000 copies of the tree on the terrain
	Ogre::Vector3 position = Ogre::Vector3::ZERO;
	Radian yaw;
	Real scale;
	for (int i = 0; i < 20000; i++){
		yaw = Degree(Math::RangeRandom(0, 360));

		position.x = Math::RangeRandom(0, 1500);
		position.z = Math::RangeRandom(0, 1500);

		scale = Math::RangeRandom(0.9f, 1.1f);

		//[NOTE] Unlike TreeLoader3D, TreeLoader2D's addTree() function accepts a Vector2D position (x/z)
		//The Y value is calculated during runtime (to save memory) from the height function supplied (above)
		treeLoader->addTree(myEntity, position, yaw, scale);
	}
}
Exemplo n.º 17
0
INT WINAPI EmbeddedMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
{
	try 
	{
		// Create a new window

		// Style & size
		DWORD dwStyle = WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_OVERLAPPEDWINDOW;

		// Register the window class
		WNDCLASS wc = { 0, TestWndProc, 0, 0, hInst,
			LoadIcon(0, IDI_APPLICATION), LoadCursor(NULL, IDC_ARROW),
			(HBRUSH)GetStockObject(BLACK_BRUSH), 0, "TestWnd" };
		RegisterClass(&wc);

		HWND hwnd = CreateWindow("TestWnd", "Test embedding", dwStyle,
				0, 0, 800, 600, 0, 0, hInst, 0);

		Root root("", "");

		root.loadPlugin("RenderSystem_GL");
		//root.loadPlugin("RenderSystem_Direct3D9");
		root.loadPlugin("Plugin_ParticleFX");
		root.loadPlugin("Plugin_CgProgramManager");

		// select first renderer & init with no window
		root.setRenderSystem(*(root.getAvailableRenderers().begin()));
		root.initialise(false);

		// create first window manually
		NameValuePairList options;
		options["externalWindowHandle"] = 
			StringConverter::toString((size_t)hwnd);

		renderWindow = root.createRenderWindow("embedded", 800, 600, false, &options);

		setupResources();
		ResourceGroupManager::getSingleton().initialiseAllResourceGroups();

		SceneManager *scene = root.createSceneManager(Ogre::ST_GENERIC, "default");


		Camera *cam = scene->createCamera("cam");


		Viewport* vp = renderWindow->addViewport(cam);
		vp->setBackgroundColour(Ogre::ColourValue(0.5, 0.5, 0.7));
		cam->setAutoAspectRatio(true);
		cam->setPosition(0,0,300);
		cam->setDirection(0,0,-1);

		Entity* e = scene->createEntity("1", "ogrehead.mesh");
		scene->getRootSceneNode()->createChildSceneNode()->attachObject(e);
		Light* l = scene->createLight("l");
		l->setPosition(300, 100, -100);

		// message loop
		MSG msg;
		while(GetMessage(&msg, NULL, 0, 0 ) != 0)
		{ 
			TranslateMessage(&msg); 
			DispatchMessage(&msg); 
		} 

	} 
	catch( Exception& e ) 
	{
		MessageBox( NULL, e.getFullDescription().c_str(), 
			"An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
	}


	return 0;
}