TerrainGroup에서 Terain을 Iterator로 받아오는 방법

//
//
//
Ogre::TerrainGroup::TerrainIterator ti = pTerrainGroup->getTerrainIterator();
while(ti.hasMoreElements())
{
	Ogre::Terrain* t = ti.getNext()->instance;
	t->_setNormalMapRequired(false);
}


by 炫's 2013. 2. 14. 09:47
  • Manual Object 로 Cube 생성하는 함수
//
//
//
Ogre::ManualObject* createCubeMesh (Ogre::String name, Ogre::String matName) 
{
   Ogre::ManualObject* cube = new Ogre::ManualObject(name);
   cube->begin(matName);
 
   cube->position(0.5f,-0.5f,1.0f);cube->normal(0.408248f,-0.816497f,0.408248f);cube->textureCoord(1,0);
   cube->position(-0.5f,-0.5f,0.0f);cube->normal(-0.408248f,-0.816497f,-0.408248f);cube->textureCoord(0,1);
   cube->position(0.5f,-0.5f,0.0f);cube->normal(0.666667f,-0.333333f,-0.666667f);cube->textureCoord(1,1);
   cube->position(-0.5f,-0.5f,1.0f);cube->normal(-0.666667f,-0.333333f,0.666667f);cube->textureCoord(0,0);
   cube->position(0.5f,0.5f,1.0f);cube->normal(0.666667f,0.333333f,0.666667f);cube->textureCoord(1,0);
   cube->position(-0.5,-0.5,1.0);cube->normal(-0.666667f,-0.333333f,0.666667f);cube->textureCoord(0,1);
   cube->position(0.5,-0.5,1.0);cube->normal(0.408248,-0.816497,0.408248f);cube->textureCoord(1,1);
   cube->position(-0.5,0.5,1.0);cube->normal(-0.408248,0.816497,0.408248);cube->textureCoord(0,0);
   cube->position(-0.5,0.5,0.0);cube->normal(-0.666667,0.333333,-0.666667);cube->textureCoord(0,1);
   cube->position(-0.5,-0.5,0.0);cube->normal(-0.408248,-0.816497,-0.408248);cube->textureCoord(1,1);
   cube->position(-0.5,-0.5,1.0);cube->normal(-0.666667,-0.333333,0.666667);cube->textureCoord(1,0);
   cube->position(0.5,-0.5,0.0);cube->normal(0.666667,-0.333333,-0.666667);cube->textureCoord(0,1);
   cube->position(0.5,0.5,0.0);cube->normal(0.408248,0.816497,-0.408248);cube->textureCoord(1,1);
   cube->position(0.5,-0.5,1.0);cube->normal(0.408248,-0.816497,0.408248);cube->textureCoord(0,0);
   cube->position(0.5,-0.5,0.0);cube->normal(0.666667,-0.333333,-0.666667);cube->textureCoord(1,0);
   cube->position(-0.5,-0.5,0.0);cube->normal(-0.408248,-0.816497,-0.408248);cube->textureCoord(0,0);
   cube->position(-0.5,0.5,1.0);cube->normal(-0.408248,0.816497,0.408248);cube->textureCoord(1,0);
   cube->position(0.5,0.5,0.0);cube->normal(0.408248,0.816497,-0.408248);cube->textureCoord(0,1);
   cube->position(-0.5,0.5,0.0);cube->normal(-0.666667,0.333333,-0.666667);cube->textureCoord(1,1);
   cube->position(0.5,0.5,1.0);cube->normal(0.666667,0.333333,0.666667);cube->textureCoord(0,0);
 
   cube->triangle(0,1,2);      cube->triangle(3,1,0);
   cube->triangle(4,5,6);      cube->triangle(4,7,5);
   cube->triangle(8,9,10);      cube->triangle(10,7,8);
   cube->triangle(4,11,12);   cube->triangle(4,13,11);
   cube->triangle(14,8,12);   cube->triangle(14,15,8);
   cube->triangle(16,17,18);   cube->triangle(16,19,17);
   cube->end();
 
   return cube;
}
  • 생성된 Manual Object를 연속해서 여러개 그림
