Example #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;
}
Example #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
}
Example #3
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;
}
Example #4
0
	void VideoManager::createQuad(String name,String material_name,float left,float top,float right,float bottom)
	{
		ManualObject* model = OgreManager::getSingleton().getSceneManager()->createManualObject(name);
		model->begin(material_name);

		model->position(right,bottom,0); model->textureCoord(1,1);
		model->position(right,top   ,0); model->textureCoord(1,0);
		model->position(left ,top   ,0); model->textureCoord(0,0);
		model->position(left ,top   ,0); model->textureCoord(0,0);
		model->position(right,bottom,0); model->textureCoord(1,1);
		model->position(left, bottom,0); model->textureCoord(0,1);

		model->end();
		// make the model 2D
		model->setUseIdentityProjection(true);
		model->setUseIdentityView(true);
		// and atach it to the root node
		SceneNode* node = OgreManager::getSingleton().getSceneManager()->getRootSceneNode()->createChildSceneNode();
		node->attachObject(model);
	}
Example #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;
}
Example #6
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;
}