ogre一些代码(人物 动作 地形 粒子系统)ogre例子的改写
2013-11-19 23:10
573 查看
/*
-----------------------------------------------------------------------------
This source file is part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/
Copyright (c) 2000-2012 Torus Knot Software Ltd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/
#include "OgrePlatform.h"
#include "SampleBrowser.h"
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
#include "OgreString.h"
#elif OGRE_PLATFORM == OGRE_PLATFORM_APPLE
#include "SampleBrowser_OSX.h"
#elif OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS
#include "SampleBrowser_iOS.h"
#elif OGRE_PLATFORM == OGRE_PLATFORM_NACL
#include "SampleBrowser_NaCl.h"
#endif
#include "OgreTerrain.h"
#include "OgreTerrainGroup.h"
#if OGRE_PLATFORM != OGRE_PLATFORM_NACL
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
INT WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR cmdLine, INT)
#else
int main(int argc, char *argv[])
#endif
{
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, @"UIApplication", @"AppDelegate");
[pool release];
return retVal;
#elif (OGRE_PLATFORM == OGRE_PLATFORM_APPLE) && __LP64__
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
mAppDelegate = [[AppDelegate alloc] init];
[[NSApplication sharedApplication] setDelegate:mAppDelegate];
int retVal = NSApplicationMain(argc, (const char **) argv);
[pool release];
return retVal;
#else
try
{
bool nograb = false;
#if OGRE_PLATFORM != OGRE_PLATFORM_WIN32
if (argc >= 2 && Ogre::String(argv[1]) == "nograb")
nograb = true;
#else
// somewhat hacky, but much simpler than other solutions
if (Ogre::String(cmdLine).find("nograb") != Ogre::String::npos)
nograb = true;
#endif
//OgreBites::SampleBrowser brows (nograb);
//brows.go();
//if(0)
//return 0;
//create root
Ogre::Root* rt=new Ogre::Root("C:\\workspace\\ogre\\ogre4vs2010\\MyOgre\\Debug\\plugins.cfg",
"C:\\workspace\\ogre\\ogre4vs2010\\MyOgre\\Debug\\ogre.cfg",
"C:\\workspace\\ogre\\ogre4vs2010\\MyOgre\\Debug\\ogre.log");
if(!rt->restoreConfig())
rt->showConfigDialog();
//create window
Ogre::RenderWindow* rw=rt->initialise(true);
size_t winHandler=0;
rw->getCustomAttribute("WINDOW",&winHandler);
rw->setAutoUpdated(true);
//create input system
std::ostringstream winHandlerStr;
winHandlerStr<<winHandler;
OIS::ParamList pl;
pl.insert(std::make_pair("WINDOW",winHandlerStr.str()));
OIS::InputManager* im=OIS::InputManager::createInputSystem(pl);
/**Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
"C:\\workspace\\ogre\\ogre4vs2010\\OgreSDK_vc10_v1-8-1\\media\\models"
,"FileSystem"
,"models");
Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
"C:\\workspace\\ogre\\ogre4vs2010\\OgreSDK_vc10_v1-8-1\\media\\materials\\scripts"
,"FileSystem"
,"materials");
**/
Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
"C:\\workspace\\ogre\\ogre4vs2010\\OgreSDK_vc10_v1-8-1\\media\\materials\\textures"
,"FileSystem"
,Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
"C:\\workspace\\ogre\\ogre4vs2010\\OgreSDK_vc10_v1-8-1\\media\\materials\\textures\\nvidia"
,"FileSystem"
,Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
"C:\\ogremaxexport"
,"FileSystem"
,"dc");
Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
Ogre::ResourceGroupManager::getSingleton().loadResourceGroup("dc");
//Ogre::ResourceGroupManager::getSingleton().loadResourceGroup(Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
Ogre::StringVectorPtr dc=Ogre::ResourceGroupManager::getSingleton().listResourceNames("dc");
Ogre::StringVectorPtr ds=Ogre::ResourceGroupManager::getSingleton().listResourceLocations("dc");
//Ogre::MaterialManager.
/**
Ogre::OverlayManager& om=Ogre::OverlayManager::getSingleton();
Ogre::Overlay* ol=om.create("test");
Ogre::OverlayContainer* testPanel=(Ogre::OverlayContainer*)om.createOverlayElementFromTemplate("SdkTrays/Cursor","","");
testPanel->setMaterialName("BaseWhite");
ol->add2D(testPanel);
ol->setZOrder(10);
ol->show();
**/
/**
Ogre::Overlay* overlay=om.create("overlay");
overlay->setZOrder(100);
Ogre::OverlayContainer* ole=(Ogre::OverlayContainer*)om.createOverlayElement("Panel","Backdrop");
overlay->add2D(ole);
overlay->show();
**/
rw->removeAllViewports();
//create scenemanager and camera
Ogre::SceneManager* sm=rt->createSceneManager(Ogre::ST_GENERIC,"testScence");
Ogre::Camera* oc=sm->createCamera("testCamera");
/**
oc->setNearClipDistance(0.1);
oc->setPosition(-3,0,0);
oc->lookAt(1,0,0);
**/
Ogre::Viewport* ovp=rw->addViewport(oc);
ovp->setBackgroundColour(Ogre::ColourValue(0.8f, 0.8f, 0.8f));
//sm->setFog(Ogre::FOG_LINEAR, Ogre::ColourValue(0.2f, 0.2f, 0.2f), 0, 15, 100);
/**
//save camera status
Ogre::NameValuePairList state;
state["CameraPosition"] = Ogre::StringConverter::toString(oc->getPosition());
state["CameraOrientation"] = Ogre::StringConverter::toString(oc->getOrientation());
oc->setPosition(Ogre::StringConverter::parseVector3(state["CameraPosition"]));
oc->setOrientation(Ogre::StringConverter::parseQuaternion(state["CameraOrientation"]));
//create entity and attach to scence node
Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
/**
Ogre::Entity* et=sm->createEntity("robot.mesh");
//Ogre::ResourceGroupManager::getSingleton().create
//et->setMaterial();
Ogre::SceneNode* node=sm->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(0,0,0));
node->attachObject(et);
node->roll(Ogre::Radian(0.9));
node->scale(1,1,3);
Ogre::Entity* et2=sm->createEntity("ogrehead.mesh");
Ogre::SceneNode* node2=sm->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(0,0,100));
node2->attachObject(et2);
**/
using namespace Ogre;
/**
Light* light = sm->createLight();
light->setType(Light::LT_POINT);
light->setPosition(-10, 0, 0);
light->setSpecularColour(ColourValue::White);
**/
Ogre::Entity* et=sm->createEntity("__.mesh");
et->getSubEntity(0)->setMaterialName("dcy","dc");
et->getSubEntity(1)->setMaterialName("dcyzs","dc");
et->getSubEntity(2)->setMaterialName("dct","dc");
et->getSubEntity(3)->setMaterialName("dcts","dc");
Ogre::SceneNode* node=sm->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(10,-3,0));
node->attachObject(et);
const Ogre::Radian or(0.9);
//node->roll(Ogre::Radian(0.9));
node->rotate(Ogre::Vector3(0,1,0),Ogre::Radian(0.9));
Ogre::AnimationState* ao= et->getAnimationState("releax");
ao->setLoop(true);
ao->setEnabled(true);
node->scale(3,3,3);
//set light
sm->setAmbientLight(Ogre::ColourValue(1,1,1));
/**
Ogre::ParticleSystem* ps= sm->createParticleSystem("Nimbus", "PEExamples/blast");
node->attachObject(ps);
ps->setVisible("true");
**/
//start rendering
//rt->startRendering();
//sm->setAmbientLight(ColourValue(0.2, 0.2, 0.2));
//terrain
Vector3 mTerrainPos(1000,0,5000);
oc->setPosition(mTerrainPos + Vector3(1683, 50, 2116));
oc->lookAt(Vector3(1963, 50, 1660));
oc->setNearClipDistance(0.1);
oc->setFarClipDistance(50000);
TerrainGlobalOptions* mTerrainGlobals = OGRE_NEW Ogre::TerrainGlobalOptions();
Light* l = sm->createLight("tstLight");
l->setType(Light::LT_DIRECTIONAL);
Vector3 lightdir(0.55, -0.3, 0.75);
l->setDirection(lightdir);
l->setDiffuseColour(ColourValue::White);
l->setSpecularColour(ColourValue(0.4, 0.4, 0.4));
#define TERRAIN_WORLD_SIZE 12000.0f
#define TERRAIN_SIZE 513
Ogre::TerrainGroup* mTerrainGroup = OGRE_NEW Ogre::TerrainGroup(sm, Terrain::ALIGN_X_Z, TERRAIN_SIZE, TERRAIN_WORLD_SIZE);
mTerrainGroup->setFilenameConvention("test", "sad");
// Vector3 mTerrainPos(1000,0,5000);
mTerrainGroup->setOrigin(mTerrainPos);
mTerrainGlobals->setMaxPixelError(8);
// testing composite map
mTerrainGlobals->setCompositeMapDistance(3000);
//mTerrainGlobals->setUseRayBoxDistanceCalculation(true);
//mTerrainGlobals->getDefaultMaterialGenerator()->setDebugLevel(1);
//mTerrainGlobals->setLightMapSize(256);
//matProfile->setLightmapEnabled(false);
// Important to set these so that the terrain knows what to use for derived (non-realtime) data
mTerrainGlobals->setLightMapDirection(l->getDerivedDirection());
mTerrainGlobals->setCompositeMapAmbient(sm->getAmbientLight());
//mTerrainGlobals->setCompositeMapAmbient(ColourValue::Red);
mTerrainGlobals->setCompositeMapDiffuse(l->getDiffuseColour());
// Configure default import settings for if we use imported image
Ogre::Terrain::ImportData& defaultimp = mTerrainGroup->getDefaultImportSettings();
defaultimp.terrainSize = TERRAIN_SIZE;
defaultimp.worldSize = TERRAIN_WORLD_SIZE;
defaultimp.inputScale = 600;
defaultimp.minBatchSize = 33;
defaultimp.maxBatchSize = 65;
// textures
defaultimp.layerList.resize(3);
defaultimp.layerList[0].worldSize = 100;
defaultimp.layerList[0].textureNames.push_back("dirt_grayrocky_diffusespecular.dds");
defaultimp.layerList[0].textureNames.push_back("dirt_grayrocky_normalheight.dds");
defaultimp.layerList[1].worldSize = 30;
defaultimp.layerList[1].textureNames.push_back("grass_green-01_diffusespecular.dds");
defaultimp.layerList[1].textureNames.push_back("grass_green-01_normalheight.dds");
defaultimp.layerList[2].worldSize = 200;
defaultimp.layerList[2].textureNames.push_back("growth_weirdfungus-03_diffusespecular.dds");
defaultimp.layerList[2].textureNames.push_back("growth_weirdfungus-03_normalheight.dds");
int x=0;int y=0;
//String filename = mTerrainGroup->generateFilename(x, y);
//if (ResourceGroupManager::getSingleton().resourceExists(mTerrainGroup->getResourceGroup(), filename))
//{
//mTerrainGroup->defineTerrain(x, y);
//}
//else
{
Image img;
//getTerrainImage(x % 2 != 0, y % 2 != 0, img);
{
img.load("terrain.png", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
if (x % 2 != 0)
img.flipAroundY();
if (y % 2 != 0)
img.flipAroundX();
}
mTerrainGroup->defineTerrain(x, y, &img);
//mTerrainsImported = true;
}
mTerrainGroup->loadAllTerrains(true);
TerrainGroup::TerrainIterator ti = mTerrainGroup->getTerrainIterator();
while(ti.hasMoreElements())
{
Terrain* terrain = ti.getNext()->instance;
//initBlendMaps(terrain);
{
TerrainLayerBlendMap* blendMap0 = terrain->getLayerBlendMap(1);
TerrainLayerBlendMap* blendMap1 = terrain->getLayerBlendMap(2);
Real minHeight0 = 70;
Real fadeDist0 = 40;
Real minHeight1 = 70;
Real fadeDist1 = 15;
float* pBlend1 = blendMap1->getBlendPointer();
for (Ogre::uint16 y = 0; y < terrain->getLayerBlendMapSize(); ++y)
{
for (Ogre::uint16 x = 0; x < terrain->getLayerBlendMapSize(); ++x)
{
Real tx, ty;
blendMap0->convertImageToTerrainSpace(x, y, &tx, &ty);
Real height = terrain->getHeightAtTerrainPosition(tx, ty);
Real val = (height - minHeight0) / fadeDist0;
val = Math::Clamp(val, (Real)0, (Real)1);
//*pBlend0++ = val;
val = (height - minHeight1) / fadeDist1;
val = Math::Clamp(val, (Real)0, (Real)1);
*pBlend1++ = val;
}
}
blendMap0->dirty();
blendMap1->dirty();
//blendMap0->loadImage("blendmap1.png", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
blendMap0->update();
blendMap1->update();
}
}
mTerrainGroup->freeTemporaryResources();
while(1){
ao->addTime(0.01);
rt->renderOneFrame();
}
//clear scene and destroy it
sm->clearScene();
rt->destroySceneManager(sm);
//unload resource
Ogre::ResourceGroupManager::ResourceManagerIterator resMgrs =
Ogre::ResourceGroupManager::getSingleton().getResourceManagerIterator();
while (resMgrs.hasMoreElements())
{
resMgrs.getNext()->unloadUnreferencedResources();
}
}
catch (Ogre::Exception& e)
{
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
MessageBoxA(NULL, e.getFullDescription().c_str(), "An exception has occurred!", MB_ICONERROR | MB_TASKMODAL);
#else
std::cerr << "An exception has occurred: " << e.getFullDescription().c_str() << std::endl;
#endif
}
#endif
return 0;
}
#endif
-----------------------------------------------------------------------------
This source file is part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/
Copyright (c) 2000-2012 Torus Knot Software Ltd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/
#include "OgrePlatform.h"
#include "SampleBrowser.h"
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
#include "OgreString.h"
#elif OGRE_PLATFORM == OGRE_PLATFORM_APPLE
#include "SampleBrowser_OSX.h"
#elif OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS
#include "SampleBrowser_iOS.h"
#elif OGRE_PLATFORM == OGRE_PLATFORM_NACL
#include "SampleBrowser_NaCl.h"
#endif
#include "OgreTerrain.h"
#include "OgreTerrainGroup.h"
#if OGRE_PLATFORM != OGRE_PLATFORM_NACL
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
INT WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR cmdLine, INT)
#else
int main(int argc, char *argv[])
#endif
{
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, @"UIApplication", @"AppDelegate");
[pool release];
return retVal;
#elif (OGRE_PLATFORM == OGRE_PLATFORM_APPLE) && __LP64__
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
mAppDelegate = [[AppDelegate alloc] init];
[[NSApplication sharedApplication] setDelegate:mAppDelegate];
int retVal = NSApplicationMain(argc, (const char **) argv);
[pool release];
return retVal;
#else
try
{
bool nograb = false;
#if OGRE_PLATFORM != OGRE_PLATFORM_WIN32
if (argc >= 2 && Ogre::String(argv[1]) == "nograb")
nograb = true;
#else
// somewhat hacky, but much simpler than other solutions
if (Ogre::String(cmdLine).find("nograb") != Ogre::String::npos)
nograb = true;
#endif
//OgreBites::SampleBrowser brows (nograb);
//brows.go();
//if(0)
//return 0;
//create root
Ogre::Root* rt=new Ogre::Root("C:\\workspace\\ogre\\ogre4vs2010\\MyOgre\\Debug\\plugins.cfg",
"C:\\workspace\\ogre\\ogre4vs2010\\MyOgre\\Debug\\ogre.cfg",
"C:\\workspace\\ogre\\ogre4vs2010\\MyOgre\\Debug\\ogre.log");
if(!rt->restoreConfig())
rt->showConfigDialog();
//create window
Ogre::RenderWindow* rw=rt->initialise(true);
size_t winHandler=0;
rw->getCustomAttribute("WINDOW",&winHandler);
rw->setAutoUpdated(true);
//create input system
std::ostringstream winHandlerStr;
winHandlerStr<<winHandler;
OIS::ParamList pl;
pl.insert(std::make_pair("WINDOW",winHandlerStr.str()));
OIS::InputManager* im=OIS::InputManager::createInputSystem(pl);
/**Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
"C:\\workspace\\ogre\\ogre4vs2010\\OgreSDK_vc10_v1-8-1\\media\\models"
,"FileSystem"
,"models");
Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
"C:\\workspace\\ogre\\ogre4vs2010\\OgreSDK_vc10_v1-8-1\\media\\materials\\scripts"
,"FileSystem"
,"materials");
**/
Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
"C:\\workspace\\ogre\\ogre4vs2010\\OgreSDK_vc10_v1-8-1\\media\\materials\\textures"
,"FileSystem"
,Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
"C:\\workspace\\ogre\\ogre4vs2010\\OgreSDK_vc10_v1-8-1\\media\\materials\\textures\\nvidia"
,"FileSystem"
,Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
"C:\\ogremaxexport"
,"FileSystem"
,"dc");
Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
Ogre::ResourceGroupManager::getSingleton().loadResourceGroup("dc");
//Ogre::ResourceGroupManager::getSingleton().loadResourceGroup(Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
Ogre::StringVectorPtr dc=Ogre::ResourceGroupManager::getSingleton().listResourceNames("dc");
Ogre::StringVectorPtr ds=Ogre::ResourceGroupManager::getSingleton().listResourceLocations("dc");
//Ogre::MaterialManager.
/**
Ogre::OverlayManager& om=Ogre::OverlayManager::getSingleton();
Ogre::Overlay* ol=om.create("test");
Ogre::OverlayContainer* testPanel=(Ogre::OverlayContainer*)om.createOverlayElementFromTemplate("SdkTrays/Cursor","","");
testPanel->setMaterialName("BaseWhite");
ol->add2D(testPanel);
ol->setZOrder(10);
ol->show();
**/
/**
Ogre::Overlay* overlay=om.create("overlay");
overlay->setZOrder(100);
Ogre::OverlayContainer* ole=(Ogre::OverlayContainer*)om.createOverlayElement("Panel","Backdrop");
overlay->add2D(ole);
overlay->show();
**/
rw->removeAllViewports();
//create scenemanager and camera
Ogre::SceneManager* sm=rt->createSceneManager(Ogre::ST_GENERIC,"testScence");
Ogre::Camera* oc=sm->createCamera("testCamera");
/**
oc->setNearClipDistance(0.1);
oc->setPosition(-3,0,0);
oc->lookAt(1,0,0);
**/
Ogre::Viewport* ovp=rw->addViewport(oc);
ovp->setBackgroundColour(Ogre::ColourValue(0.8f, 0.8f, 0.8f));
//sm->setFog(Ogre::FOG_LINEAR, Ogre::ColourValue(0.2f, 0.2f, 0.2f), 0, 15, 100);
/**
//save camera status
Ogre::NameValuePairList state;
state["CameraPosition"] = Ogre::StringConverter::toString(oc->getPosition());
state["CameraOrientation"] = Ogre::StringConverter::toString(oc->getOrientation());
oc->setPosition(Ogre::StringConverter::parseVector3(state["CameraPosition"]));
oc->setOrientation(Ogre::StringConverter::parseQuaternion(state["CameraOrientation"]));
//create entity and attach to scence node
Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
/**
Ogre::Entity* et=sm->createEntity("robot.mesh");
//Ogre::ResourceGroupManager::getSingleton().create
//et->setMaterial();
Ogre::SceneNode* node=sm->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(0,0,0));
node->attachObject(et);
node->roll(Ogre::Radian(0.9));
node->scale(1,1,3);
Ogre::Entity* et2=sm->createEntity("ogrehead.mesh");
Ogre::SceneNode* node2=sm->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(0,0,100));
node2->attachObject(et2);
**/
using namespace Ogre;
/**
Light* light = sm->createLight();
light->setType(Light::LT_POINT);
light->setPosition(-10, 0, 0);
light->setSpecularColour(ColourValue::White);
**/
Ogre::Entity* et=sm->createEntity("__.mesh");
et->getSubEntity(0)->setMaterialName("dcy","dc");
et->getSubEntity(1)->setMaterialName("dcyzs","dc");
et->getSubEntity(2)->setMaterialName("dct","dc");
et->getSubEntity(3)->setMaterialName("dcts","dc");
Ogre::SceneNode* node=sm->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(10,-3,0));
node->attachObject(et);
const Ogre::Radian or(0.9);
//node->roll(Ogre::Radian(0.9));
node->rotate(Ogre::Vector3(0,1,0),Ogre::Radian(0.9));
Ogre::AnimationState* ao= et->getAnimationState("releax");
ao->setLoop(true);
ao->setEnabled(true);
node->scale(3,3,3);
//set light
sm->setAmbientLight(Ogre::ColourValue(1,1,1));
/**
Ogre::ParticleSystem* ps= sm->createParticleSystem("Nimbus", "PEExamples/blast");
node->attachObject(ps);
ps->setVisible("true");
**/
//start rendering
//rt->startRendering();
//sm->setAmbientLight(ColourValue(0.2, 0.2, 0.2));
//terrain
Vector3 mTerrainPos(1000,0,5000);
oc->setPosition(mTerrainPos + Vector3(1683, 50, 2116));
oc->lookAt(Vector3(1963, 50, 1660));
oc->setNearClipDistance(0.1);
oc->setFarClipDistance(50000);
TerrainGlobalOptions* mTerrainGlobals = OGRE_NEW Ogre::TerrainGlobalOptions();
Light* l = sm->createLight("tstLight");
l->setType(Light::LT_DIRECTIONAL);
Vector3 lightdir(0.55, -0.3, 0.75);
l->setDirection(lightdir);
l->setDiffuseColour(ColourValue::White);
l->setSpecularColour(ColourValue(0.4, 0.4, 0.4));
#define TERRAIN_WORLD_SIZE 12000.0f
#define TERRAIN_SIZE 513
Ogre::TerrainGroup* mTerrainGroup = OGRE_NEW Ogre::TerrainGroup(sm, Terrain::ALIGN_X_Z, TERRAIN_SIZE, TERRAIN_WORLD_SIZE);
mTerrainGroup->setFilenameConvention("test", "sad");
// Vector3 mTerrainPos(1000,0,5000);
mTerrainGroup->setOrigin(mTerrainPos);
mTerrainGlobals->setMaxPixelError(8);
// testing composite map
mTerrainGlobals->setCompositeMapDistance(3000);
//mTerrainGlobals->setUseRayBoxDistanceCalculation(true);
//mTerrainGlobals->getDefaultMaterialGenerator()->setDebugLevel(1);
//mTerrainGlobals->setLightMapSize(256);
//matProfile->setLightmapEnabled(false);
// Important to set these so that the terrain knows what to use for derived (non-realtime) data
mTerrainGlobals->setLightMapDirection(l->getDerivedDirection());
mTerrainGlobals->setCompositeMapAmbient(sm->getAmbientLight());
//mTerrainGlobals->setCompositeMapAmbient(ColourValue::Red);
mTerrainGlobals->setCompositeMapDiffuse(l->getDiffuseColour());
// Configure default import settings for if we use imported image
Ogre::Terrain::ImportData& defaultimp = mTerrainGroup->getDefaultImportSettings();
defaultimp.terrainSize = TERRAIN_SIZE;
defaultimp.worldSize = TERRAIN_WORLD_SIZE;
defaultimp.inputScale = 600;
defaultimp.minBatchSize = 33;
defaultimp.maxBatchSize = 65;
// textures
defaultimp.layerList.resize(3);
defaultimp.layerList[0].worldSize = 100;
defaultimp.layerList[0].textureNames.push_back("dirt_grayrocky_diffusespecular.dds");
defaultimp.layerList[0].textureNames.push_back("dirt_grayrocky_normalheight.dds");
defaultimp.layerList[1].worldSize = 30;
defaultimp.layerList[1].textureNames.push_back("grass_green-01_diffusespecular.dds");
defaultimp.layerList[1].textureNames.push_back("grass_green-01_normalheight.dds");
defaultimp.layerList[2].worldSize = 200;
defaultimp.layerList[2].textureNames.push_back("growth_weirdfungus-03_diffusespecular.dds");
defaultimp.layerList[2].textureNames.push_back("growth_weirdfungus-03_normalheight.dds");
int x=0;int y=0;
//String filename = mTerrainGroup->generateFilename(x, y);
//if (ResourceGroupManager::getSingleton().resourceExists(mTerrainGroup->getResourceGroup(), filename))
//{
//mTerrainGroup->defineTerrain(x, y);
//}
//else
{
Image img;
//getTerrainImage(x % 2 != 0, y % 2 != 0, img);
{
img.load("terrain.png", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
if (x % 2 != 0)
img.flipAroundY();
if (y % 2 != 0)
img.flipAroundX();
}
mTerrainGroup->defineTerrain(x, y, &img);
//mTerrainsImported = true;
}
mTerrainGroup->loadAllTerrains(true);
TerrainGroup::TerrainIterator ti = mTerrainGroup->getTerrainIterator();
while(ti.hasMoreElements())
{
Terrain* terrain = ti.getNext()->instance;
//initBlendMaps(terrain);
{
TerrainLayerBlendMap* blendMap0 = terrain->getLayerBlendMap(1);
TerrainLayerBlendMap* blendMap1 = terrain->getLayerBlendMap(2);
Real minHeight0 = 70;
Real fadeDist0 = 40;
Real minHeight1 = 70;
Real fadeDist1 = 15;
float* pBlend1 = blendMap1->getBlendPointer();
for (Ogre::uint16 y = 0; y < terrain->getLayerBlendMapSize(); ++y)
{
for (Ogre::uint16 x = 0; x < terrain->getLayerBlendMapSize(); ++x)
{
Real tx, ty;
blendMap0->convertImageToTerrainSpace(x, y, &tx, &ty);
Real height = terrain->getHeightAtTerrainPosition(tx, ty);
Real val = (height - minHeight0) / fadeDist0;
val = Math::Clamp(val, (Real)0, (Real)1);
//*pBlend0++ = val;
val = (height - minHeight1) / fadeDist1;
val = Math::Clamp(val, (Real)0, (Real)1);
*pBlend1++ = val;
}
}
blendMap0->dirty();
blendMap1->dirty();
//blendMap0->loadImage("blendmap1.png", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
blendMap0->update();
blendMap1->update();
}
}
mTerrainGroup->freeTemporaryResources();
while(1){
ao->addTime(0.01);
rt->renderOneFrame();
}
//clear scene and destroy it
sm->clearScene();
rt->destroySceneManager(sm);
//unload resource
Ogre::ResourceGroupManager::ResourceManagerIterator resMgrs =
Ogre::ResourceGroupManager::getSingleton().getResourceManagerIterator();
while (resMgrs.hasMoreElements())
{
resMgrs.getNext()->unloadUnreferencedResources();
}
}
catch (Ogre::Exception& e)
{
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
MessageBoxA(NULL, e.getFullDescription().c_str(), "An exception has occurred!", MB_ICONERROR | MB_TASKMODAL);
#else
std::cerr << "An exception has occurred: " << e.getFullDescription().c_str() << std::endl;
#endif
}
#endif
return 0;
}
#endif
相关文章推荐
- 一些XMLHttpRequest的例子代码
- return false,对阻止事件默认动作的一些测试代码
- jQuery一些简单的代码简化,循环链接的完整例子
- 一些 NSArray 的基本操作代码例子
- OGRE(八):Ogre例子中的Character脱离Browser的代码
- 代码里写控件的一些例子
- 一些 NSArray 的基本操作代码例子
- 一些VC例子的代码--编辑框
- Ogre1.7.2 terrain地形构建例子
- 【编程技巧】一些 NSArray 的基本操作代码例子
- [代码整理]今天抽空整理了一些java.sql的例子,有兴趣的可以去看看
- 近期OGRE的一些研究---创建道路并且与让地形与道路对齐
- 一些 NSArray 的基本操作代码例子
- return false,对阻止事件默认动作的一些测试代码
- 近期OGRE的一些研究---创建道路并且与让地形与道路对齐
- 一些XMLHttpRequest的例子代码
- 软件开发者面试百问-----你在代码里面怎么提前处理需求的变化?给一些例子。
- Ogre代码学习之1——Ogre中地形lod的基础:deltaHeight的计算
- iOS一些代码小例子
- [资源分享][Unity][人物模型][动作]一些人物模型以及动作的分享