//
//
//
void createScene(void)
{
	    ⁄⁄Create a basic green color texture 
	Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().create("BoxColor", "General", true );
	Ogre::Technique* tech = mat->getTechnique(0);
	Ogre::Pass* pass = tech->getPass(0);
	Ogre::TextureUnitState* tex = pass->createTextureUnitState();
	tex->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, Ogre::ColourValue(0, 0.5, 0));
 
	    ⁄⁄Create the one box and the supporting class objects
	Ogre::ManualObject* testBox  = createCubeMesh("TestBox1", "BoxColor");	
        Ogre::SceneNode* headNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
	Ogre::MeshPtr Mesh = testBox->convertToMesh("TestBox2");
	Ogre::StaticGeometry* pGeom = new Ogre::StaticGeometry (mSceneMgr, "Boxes");
	Ogre::Entity* pEnt = mSceneMgr->createEntity("TestBox2");
 
	pGeom->setRegionDimensions(Ogre::Vector3(300, 300, 300));
 
	    ⁄⁄Create out solid block world
	for (int z = 0; z < 256; ++z)
	{
		for (int y = 0; y < 256; ++y)
		{
			for (int x = 0; x < 256; ++x)
			{
				pGeom->addEntity(pEnt, Ogre::Vector3(x,y,z));
			}
		}
	}
 
	pGeom->build ();
 
        mSceneMgr->setAmbientLight(Ogre::ColourValue(0.5, 0.5, 0.5));
	Ogre::Light* l = mSceneMgr->createLight("MainLight");
        l->setPosition(20,80,50);
}

by 炫's 2013. 2. 7. 12:18
택스쳐 생성
Ogre::TexturePtr texture;
texture = TextureManager::getSingleton().createManual(
		"TextureName",		⁄⁄ 텍스쳐의 이름입니다.
		"ResourceGroup",	⁄⁄ 텍스쳐가 생성될 리소스 그룹입니다.
		TEX_TYPE_2D,		⁄⁄ 텍스쳐 타입
		width,				⁄⁄ 폭
		height,				⁄⁄ 높이
		1,					⁄⁄ 깊이(2차원 텍스쳐는 반듯이 1로 설정해야만 합니다.)
		0,					⁄⁄ 밉맵의 갯수
		PF_A8R8G8B8,		⁄⁄ 픽셀 포멧
		TU_STATIC			⁄⁄ 사용법
	);

Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().create("TextureName", "ResourceGroup");
material->getTechnique(0)->getPass(0)->createTextureUnitState(iter2->c_str());
material->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
material->getTechnique(0)->getPass(0)->setAlphaRejectSettings(CompareFunction::CMPF_GREATER, Ogre::StringConverter::parseInt("128"));
material->setCullingMode(Ogre::CULL_NONE );

수동으로 객체 그림
ManualObject* manual = pSceneMgr->createManualObject((*iter2));
manual->begin("ObjectName", RenderOperation::OT_TRIANGLE_LIST);
for(int i=0; i<nSize; i++)
{
	manual->position(x, y, z);
	manual->normal(z, y, z);
	manual->textureCoord(u, v);
}
manual->end();
이미지 픽셀데이터를 텍스쳐 버퍼에 복사
Ogre::HardwarePixelBufferSharedPtr pxBuffer = texture->getBuffer();
pxBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD);
const Ogre::PixelBox& pixelBox = pxBuffer->getCurrentLock();
Ogre::uint8* pDest = static_cast<Ogre::uint8*>(pixelBox.data);

for(int i=height-1; i >= 0; i--)
{    
	for(int j=0; j < width; j++)
	{
		*pDest++ = out[((i*nDepth*width)+j*nDepth + 0)];		⁄⁄ B
		*pDest++ = out[((i*nDepth*width)+j*nDepth + 1)];		⁄⁄ G
		*pDest++ = out[((i*nDepth*width)+j*nDepth + 2)];		⁄⁄ R
		*pDest++ = out[((i*nDepth*width)+j*nDepth + 3)];		⁄⁄ A
	}
}

pxBuffer->unlock();

'OGRE3D' 카테고리의 다른 글

Terrain 반복자(Iterator) 사용 방법  (0) 2013.02.14
Manual Object 연속 생성 샘플 코드  (0) 2013.02.07
by 炫's 2013. 1. 30. 14:49
| 1 |