Exemplo n.º 1
0
//  util
//---------------------------------------------------------------------------------------------------------------
ManualObject* App::Create2D(const String& mat, Real s, bool dyn)
{
	ManualObject* m = mSceneMgr->createManualObject();
	m->setDynamic(dyn);
	m->setUseIdentityProjection(true);
	m->setUseIdentityView(true);
	m->setCastShadows(false);
	m->estimateVertexCount(4);
	m->begin(mat, RenderOperation::OT_TRIANGLE_STRIP);
	m->position(-s,-s*asp, 0);  m->textureCoord(0, 1);
	m->position( s,-s*asp, 0);  m->textureCoord(1, 1);
	m->position(-s, s*asp, 0);  m->textureCoord(0, 0);
	m->position( s, s*asp, 0);  m->textureCoord(1, 0);
	m->end();
 
	//TODO:replace OT_TRIANGLE_FAN with a more friendly version for D3D11 as it is not supported
	/*
	m->estimateVertexCount(6);
	m->begin(mat, RenderOperation::OT_TRIANGLE_LIST);

	m->position(-s,-s*asp, 0);  m->textureCoord(0, 1);
	m->position( s,-s*asp, 0);  m->textureCoord(1, 1);
	m->position( s, s*asp, 0);  m->textureCoord(1, 0);
	m->position(-s, s*asp, 0);  m->textureCoord(0, 0);
	m->position(-s,-s*asp, 0);  m->textureCoord(0, 1);
	m->position( s, s*asp, 0);  m->textureCoord(1, 0);
	m->end();
	*/
	AxisAlignedBox aabInf;	aabInf.setInfinite();
	m->setBoundingBox(aabInf);  // always visible
	m->setRenderQueueGroup(RQG_Hud2);
	return m;
}
Exemplo n.º 2
0
void HelloOgre::createManual(){
	Ogre::SceneManager* mSceneMgr= OgreApp::I()->getSceneManager();
#if 1
	ManualObject* manual = mSceneMgr->createManualObject("manual");
	// specify the material (by name) and rendering type
	manual->begin("BaseWhiteNoLighting", RenderOperation::OT_LINE_LIST);
//	manual->begin("BaseWhiteNoLighting", RenderOperation::OT_TRIANGLE_STRIP);
	// define start and end point
	manual->position(-100, -100, -100 );
	manual->position(100, 100, 100 );
	manual->colour( 1.0f, 1.0f, 1.0f, 1.0f );
	// tell Ogre, your definition has finished
	manual->end();
	// add ManualObject to the RootSceneNode (so it will be visible)
	mSceneMgr->getRootSceneNode()->attachObject(manual);
#endif

#if 1
// Create a manual object for 2D
	manual = mSceneMgr->createManualObject("manual2");
	 
	// Use identity view/projection matrices
	manual->setUseIdentityProjection(true);
	manual->setUseIdentityView(true);
	 
	manual->begin("BaseWhiteNoLighting", RenderOperation::OT_LINE_STRIP);
	 
	manual->position(-0.2, -0.2, 0.0);
	manual->position( 0.2, -0.2, 0.0);
	manual->position( 0.2,  0.2, 0.0);
	manual->position(-0.2,  0.2, 0.0);
	 
	manual->index(0);
	manual->index(1);
	manual->index(2);
	manual->index(3);
	manual->index(0);
	 
	manual->end();
	 
	// Use infinite AAB to always stay visible
	AxisAlignedBox aabInf;
	aabInf.setInfinite();
	manual->setBoundingBox(aabInf);
	 
	// Render just before overlays
	manual->setRenderQueueGroup(RENDER_QUEUE_OVERLAY - 1);
	 
	// Attach to scene
	mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(manual);
#endif
}
Exemplo n.º 3
0
//  Sky Dome
//-------------------------------------------------------------------------------------
void CScene::CreateSkyDome(String sMater, Vector3 sc, float yaw)
{
	ManualObject* m = app->mSceneMgr->createManualObject();
	m->begin(sMater, RenderOperation::OT_TRIANGLE_LIST);

	//  divisions- quality
	int ia = 32*2, ib = 24,iB = 24 +1/*below_*/, i=0;
	//int ia = 4, ib = 4, i=0;
	//  angles, max
	float a,b;  const float B = PI_d/2.f, A = 2.f*PI_d;
	float bb = B/ib, aa = A/ia;  // add
	ia += 1;

	//  up/dn y  )
	for (b = 0.f; b <= B+bb/*1*/*iB; b += bb)
	{
		float cb = sinf(b), sb = cosf(b);
		float y = sb;

		//  circle xz  o
		for (a = 0.f; a <= A; a += aa, ++i)
		{
			float x = cosf(a)*cb, z = sinf(a)*cb;
			m->position(x,y,z);

			m->textureCoord(a/A, b/B);

			if (a > 0.f && b > 0.f)  // rect 2tri
			{
				m->index(i-1);  m->index(i);     m->index(i-ia);
				m->index(i-1);  m->index(i-ia);  m->index(i-ia-1);
			}
		}
	}
	m->end();
	AxisAlignedBox aab;  aab.setInfinite();
	m->setBoundingBox(aab);  // always visible
	m->setRenderQueueGroup(RQG_Sky);
	m->setCastShadows(false);
	#ifdef SR_EDITOR
	m->setVisibilityFlags(RV_Sky);  // hide on minimap
	#endif

	app->ndSky = app->mSceneMgr->getRootSceneNode()->createChildSceneNode();
	app->ndSky->attachObject(m);
	app->ndSky->setScale(sc);
	Quaternion q;  q.FromAngleAxis(Degree(-yaw), Vector3::UNIT_Y);
	app->ndSky->setOrientation(q);
}
Exemplo n.º 4
0
Ogre::SceneNode* Terminal::createTexturedRect(std::string object_name, std::string texture_name, float left, float top, float right, float bottom)
{
    MaterialPtr material = MaterialManager::getSingleton().create(object_name,Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
    material->getTechnique(0)->getPass(0)->createTextureUnitState(texture_name);
    material->getTechnique(0)->getPass(0)->setDepthCheckEnabled(false);
    material->getTechnique(0)->getPass(0)->setDepthWriteEnabled(true);
    material->getTechnique(0)->getPass(0)->setLightingEnabled(false);

//    Ogre::Rectangle2D* rect = new Ogre::Rectangle2D(true);
    ManualObject* manual = Entropy::getSingletonPtr()->mSceneMgr->createManualObject(object_name);
    manual->setUseIdentityProjection(true);
    manual->setUseIdentityView(true);

    manual->begin(object_name, RenderOperation::OT_TRIANGLE_STRIP);

    manual->position(left, bottom, 0.0);
    manual->position(left, top, 0.0);
    manual->position(right, bottom, 0.0);
    manual->position(right,  top, 0.0);

    manual->index(0);
    manual->index(1);
    manual->index(2);
    manual->index(3);

    manual->end();

//    rect->setCorners(left,top,right,bottom);
//    rect->setMaterial(object_name);

    manual->setRenderQueueGroup(RENDER_QUEUE_OVERLAY);

    Ogre::AxisAlignedBox aabInf;
    aabInf.setInfinite();
    manual->setBoundingBox(aabInf);

    Ogre::SceneNode* rect_node = Entropy::getSingletonPtr()->mSceneMgr->getRootSceneNode()->createChildSceneNode(object_name);
    rect_node->attachObject(manual);


//    rect->setVisible(false);



//    rect_node->setPosition(0,0,0);

    return rect_node;
}
Exemplo n.º 5
0
ManualObject* CHud::Create2D(const String& mat, SceneManager* sceneMgr,
	Real s,  // scale pos
	bool dyn, bool clr,
	Real mul, Vector2 ofs,
	uint32 vis, uint8 rndQue,
	int cnt)
{
	ManualObject* m = sceneMgr->createManualObject();
	m->setDynamic(dyn);
	m->setUseIdentityProjection(true);
	m->setUseIdentityView(true);
	m->setCastShadows(false);

	m->estimateVertexCount(cnt * 4);
	m->begin(mat, cnt > 1 ? RenderOperation::OT_TRIANGLE_LIST : RenderOperation::OT_TRIANGLE_STRIP);
	const static Vector2 uv[4] = { Vector2(0.f,1.f),Vector2(1.f,1.f),Vector2(0.f,0.f),Vector2(1.f,0.f) };

	for (int i=0; i < cnt; ++i)
	{	m->position(-s,-s*asp, 0);  m->textureCoord(uv[0]*mul + ofs);  if (clr)  m->colour(0,1,0);
		m->position( s,-s*asp, 0);  m->textureCoord(uv[1]*mul + ofs);  if (clr)  m->colour(0,0,0);
		m->position(-s, s*asp, 0);  m->textureCoord(uv[2]*mul + ofs);  if (clr)  m->colour(1,1,0);
		m->position( s, s*asp, 0);  m->textureCoord(uv[3]*mul + ofs);  if (clr)  m->colour(1,0,0);
	}
	if (cnt > 1)
	for (int i=0; i < cnt; ++i)
	{	int n = i*4;
		m->quad(n,n+1,n+3,n+2);
	}
	m->end();
 
	AxisAlignedBox aabInf;	aabInf.setInfinite();
	m->setBoundingBox(aabInf);  // always visible
	m->setVisibilityFlags(vis);
	m->setRenderQueueGroup(rndQue);  //RQG_Hud2
	return m;
}
Exemplo n.º 6
0
void App::CreateRoadBezier()
{
	ManualObject* m = mSceneMgr->createManualObject();
	//m->begin("pipeGlass", RenderOperation::OT_TRIANGLE_LIST);
	m->begin("roadAsphalt", RenderOperation::OT_TRIANGLE_LIST);
	int ii=0;

	#ifdef SR_EDITOR
	const std::list <ROADSTRIP>& roads = track->GetRoadList();
	#else
	const std::list <ROADSTRIP>& roads = pGame->track.GetRoadList();
	#endif
	for (std::list <ROADSTRIP>::const_iterator it = roads.begin(); it != roads.end(); ++it)
	{
		#define VDR_LEN  // to get whole track length
		#ifdef VDR_LEN
		MATHVECTOR<float,3> vec0;  float length = 0.f;
		#endif
		const std::list <ROADPATCH>& pats = (*it).GetPatchList();
		for (std::list <ROADPATCH>::const_iterator i = pats.begin(); i != pats.end(); ++i)
		{
			float p[16][3];  int a=0;
			for (int y=0; y<4; ++y)
			for (int x=0; x<4; ++x)
			{
				const MATHVECTOR<float,3>& vec = (*i).GetPatch().GetPoint(x,y);
				p[a][0] = vec[2];  p[a][1] = vec[1] + 0.2f/*ofs up*/;  p[a][2] = -vec[0];  a++;
				
				#ifdef VDR_LEN
				if (x==1 && y==1 /*&& it == roads.begin()*/)  //main only-
				{
					if (i != pats.begin())  // sum distance
						length += (vec0-vec).Magnitude();
					vec0 = vec;
					//LogO(fToStr(length,2,6));
				}
				#endif
			}
			a=0;

			// normal
			Vector3 pos (p[a  ][0], p[a  ][1], p[a  ][2]);
			Vector3 posX(p[a+3][0], p[a+3][1], p[a+3][2]);   posX-=pos;  posX.normalise();
			Vector3 posY(p[a+12][0],p[a+12][1],p[a+12][2]);  posY-=pos;  posY.normalise();
			Vector3 norm = posX.crossProduct(posY);  norm.normalise();/**/

			for (int y=0; y<4; ++y)
			for (int x=0; x<4; ++x)
			{
				Vector3 pos(p[a][0], p[a][1], p[a][2]);  a++;
				m->position(pos);
				m->normal(norm);/**/
				m->textureCoord(y/3.f,x/3.f);
				if (x<3 && y<3)
				{
					int a = ii+x+y*4;
					m->index(a);	m->index(a+1);	m->index(a+4);
					m->index(a+5);	m->index(a+4);	m->index(a+1);
				}
			}
			ii += 16;
		}
		#ifdef VDR_LEN
		LogO("VDR TRK: " + pSet->gui.track +" LEN: "+fToStr(length,2,6));
		#endif
	}
	m->end();
	AxisAlignedBox aabInf;	aabInf.setInfinite();
	m->setBoundingBox(aabInf);  // always visible
	mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(m);
}
Exemplo n.º 7
0
ManualObject* CHud::CreateVdrMinimap()
{
	asp = float(app->mWindow->getWidth())/float(app->mWindow->getHeight());

	//  get track sizes
	minX=FLT_MAX; maxX=FLT_MIN;  minY=FLT_MAX; maxY=FLT_MIN;

	const std::list <ROADSTRIP>& roads = app->pGame->track.GetRoadList();
	for (std::list <ROADSTRIP>::const_iterator it = roads.begin(); it != roads.end(); ++it)
	{
		const std::list <ROADPATCH>& pats = (*it).GetPatchList();
		for (std::list <ROADPATCH>::const_iterator i = pats.begin(); i != pats.end(); ++i)
		{
			for (int iy=0; iy<4; ++iy)
			for (int ix=0; ix<4; ++ix)
			{
				const MATHVECTOR<float,3>& vec = (*i).GetPatch().GetPoint(ix,iy);

				Real x = vec[0], y = vec[2];
				if (x < minX)  minX = x;	if (x > maxX)  maxX = x;
				if (y < minY)  minY = y;	if (y > maxY)  maxY = y;
			}
		}
	}

	float fMapSizeX = maxX - minX, fMapSizeY = maxY - minY;  // map size
	float size = std::max(fMapSizeX, fMapSizeY);
	scX = 1.f / size;  scY = 1.f / size;

	ManualObject* m = app->mSceneMgr->createManualObject();
	m->begin("hud/Minimap", RenderOperation::OT_TRIANGLE_LIST);
	int ii = 0;

	for (std::list <ROADSTRIP>::const_iterator it = roads.begin(); it != roads.end(); ++it)
	{
		const std::list <ROADPATCH>& pats = (*it).GetPatchList();
		for (std::list <ROADPATCH>::const_iterator i = pats.begin(); i != pats.end(); ++i)
		{
			float p[16][3];  int a=0;
			for (int y=0; y<4; ++y)
			for (int x=0; x<4; ++x)
			{
				const MATHVECTOR<float,3>& vec = (*i).GetPatch().GetPoint(x,y);
				p[a][0] = vec[0];  p[a][1] = vec[2];  p[a][2] = vec[1];  a++;
			}
			a = 0;

			// normal
			Vector3 pos (p[a  ][2], -p[a  ][0], p[a  ][1]);
			Vector3 posX(p[a+3][2], -p[a+3][0], p[a+3][1]);   posX-=pos;  posX.normalise();
			Vector3 posY(p[a+12][2],-p[a+12][0],p[a+12][1]);  posY-=pos;  posY.normalise();
			Vector3 norm = posX.crossProduct(posY);  norm.normalise();/**/

			for (int y=0; y<4; ++y)
			for (int x=0; x<4; ++x)
			{
				Vector3 pos( (p[a][0] - minX)*scX*2-1,	// pos x,y = -1..1
							-(p[a][1] - minY)*scY*2+1, 0);  a++;
				m->position(pos);
				m->normal(norm);/**/

				Real c = std::min(1.f, std::max(0.3f, 1.f - 2.4f * powf( fabs(norm.y)
					/*norm.absDotProduct(vLi)*/, 0.7f) ));
				m->colour(ColourValue(c,c,c,1));

				m->textureCoord(x/3.f,y/3.f);
				if (x<3 && y<3)
				{
					int a = ii+x+y*4;
					m->index(a+0);	m->index(a+1);	m->index(a+4);
					m->index(a+1);	m->index(a+4);	m->index(a+5);
				}
			}
			ii += 16;
		}
	}
	m->end();
	m->setUseIdentityProjection(true);  m->setUseIdentityView(true);  // on hud
	m->setCastShadows(false);
	AxisAlignedBox aab;  aab.setInfinite();  m->setBoundingBox(aab);  // draw always
	m->setRenderingDistance(100000.f);
	m->setRenderQueueGroup(RQG_Hud2);  m->setVisibilityFlags(RV_Hud);
	return m;
}
//-------------------------------------------------------------------------------------
void Ogre3DRendererPlugin::createDesktopObject() {
  // Create the texture
    GLTexturePtr t = GLTextureManager::getSingleton().createManual("DynamicTexture", // name
        Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
        Ogre::TEX_TYPE_2D,      // type
        1280, 800,         // width & height
        1, //depth
        MIP_DEFAULT,//0,                // number of mipmaps
        Ogre::PF_BYTE_RGBA,     // pixel format
        Ogre::TU_DYNAMIC_WRITE_ONLY_DISCARDABLE,
        0);//TU_DEFAULT);

  t->_fireLoadingComplete(true);
  std::cerr << "**** DESKTOP TEXTURE: " << this->desktopTexture << std::endl;
  desktopTexture = t->getHandle();//getGLID();//texture->getHandle();
  std::cerr << "**** DESKTOP TEXTURE: " << this->desktopTexture << std::endl;

// Create a material using the texture
 /*Ogre::MaterialPtr */material = Ogre::MaterialManager::getSingleton().create(
     "DynamicTextureMaterial", // name
     Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);

 material->getTechnique(0)->getPass(0)->createTextureUnitState("DynamicTexture");
 material->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SBT_REPLACE);//SBT_TRANSPARENT_ALPHA);
//return;
//  ogreHead->setMaterial(material);

 Ogre::ManualObject* manual = mSceneMgr->createManualObject("manual");
//  manual->begin("DynamicTextureMaterial", Ogre::RenderOperation::OT_TRIANGLE_STRIP, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
 manual->begin("BlankWhiteMaterial", Ogre::RenderOperation::OT_TRIANGLE_STRIP, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);

 manual->textureCoord(0, 0);
 manual->position(-40.0, -40.0, 0.0);  // start position
 manual->textureCoord(1, 0);
 manual->position( 40.0, -40.0, 0.0);  // draw first line
 manual->textureCoord(0, 1);
 manual->position(-40.0, 40.0, 0.0);
 manual->textureCoord(1, 1);
 manual->position(40.0,  40.0, 0.0);

 manual->end();
//  mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(manual);


  ManualObject *manObj; // we will use this Manual Object as a reference point for the native rendering
  manObj = mSceneMgr->createManualObject("sampleArea");

  Ogre::AxisAlignedBox b(-40, -40, -40, 40, 40, 40);
  manObj->setBoundingBox(b);

  // Attach to child of root node, better for culling (otherwise bounds are the combination of the 2)
  Ogre::SceneNode *desktopNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
  desktopNode->attachObject(manObj);
  desktopNode->setPosition(40, 15, 0);

  String RenderSystemName = mSceneMgr->getDestinationRenderSystem()->getName();
  mRenderSystemCommandsRenderQueueListener = new OpenGLNativeRenderSystemCommandsRenderQueueListener(manObj, mCamera2, mSceneMgr);

  mSceneMgr->addRenderQueueListener(mRenderSystemCommandsRenderQueueListener);

  std::cerr << "***** DONE CONFIGURE and INIT SCENE" << std::endl;
}