Example #1
0
void GridLineFactory::createMaterials(void)
{
	Ogre::MaterialPtr myManualObjectMaterial = Ogre::MaterialManager::getSingleton().create("RedGridLine","General"); 
	myManualObjectMaterial->setReceiveShadows(false); 
	myManualObjectMaterial->getTechnique(0)->setLightingEnabled(true); 
	myManualObjectMaterial->getTechnique(0)->getPass(0)->setDiffuse(1,0,0,0); 
	myManualObjectMaterial->getTechnique(0)->getPass(0)->setAmbient(1,0,0); 
	myManualObjectMaterial->getTechnique(0)->getPass(0)->setSelfIllumination(1,0,0); 
	//myManualObjectMaterial->dispose();  // dispose pointer, not the material
	
	myManualObjectMaterial = Ogre::MaterialManager::getSingleton().create("GreenGridLine","General"); 
	myManualObjectMaterial->setReceiveShadows(false); 
	myManualObjectMaterial->getTechnique(0)->setLightingEnabled(true); 
	myManualObjectMaterial->getTechnique(0)->getPass(0)->setDiffuse(0,1,0,0); 
	myManualObjectMaterial->getTechnique(0)->getPass(0)->setAmbient(0,1,0); 
	myManualObjectMaterial->getTechnique(0)->getPass(0)->setSelfIllumination(0,1,0); 
	
	myManualObjectMaterial = Ogre::MaterialManager::getSingleton().create("BlueGridLine","General"); 
	myManualObjectMaterial->setReceiveShadows(false); 
	myManualObjectMaterial->getTechnique(0)->setLightingEnabled(true); 
	myManualObjectMaterial->getTechnique(0)->getPass(0)->setDiffuse(0,0,1,0); 
	myManualObjectMaterial->getTechnique(0)->getPass(0)->setAmbient(0,0,1); 
	myManualObjectMaterial->getTechnique(0)->getPass(0)->setSelfIllumination(0,0,1); 
	
	//materialsCreated = true;
}
Example #2
0
/**-------------------------------------------------------------------------------
    SensorDecoratorVector

    @brief
    @param color
    @return
---------------------------------------------------------------------------------*/
SensorDecoratorVector::SensorDecoratorVector(Sensor* sensor, const Ogre::ColourValue& color, bool persistent)
	: SensorDecorator(sensor), ManualObject(sensor->getSensorName())
{
	Ogre::SceneNode* myManualObjectNode = getSimulation()->getScene()->getSceneManager().getRootSceneNode()->createChildSceneNode(mName + "_node");

	Ogre::MaterialPtr myManualObjectMaterial = Ogre::MaterialManager::getSingleton().create(mName + "Material", OGRE_DEBUG_GROUP);
	myManualObjectMaterial->setReceiveShadows(false);
	myManualObjectMaterial->getTechnique(0)->setLightingEnabled(true);
	myManualObjectMaterial->getTechnique(0)->getPass(0)->setDiffuse(color);
	myManualObjectMaterial->getTechnique(0)->getPass(0)->setAmbient(color);
	myManualObjectMaterial->getTechnique(0)->getPass(0)->setSelfIllumination(color);

	myManualObjectNode->attachObject(this);

	mPersistent = persistent;
	mVisible = false;

	Ogre::Vector3 zero(0,0,0);
	begin(mName + "Material", Ogre::RenderOperation::OT_LINE_LIST);
	position(zero);
	position(zero);
	position(zero);
	position(zero);
	position(zero);
	position(zero);
	position(zero);
	position(zero);
	position(zero);
	position(zero);
	end();
}
Example #3
0
void EC_SkyBox::CreateSky()
{
    if (!ViewEnabled())
        return;

    if (renderer_.expired())
        return;

    QString currentMaterial = materialRef.Get().ref;

    Ogre::MaterialPtr materialPtr = Ogre::MaterialManager::getSingleton().getByName(currentMaterial.toStdString().c_str());
    if (materialPtr.isNull())
    {
        LogError("Could not get SkyBox material : " + currentMaterial.toStdString());
        return;
    }

    materialPtr->setReceiveShadows(false);

    try
    {
        //RexTypes::Vector3 v = angleAxisAttr.Get();
        //Ogre::Quaternion rotation(Ogre::Degree(90.0), Ogre::Vector3(1, 0, 0));
        Quaternion o = orientation.Get();
        renderer_.lock()->GetSceneManager()->setSkyBox(true, currentMaterial.toStdString().c_str(), distance.Get(),
            drawFirst.Get(), Ogre::Quaternion(o.w, o.x, o.y, o.z));
    }
    catch(Ogre::Exception& e)
    {
        LogError("Could not set SkyBox: " + std::string(e.what()));
    }
}
Example #4
0
PDebugger::PDebugger(Ogre::SceneManager *mgr, PLevel *lv, PPlayer *pl) :
    mNode(NULL), mLevel(lv), mPlayer(pl)
{
    mMObject = new Ogre::ManualObject("PLevelDebug");
    Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().create("matDebug","Grup_prova");
    mat->setReceiveShadows(false);
    mat->getTechnique(0)->setLightingEnabled(true);
    mat->getTechnique(0)->getPass(0)->setDiffuse(0,1,0,0);
    mat->getTechnique(0)->getPass(0)->setAmbient(0,1,0);
    mat->getTechnique(0)->getPass(0)->setSelfIllumination(0,1,0);
    mMObject->begin("matDebug", Ogre::RenderOperation::OT_LINE_LIST);
    //comencem indexacio
    cpShape *shape;
    cpSegmentShape *s;
    cpVect v;
    const Ogre::Real zeta = -7.0f;
    for(int i=0;; i++)
    {
        shape = mLevel->getSegment(i);
        if(shape==NULL) break; //ja hem acabat
        v = cpSegmentShapeGetA(shape);
        mMObject->position(v.x, v.y, zeta);
        std::cerr << v.x << "  " << v.y << std::endl;
        v = cpSegmentShapeGetB(shape);
        mMObject->position(v.x, v.y, zeta);
        std::cerr << v.x << "  " << v.y << std::endl;
    }

    mMObject->end();
    mNode = mgr->getRootSceneNode()->createChildSceneNode("PLevelDebugNode");
    mNode->attachObject(mMObject);
}
Example #5
0
void EC_Sky::CreateSky()
{
    if (!ViewEnabled())
        return;

    if (world_.expired())
        return;

    QString currentMaterial = materialRef.Get().ref;

    Ogre::MaterialPtr materialPtr = Ogre::MaterialManager::getSingleton().getByName(currentMaterial.toStdString().c_str());
    //Ogre::MaterialPtr materialPtr = Ogre::MaterialManager::getSingleton().getByName(framework->Asset()->LookupAssetRefToStorage(materialRef.Get().ref).toStdString().c_str());
    if (materialPtr.isNull())
    {
        LogError("Could not get SkyBox material : " + currentMaterial.toStdString());
        return;
    }

    materialPtr->setReceiveShadows(false);

    try
    {
        world_.lock()->GetSceneManager()->setSkyBox(true, currentMaterial.toStdString().c_str(), distance.Get(),
            drawFirst.Get(), orientation.Get());
    }
    catch(Ogre::Exception& e)
    {
        LogError("Could not set SkyBox: " + std::string(e.what()));
    }
}
Example #6
0
	void _drawGridPlane(void)
	{
		Ogre::ManualObject* gridPlane = mSceneMgr->createManualObject("GridPlane");
		Ogre::SceneNode* gridPlaneNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("GridPlaneNode");

		Ogre::MaterialPtr gridPlaneMaterial = Ogre::MaterialManager::getSingleton().create("GridPlanMaterial", "General");
		gridPlaneMaterial->setReceiveShadows(false);
		gridPlaneMaterial->getTechnique(0)->setLightingEnabled(true);
		gridPlaneMaterial->getTechnique(0)->getPass(0)->setDiffuse(1, 1, 1, 0);
		gridPlaneMaterial->getTechnique(0)->getPass(0)->setAmbient(1, 1, 1);
		gridPlaneMaterial->getTechnique(0)->getPass(0)->setSelfIllumination(1, 1, 1);

		gridPlane->begin("GridPlaneMaterial", Ogre::RenderOperation::OT_LINE_LIST);
		for (int i = 0; i < 21; i++)
		{
			gridPlane->position(-500.0f, 0.0f, 500.0f - i * 50);
			gridPlane->position(500.0f, 0.0f, 500.0f - i * 50);

			gridPlane->position(-500.f + i * 50, 0.f, 500.0f);
			gridPlane->position(-500.f + i * 50, 0.f, -500.f);
		}

		gridPlane->end();

		gridPlaneNode->attachObject(gridPlane);
	}
Example #7
0
void OgreBtDebugDrawer::initialize(Ogre::SceneManager* const sceneManager,
		const bool drawTrajectory) {
	mDrawTrajectory = drawTrajectory;
	mContactPoints = &mContactPoints1;
	mLines = new Ogre::ManualObject("BulletPhysicsLines1");
	mLines2 = new Ogre::ManualObject("BulletPhysicsLines2");

	mTriangles = new Ogre::ManualObject("BulletPhysicsTriangles1");
	mTriangles2 = new Ogre::ManualObject("BulletPhysicsTriangles2");

	mLines->setDynamic(true);
	mLines2->setDynamic(true);
	mTriangles->setDynamic(true);
	mTriangles2->setDynamic(true);
	//mLines->estimateVertexCount( 100000 );
	//mLines->estimateIndexCount( 0 );

	sceneManager->getRootSceneNode()->attachObject(mLines);
	sceneManager->getRootSceneNode()->attachObject(mLines2);
	sceneManager->getRootSceneNode()->attachObject(mTriangles);
	sceneManager->getRootSceneNode()->attachObject(mTriangles2);

	static const char* matName = "OgreBulletCollisionsDebugDefault";
	Ogre::MaterialPtr mtl =
			Ogre::MaterialManager::getSingleton().getDefaultSettings()->clone(
					matName);
	mtl->setReceiveShadows(false);
	mtl->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
	mtl->setDepthBias(0.1, 0);
	Ogre::TextureUnitState * tu =
			mtl->getTechnique(0)->getPass(0)->createTextureUnitState();

	tu->setColourOperationEx(Ogre::LBX_SOURCE1, Ogre::LBS_DIFFUSE);
	mtl->getTechnique(0)->setLightingEnabled(false);
	//mtl->getTechnique(0)->setSelfIllumination( ColourValue::White );

	//for the ogre text
	Ogre::Root::getSingleton().addFrameListener(this);
	//TODO: Add 3D text writing capability to ogreBtdebugdrawer #133.
//	olm = Ogre::OverlayManager::getSingletonPtr();
//	panel = static_cast<Ogre::OverlayContainer*>(olm->createOverlayElement(
//			"Panel", "OGREBTDEBUGDRAWER_GUI"));
//	panel->setMetricsMode(Ogre::GMM_PIXELS);
//	panel->setPosition(0, 0);
//	panel->setDimensions(1.0f, 1.0f);
//	overlay = olm->create("OGREBTDEBUGDRAWER_OVERLAY");
//	overlay->add2D(panel);
//
//	szElement = "element_";
//	overlay = olm->getByName("OGREBTDEBUGDRAWER_OVERLAY");
//	panel = static_cast<Ogre::OverlayContainer*>(olm->getOverlayElement(
//			"OGREBTDEBUGDRAWER_GUI"));
//	textArea =
//			static_cast<Ogre::TextAreaOverlayElement*>(olm->createOverlayElement(
//					"TextArea", szElement));
//	panel->addChild(textArea);
//	overlay->show();

}
//----------------------------------------------------------------------------------------
 void PortalOutlineRenderable::createPortalMaterials(void)
 {
	Ogre::ColourValue colour = Ogre::ColourValue(0,1,0);//
	Ogre::String matname = "PortalOutlineMaterial";

	Ogre::ResourceManager::ResourceCreateOrRetrieveResult result = Ogre::MaterialManager::getSingleton().createOrRetrieve(matname, "General");
	if(result.second)
	{
		Ogre::MaterialPtr freePortalMaterial = result.first;
	    freePortalMaterial->setReceiveShadows(false);
	    freePortalMaterial->getTechnique(0)->setLightingEnabled(true);
	    freePortalMaterial->getTechnique(0)->getPass(0)->setDiffuse(colour);
	    freePortalMaterial->getTechnique(0)->getPass(0)->setAmbient(colour);
	    freePortalMaterial->getTechnique(0)->getPass(0)->setSelfIllumination(colour);
	}

	colour = Ogre::ColourValue(1,1,0);//Yellow
	matname = "PortalOutlineMaterialConnected";
	result = Ogre::MaterialManager::getSingleton().createOrRetrieve(matname, "General");
	if(result.second)
	{
		Ogre::MaterialPtr connectedPortalMaterial = result.first;
	    connectedPortalMaterial->setReceiveShadows(false);
	    connectedPortalMaterial->getTechnique(0)->setLightingEnabled(true);
	    connectedPortalMaterial->getTechnique(0)->getPass(0)->setDiffuse(colour);
	    connectedPortalMaterial->getTechnique(0)->getPass(0)->setAmbient(colour);
	    connectedPortalMaterial->getTechnique(0)->getPass(0)->setSelfIllumination(colour);
	}

	colour = Ogre::ColourValue(1,0,0);//Red
	matname = "PortalOutlineMaterialLinked";
	result = Ogre::MaterialManager::getSingleton().createOrRetrieve(matname, "General");
	if(result.second)
	{
		Ogre::MaterialPtr linkedPortalMaterial = result.first;
	    linkedPortalMaterial->setReceiveShadows(false);
	    linkedPortalMaterial->getTechnique(0)->setLightingEnabled(true);
	    linkedPortalMaterial->getTechnique(0)->getPass(0)->setDiffuse(colour);
	    linkedPortalMaterial->getTechnique(0)->getPass(0)->setAmbient(colour);
	    linkedPortalMaterial->getTechnique(0)->getPass(0)->setSelfIllumination(colour);
	}

 }
void createColorMaterial(const std::string& name, const Ogre::ColourValue& color, bool use_self_illumination)
{
    Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().create( name, ROS_PACKAGE_NAME );
    mat->setAmbient(color * 0.5f);
    mat->setDiffuse(color);
    if( use_self_illumination )
    {
        mat->setSelfIllumination(color);
    }
    mat->setLightingEnabled(true);
    mat->setReceiveShadows(false);
}
  VideoVisual::VideoVisual(
      const std::string &name, rendering::VisualPtr parent, 
      int height, int width) : 
      rendering::Visual(name, parent), height_(height), width_(width) 
  {

    texture_ = Ogre::TextureManager::getSingleton().createManual(
        name + "__VideoTexture__",
        Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
        Ogre::TEX_TYPE_2D,
        width_, height_,
        0,
        Ogre::PF_BYTE_BGRA,
        Ogre::TU_DYNAMIC_WRITE_ONLY_DISCARDABLE);

    Ogre::MaterialPtr material =
      Ogre::MaterialManager::getSingleton().create(
          name + "__VideoMaterial__", "General");
    material->getTechnique(0)->getPass(0)->createTextureUnitState(
        name + "__VideoTexture__");
    material->setReceiveShadows(false);

    double factor = 1.0;

    Ogre::ManualObject mo(name + "__VideoObject__");
    mo.begin(name + "__VideoMaterial__",
        Ogre::RenderOperation::OT_TRIANGLE_LIST);

    mo.position(-factor / 2, factor / 2, 0.51);
    mo.textureCoord(0, 0);

    mo.position(factor / 2, factor / 2, 0.51);
    mo.textureCoord(1, 0);

    mo.position(factor / 2, -factor / 2, 0.51);
    mo.textureCoord(1, 1);

    mo.position(-factor / 2, -factor / 2, 0.51);
    mo.textureCoord(0, 1);

    mo.triangle(0, 3, 2);
    mo.triangle(2, 1, 0);
    mo.end();

    mo.convertToMesh(name + "__VideoMesh__");

    Ogre::MovableObject *obj = (Ogre::MovableObject*)
      this->GetSceneNode()->getCreator()->createEntity(
          name + "__VideoEntity__",
          name + "__VideoMesh__");
    obj->setCastShadows(false);
    this->AttachObject(obj);
  }
Example #11
0
DebugDrawer::DebugDrawer(Ogre::SceneNode *node, btDynamicsWorld *world) :
	mNode(node), mWorld(world), m_debugMode(0)
{
	mLineDrawer = new DynamicLines(Ogre::RenderOperation::OT_LINE_LIST);
	mLineDrawer->setCastShadows(false); //`
	mNode->attachObject(mLineDrawer);

	Ogre::ResourceGroupManager::getSingleton().createResourceGroup("BtOgre");
	Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().create("BtOgre/DebugLines", "BtOgre");
	mat->setReceiveShadows(false);
	mat->setLightingEnabled(false);
	//mat->setSelfIllumination(1,1,1);
	mLineDrawer->setMaterial("BtOgre/DebugLines");/**/  //crash debug..
}
Example #12
0
 void
 setupMaterial() {
     Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().getDefaultSettings()->clone(
         MATERIAL_NAME
     );
     material->setReceiveShadows(false);
     material->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
     material->setDepthBias(0.1, 0);
     Ogre::TextureUnitState* textureUnitState = material->getTechnique(0)->getPass(0)->createTextureUnitState();
     textureUnitState->setColourOperationEx(
         Ogre::LBX_SOURCE1,
         Ogre::LBS_DIFFUSE
     );
     material->getTechnique(0)->setLightingEnabled(false);
 }
Example #13
0
void
	Player::createHitBox(std::string name)
{
	Ogre::ManualObject* myManualObject =  mSceneManager->createManualObject(name); 
	myManualObject->setDynamic(true);
	Ogre::SceneNode* myManualObjectNode = mSceneManager->getRootSceneNode()->createChildSceneNode(name + "_node"); 

	Ogre::MaterialPtr myManualObjectMaterial = Ogre::MaterialManager::getSingleton().create(name + "Material","General"); 
	myManualObjectMaterial->setReceiveShadows(false); 
	myManualObjectMaterial->getTechnique(0)->setLightingEnabled(true);
	myManualObjectMaterial->getTechnique(0)->getPass(0)->setDiffuse(1,0,0,0); 
	myManualObjectMaterial->getTechnique(0)->getPass(0)->setAmbient(1,0,0); 
	myManualObjectMaterial->getTechnique(0)->getPass(0)->setSelfIllumination(1,0,0);

	myManualObjectNode->attachObject(myManualObject);
}
  std::string createMaterialIfNotExists(const float r, const float g, const float b, const float a)
  {
    char buf[128];
    sprintf(buf, "ShapeColor%f;%f;%f;%f",r,g,b,a);
    if(!Ogre::MaterialManager::getSingleton().getByName(buf, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME).isNull())
      return buf;

    Ogre::ColourValue color( r,g,b,a );
    Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().create( buf, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME );
    mat->setAmbient(color * 0.01f);
    mat->setDiffuse(color);
    mat->setLightingEnabled(true);
    mat->setReceiveShadows(true);
    mat->setCullingMode(Ogre::CULL_NONE);

    return buf;
  }
void AxisComponent::addMaterial(const Ogre::String &mat, Ogre::ColourValue &clr, Ogre::SceneBlendType sbt)
{
	static int init=false;
	if(init)
		return;
	else
		init=true;

	Ogre::MaterialPtr matptr = Ogre::MaterialManager::getSingleton().create(mat, "General"); 
	matptr->setReceiveShadows(false); 
	matptr->getTechnique(0)->setLightingEnabled(true);
	matptr->getTechnique(0)->getPass(0)->setDiffuse(clr); 
	matptr->getTechnique(0)->getPass(0)->setAmbient(clr); 
	matptr->getTechnique(0)->getPass(0)->setSelfIllumination(clr); 
	matptr->getTechnique(0)->getPass(0)->setSceneBlending(sbt);
	matptr->getTechnique(0)->getPass(0)->setLightingEnabled(false);
	matptr->getTechnique(0)->getPass(0)->setVertexColourTracking(Ogre::TVC_DIFFUSE);
}
 void PolygonArrayDisplay::allocateMaterials(int num)
 {
   if (only_border_) {
     return;
   }
   static uint32_t count = 0;
   
   if (num > materials_.size()) {
     for (size_t i = materials_.size(); num > i; i++) {
       std::stringstream ss;
       ss << "PolygonArrayMaterial" << count++;
       Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().create(ss.str(), "rviz");
       material->setReceiveShadows(false);
       material->getTechnique(0)->setLightingEnabled(true);
       material->getTechnique(0)->setAmbient(0.5, 0.5, 0.5);
       materials_.push_back(material);
     }
   }
 }
Example #17
0
	void OgreModule::initEnd()
	{
		Ogre::CompositorManager2* compositorManager = mOgreRoot.getCompositorManager2();
		compositorManager->createBasicWorkspaceDef("Basic Workspace", Ogre::ColourValue(0.15f, 0.15f, 0.15f));
		compositorManager->createBasicWorkspaceDef("Black Workspace", Ogre::ColourValue::Black);

		Ogre::MaterialManager* materialManager = Ogre::MaterialManager::getSingletonPtr();
		Ogre::MaterialPtr material = materialManager->create("debug_invisible", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
		material->setReceiveShadows(false);
		Ogre::Pass* pass = material->getTechnique(0)->getPass(0);
#if OGRE_VERSION_MAJOR == 2 && OGRE_VERSION_MINOR > 0
#else
		pass->setCullingMode(Ogre::CULL_NONE);
		pass->setColourWriteEnabled(false);
		pass->setDepthWriteEnabled(false);
#endif

		this->loadResources();
	}
Example #18
0
void RenderWindow::CreateRenderTargetOverlay(int width, int height)
{
    width = max(1, width);
    height = max(1, height);

    Ogre::TexturePtr renderTarget = Ogre::TextureManager::getSingleton().createManual(
        rttTextureName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
        Ogre::TEX_TYPE_2D, width, height, 0, Ogre::PF_A8R8G8B8, Ogre::TU_DYNAMIC_WRITE_ONLY_DISCARDABLE);

    Ogre::MaterialPtr rttMaterial = Ogre::MaterialManager::getSingleton().create(
        rttMaterialName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);

    Ogre::TextureUnitState *rttTuState = rttMaterial->getTechnique(0)->getPass(0)->createTextureUnitState();

    rttTuState->setTextureName(rttTextureName);
    rttTuState->setTextureFiltering(Ogre::TFO_NONE);
    rttTuState->setNumMipmaps(1);
    rttTuState->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);

    rttMaterial->setFog(true, Ogre::FOG_NONE); ///\todo Check, shouldn't here be false?
    rttMaterial->setReceiveShadows(false);
    rttMaterial->setTransparencyCastsShadows(false);

    rttMaterial->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SBF_SOURCE_ALPHA, Ogre::SBF_ONE_MINUS_SOURCE_ALPHA);
    rttMaterial->getTechnique(0)->getPass(0)->setDepthWriteEnabled(false);
    rttMaterial->getTechnique(0)->getPass(0)->setDepthCheckEnabled(false);
    rttMaterial->getTechnique(0)->getPass(0)->setLightingEnabled(false);
    rttMaterial->getTechnique(0)->getPass(0)->setCullingMode(Ogre::CULL_NONE);

    overlayContainer = Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "MainWindow Overlay Panel");
    overlayContainer->setMaterialName(rttMaterialName);
    overlayContainer->setMetricsMode(Ogre::GMM_PIXELS);
    overlayContainer->setPosition(0, 0);
    overlayContainer->setDimensions((Ogre::Real)width, (Ogre::Real)height);
    overlayContainer->setPosition(0,0);

    overlay = Ogre::OverlayManager::getSingleton().create("MainWindow Overlay");
    overlay->add2D(static_cast<Ogre::OverlayContainer *>(overlayContainer));
    overlay->setZOrder(500);
    overlay->show();

//    ResizeOverlay(width, height);
}
Example #19
0
void McsHudGui::addFrameGraph(CEGUI::Window* sheet)
{
    Ogre::TexturePtr tex = mOgreRoot->getTextureManager()->createManual(
                               "FrameGraph", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D,
                               TimeGraphMaxFrames, TimeGraphMaxResolution, 0, Ogre::PF_R8G8B8, Ogre::TU_RENDERTARGET);

    Ogre::SceneManager* debugSceneMgr = mOgreRoot->createSceneManager(Ogre::ST_GENERIC);
    debugSceneMgr->setAmbientLight(Ogre::ColourValue(1.0f, 1.0f, 1.0f));

    Ogre::MaterialPtr frameLinesMaterial = Ogre::MaterialManager::getSingleton().create("frameLinesMaterial","Game");
    frameLinesMaterial->setReceiveShadows(false);
    frameLinesMaterial->getTechnique(0)->setLightingEnabled(false);
    frameLinesMaterial->getTechnique(0)->getPass(0)->setDepthCheckEnabled(false);
    frameLinesMaterial->getTechnique(0)->getPass(0)->setDepthWriteEnabled(false);

    mFrameLines = new FrameGraphRenderable(TimeGraphMaxFrames, TimeGraphMaxResolution);
    mFrameLines->setMaterial("frameLinesMaterial");

    Ogre::SceneNode* frameLinesNode = debugSceneMgr->getRootSceneNode()->createChildSceneNode("frameGraph_node");
    frameLinesNode->attachObject(mFrameLines);
    Ogre::Camera* dbg_camera = debugSceneMgr->createCamera("item_camera");
    dbg_camera->setAspectRatio(static_cast<Ogre::Real>(TimeGraphMaxFrames) / static_cast<Ogre::Real>(TimeGraphMaxResolution));
    Ogre::Viewport *v = tex->getBuffer()->getRenderTarget()->addViewport(dbg_camera);
    v->setClearEveryFrame( true );
    v->setBackgroundColour( Ogre::ColourValue::Black );



    CEGUI::Texture& guiTex = mCeRenderer->createTexture(tex);
    CEGUI::Imageset& imageSet = CEGUI::ImagesetManager::getSingleton().create("FrameGraphImageset", guiTex);
    imageSet.defineImage("FrameGraphImage", CEGUI::Point(0.0f, 0.0f), CEGUI::Size(guiTex.getSize()), CEGUI::Point(0.0f, 0.0f));
    CEGUI::Window* si = CEGUI::WindowManager::getSingleton().createWindow("TaharezLook/StaticImage", "FrameGraphWindow");
    si->setSize(CEGUI::UVector2(CEGUI::UDim(0.0f, TimeGraphMaxFrames), CEGUI::UDim(0.0f, TimeGraphMaxResolution)));
    si->setPosition(CEGUI::UVector2(CEGUI::UDim(0.0f, 0), CEGUI::UDim(1.0f, -TimeGraphMaxResolution)));
    si->setProperty("Image", CEGUI::PropertyHelper::imageToString(&imageSet.getImage("FrameGraphImage")));
    si->setAlpha(0.6f);
    si->setProperty("BackgroundEnabled", "False");
    si->setProperty("FrameEnabled", "False");

    sheet->addChildWindow(si);
}
void MainApplication::shoot()
{
    
    Ogre::String number2 = Ogre::StringConverter::toString(shotCounter + 1); 
    shots.push_back("manual1_node" + number2);
    /*
    Ogre::Entity* ogreHead = mSceneMgr -> createEntity("ogrehead.mesh");
    Ogre::SceneNode *headNode = mSceneMgr -> getRootSceneNode() -> createChildSceneNode("manual1_node" + number2);
    Ogre::Vector3 pos1(mSceneMgr-> getSceneNode("NinjaNode")->getPosition());
    headNode -> setPosition(pos1);
    headNode -> attachObject(ogreHead);
    */
    Ogre::ManualObject* myManualObject =  mSceneMgr->createManualObject("manual1" + number2); 
    Ogre::SceneNode* myManualObjectNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("manual1_node" + number2); 
     
    // NOTE: The second parameter to the create method is the resource group the material will be added to.
    // If the group you name does not exist (in your resources.cfg file) the library will assert() and your program will crash
    Ogre::MaterialPtr myManualObjectMaterial = Ogre::MaterialManager::getSingleton().create("manual1Material","General"); 
    myManualObjectMaterial->setReceiveShadows(false); 
    myManualObjectMaterial->getTechnique(0)->setLightingEnabled(true); 
    myManualObjectMaterial->getTechnique(0)->getPass(0)->setDiffuse(0,0,1,0); 
    myManualObjectMaterial->getTechnique(0)->getPass(0)->setAmbient(0,0,1); 
    myManualObjectMaterial->getTechnique(0)->getPass(0)->setSelfIllumination(0,0,1); 
    //myManualObjectMaterial->dispose();  // dispose pointer, not the material
     
    Ogre::Vector3 pos1(mSceneMgr-> getSceneNode("NinjaNode")->getPosition());//Get position of player
     
    myManualObject->begin("manual1Material", Ogre::RenderOperation::OT_LINE_LIST); 
    myManualObject->position(pos1.x + 20, pos1.y, pos1.z); 
    myManualObject->position(pos1.x + 50, pos1.y, pos1.z); 
    // etc 
    myManualObject->end(); 
    myManualObjectNode->attachObject(myManualObject);
    shotCounter++;
    
}
CFootballPlayer::CFootballPlayer(CSimulationManager *simulationManager, const CPfTeamPlayers *teamPlayer, int number, CTeam *team, bool sideLeft)
:CMovingEntity()
{
	m_simulationManager = simulationManager;

	Ogre::SceneManager *scnMgr = Ogre::Root::getSingletonPtr()->getSceneManager(SIMULATION_SCENE_MANAGER_NODE_NAME);

    m_teamPlayer = new CPfTeamPlayers(*teamPlayer);
    m_stateMachine = new CStateMachine<CFootballPlayer>(this);
    Ogre::String id;
    char charId[20];
    m_centerOfMassOffset.setOrigin(btVector3(0,-0.9,0));
    m_sideLeft = sideLeft;
    m_team = team;
    m_number = number; //TODO
    m_lastKickBallCycle = -1;

    //m_direction.normalize();
    sprintf(charId,"%s%d", team->getName().c_str(), m_number);
    id = charId;
    m_entity = scnMgr->createEntity("Player"+id, "Human.mesh");
    if(sideLeft) {
        if(m_number == 1) {
            m_entity->setMaterialName("goalie_red");
        } else {
            m_entity->setMaterialName("player_red");
        }
    } else {
        if(m_number == 1) {
            m_entity->setMaterialName("goalie_yellow");
        } else {
            m_entity->setMaterialName("player_yellow");
        }
    }
    btVector3 *initialPos = team->getPlayerStrategicPosition(m_number)->getInitialPosition();
    btVector3 pos(initialPos->x(), initialPos->y(), initialPos->z());
    if(!m_sideLeft) {
        pos.setX(-pos.x());
        pos.setZ(-pos.z());
    }
    m_node = scnMgr->getRootSceneNode()->createChildSceneNode("PlayerNode"+id, Ogre::Vector3(pos.x(), pos.y(), pos.z()));
    m_node->attachObject(m_entity);
    m_shape = new btCylinderShape(btVector3(btScalar(0.5),btScalar(0.9),btScalar(0.5)));
    btScalar mass(70.0);

    //rigidbody is dynamic if and only if mass is non zero, otherwise static
    bool isDynamic = (mass != 0.f);

    btVector3 localInertia(0,0,0);
    if (isDynamic)
        m_shape->calculateLocalInertia(mass,localInertia);
    btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,this,m_shape,localInertia);
    m_body = new btRigidBody(rbInfo);
    m_body->setAngularFactor(btScalar(0));
    m_body->setActivationState(DISABLE_DEACTIVATION);

    m_steeringBehavior = new CSteeringBehaviors(this);


    //Draw Circle
    Ogre::ManualObject * circle = scnMgr->createManualObject("circle_name"+id);

    float const radius = 1.5,
                thickness = 0.7, // Of course this must be less than the radius value.
                accuracy = 5,
                height = 0.01;

    Ogre::MaterialPtr matptr;
    Ogre::Pass* pass;

    if(sideLeft) {
        matptr = Ogre::MaterialManager::getSingleton().createOrRetrieve("Red"+id, "General").first;
        matptr->setReceiveShadows(true);
        pass = matptr->getTechnique(0)->getPass(0);
        Ogre::ColourValue colour = Ogre::ColourValue::Red;
        pass->setDiffuse(colour);
        pass->setAmbient(colour);
        pass->setSpecular(colour);
        pass->setSelfIllumination(colour);
        //pass->setEmissive(ColourValue(0,0,0,colour.a));
        pass->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
        pass->setDepthWriteEnabled(false);
    } else {
        matptr = Ogre::MaterialManager::getSingleton().createOrRetrieve("Blue"+id, "General").first;
        matptr->setReceiveShadows(true);
        pass = matptr->getTechnique(0)->getPass(0);
        Ogre::ColourValue colour = Ogre::ColourValue::Blue;
        pass->setDiffuse(colour);
        pass->setAmbient(colour);
        pass->setSpecular(colour);
        pass->setSelfIllumination(colour);
        //pass->setEmissive(ColourValue(0,0,0,colour.a));
        pass->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
        pass->setDepthWriteEnabled(false);
    }
    circle->begin(matptr->getName(), Ogre::RenderOperation::OT_TRIANGLE_LIST);

    unsigned point_index = 0;
    for(float theta = 0; theta <= 2 * Ogre::Math::PI; theta += Ogre::Math::PI / (radius * accuracy)) {
        circle->position(radius * cos(theta),
                         height,
                         radius * sin(theta));
        circle->position(radius * cos(theta - Ogre::Math::PI / (radius * accuracy)),
                         height,
                         radius * sin(theta - Ogre::Math::PI / (radius * accuracy)));
        circle->position((radius - thickness) * cos(theta - Ogre::Math::PI / (radius * accuracy)),
                         height,
                         (radius - thickness) * sin(theta - Ogre::Math::PI / (radius * accuracy)));
        circle->position((radius - thickness) * cos(theta),
                         height,
                         (radius - thickness) * sin(theta));
        // Join the 4 vertices created above to form a quad.
        circle->quad(point_index, point_index + 1, point_index + 2, point_index + 3);
        point_index += 4;
    }

    circle->end();

    m_ringNode = m_node->createChildSceneNode();
    m_ringNode->attachObject(circle);
}
Example #22
0
//-------------------------------------------------------------------------------------
void TutorialApplication::createScene(void)
{
    
    // Set the scene's ambient light
    mSceneMgr->setAmbientLight(Ogre::ColourValue(0.5f, 0.5f, 0.5f));
 
    // Create an Entity
    Ogre::Entity* ogreHead = mSceneMgr->createEntity("Head", "ogrehead.mesh");
 
    // Create a SceneNode and attach the Entity to it
    Ogre::SceneNode* headNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("HeadNode");
    headNode->attachObject(ogreHead);
	headNode->setPosition(0, 25, 0);
	headNode->roll(Ogre::Radian(0.5));

	Ogre::ManualObject* myManualObject =  mSceneMgr->createManualObject("manual1"); 
	Ogre::ManualObject* myManualObject2 =  mSceneMgr->createManualObject("manual2"); 
	Ogre::SceneNode* myManualObjectNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("manual1_node"); 
	Ogre::SceneNode* myManualObjectNode2 = mSceneMgr->getRootSceneNode()->createChildSceneNode("manual2_node"); 
	 
	// NOTE: The second parameter to the create method is the resource group the material will be added to.
	// If the group you name does not exist (in your resources.cfg file) the library will assert() and your program will crash
	Ogre::MaterialPtr myManualObjectMaterial = Ogre::MaterialManager::getSingleton().create("blueMaterial","General"); 
	myManualObjectMaterial->setReceiveShadows(false); 
	myManualObjectMaterial->getTechnique(0)->setLightingEnabled(true); 
	myManualObjectMaterial->getTechnique(0)->getPass(0)->setDiffuse(0,0,1,0); 
	myManualObjectMaterial->getTechnique(0)->getPass(0)->setAmbient(0,0,1); 
	myManualObjectMaterial->getTechnique(0)->getPass(0)->setSelfIllumination(0,0,1); 

	myManualObjectMaterial = Ogre::MaterialManager::getSingleton().create("greenMaterial","General"); 
	myManualObjectMaterial->setReceiveShadows(false); 
	myManualObjectMaterial->getTechnique(0)->setLightingEnabled(true); 
	myManualObjectMaterial->getTechnique(0)->getPass(0)->setDiffuse(0,1,0,0); 
	myManualObjectMaterial->getTechnique(0)->getPass(0)->setAmbient(0,1,0); 
	myManualObjectMaterial->getTechnique(0)->getPass(0)->setSelfIllumination(0,1,0); 

	myManualObjectMaterial = Ogre::MaterialManager::getSingleton().create("redMaterial","General"); 
	myManualObjectMaterial->setReceiveShadows(false); 
	myManualObjectMaterial->getTechnique(0)->setLightingEnabled(true); 
	myManualObjectMaterial->getTechnique(0)->getPass(0)->setDiffuse(1,0,0,0); 
	myManualObjectMaterial->getTechnique(0)->getPass(0)->setAmbient(1,0,0); 
	myManualObjectMaterial->getTechnique(0)->getPass(0)->setSelfIllumination(1,0,0); 

	myManualObject->begin("blueMaterial", Ogre::RenderOperation::OT_LINE_LIST); 
	myManualObject->position(0, 0, 0); 
	myManualObject->position(50, 0, 0); 
	myManualObject->end(); 
	myManualObject->begin("greenMaterial", Ogre::RenderOperation::OT_LINE_LIST); 
	myManualObject->position(0, 0, 0); 
	myManualObject->position(0, 70, 0); 
	myManualObject->end(); 
	myManualObject->begin("redMaterial", Ogre::RenderOperation::OT_LINE_LIST); 
	myManualObject->position(0, 0, 0); 
	myManualObject->position(0, 0, 50); 
	myManualObject->end(); 
	 
	myManualObjectNode->attachObject(myManualObject);

	myManualObject2->begin("blueMaterial", Ogre::RenderOperation::OT_LINE_LIST); 
	myManualObject2->position(0, 0, 0); 
	myManualObject2->position(50, 0, 0); 
	myManualObject2->end(); 
	myManualObject2->begin("greenMaterial", Ogre::RenderOperation::OT_LINE_LIST); 
	myManualObject2->position(0, 0, 0); 
	myManualObject2->position(0, 70, 0); 
	myManualObject2->end(); 
	myManualObject2->begin("redMaterial", Ogre::RenderOperation::OT_LINE_LIST); 
	myManualObject2->position(0, 0, 0); 
	myManualObject2->position(0, 0, 50); 
	myManualObject2->end(); 
	 
	myManualObjectNode2->attachObject(myManualObject2);
	myManualObjectNode2->roll(Ogre::Radian(0.5));


    // Create a Light and set its position
    Ogre::Light* light = mSceneMgr->createLight("MainLight");
    light->setPosition(20.0f, 80.0f, 50.0f);
}
Example #23
0
void gkMaterialLoader::loadSubMeshMaterial(gkSubMesh* mesh, const gkString& group)
{
	using namespace Ogre;

	gkMaterialProperties& gma = mesh->getMaterial();
	if (gma.m_name.empty())
		gma.m_name = "<gkBuiltin/DefaultMaterial>";

	Ogre::MaterialPtr oma = Ogre::MaterialManager::getSingleton().getByName(gma.m_name.c_str(), group);
	if (!oma.isNull())
		return;

	oma = Ogre::MaterialManager::getSingleton().create(gma.m_name, group);

	if (gma.m_mode & gkMaterialProperties::MA_INVISIBLE)
	{
		// disable writing to this material
		oma->setReceiveShadows(false);
		oma->setColourWriteEnabled(false);
		oma->setDepthWriteEnabled(false);
		oma->setDepthCheckEnabled(false);
		oma->setLightingEnabled(false);
		return;
	}

	if (gma.m_mode & gkMaterialProperties::MA_TWOSIDE)
	{
		oma->setCullingMode(Ogre::CULL_NONE);
		oma->setManualCullingMode(Ogre::MANUAL_CULL_NONE);
	}

	// apply lighting params

	bool enableLights = (gma.m_mode & gkMaterialProperties::MA_LIGHTINGENABLED) != 0;
	oma->setReceiveShadows((gma.m_mode & gkMaterialProperties::MA_RECEIVESHADOWS) != 0);

	oma->setLightingEnabled(enableLights);
	if (enableLights)
	{
		gkColor emissive, ambient, specular, diffuse;

		emissive    = gma.m_diffuse * gma.m_emissive;
		ambient     = gma.m_diffuse * gma.m_ambient;
		specular    = gma.m_specular * gma.m_spec;
		diffuse     = gma.m_diffuse * (gma.m_emissive + gma.m_refraction);

		emissive.a = ambient.a = specular.a = 1.f;

		oma->setSelfIllumination(emissive);
		oma->setAmbient(ambient);
		oma->setSpecular(specular);
		oma->setDiffuse(diffuse);
		oma->setShininess(gma.m_hardness);
	}
	
	Ogre::Pass* pass = oma->getTechnique(0)->getPass(0);

	bool matBlending = gkEngine::getSingleton().getUserDefs().matblending;

	if (matBlending && (gma.m_mode & gkMaterialProperties::MA_HASRAMPBLEND))
	{
		switch (gma.m_rblend)
		{
		case GK_BT_MULTIPLY:			
			pass->setSceneBlending(SBT_MODULATE);			
			break;
		case GK_BT_SUBTRACT:			
			pass->setSceneBlending(SBF_ONE_MINUS_SOURCE_COLOUR, SBF_ONE);
			break;
		case GK_BT_DARKEN:
			pass->setSceneBlendingOperation(SBO_MIN);
			pass->setSceneBlending(SBF_ONE, SBF_ONE);
			break;
		case GK_BT_LIGHTEN:
			pass->setSceneBlendingOperation(SBO_MAX);
			pass->setSceneBlending(SBF_ONE, SBF_ONE);
			break;
		case GK_BT_SCREEN:			
			pass->setSceneBlending(SBF_ONE_MINUS_DEST_COLOUR, SBF_ONE);
			break;
		case GK_BT_ADDITIVE:
			pass->setSceneBlending(SBT_ADD);
			break;
		case GK_BT_MIXTURE:
		default:
			pass->setSceneBlending(SBF_ONE, SBF_ZERO);
			break;
		}
	}

	bool hasNormap = false;
	bool rtss = gkEngine::getSingleton().getUserDefs().rtss;

	for (int i = 0; i < gma.m_totaltex; ++i)
	{		
		gkTextureProperties& gte = gma.m_textures[i];

#ifdef OGREKIT_USE_RTSHADER_SYSTEM
		if (gte.m_mode & gkTextureProperties::TM_NORMAL)
		{
			hasNormap = true;
			continue;
		}
#endif
		Ogre::TextureUnitState* otus = pass->createTextureUnitState(gte.m_name, gte.m_layer);

		LayerBlendOperationEx op = LBX_MODULATE;

		switch (gte.m_blend)
		{
		case GK_BT_ADDITIVE:
			op = LBX_ADD;
			break;

		case GK_BT_SUBTRACT:			
			op = LBX_SUBTRACT;
			break;

		case GK_BT_DARKEN:	
		case GK_BT_LIGHTEN:	
		case GK_BT_SCREEN:
		case GK_BT_COLOR:
			//break; TODO: support more mode

		case GK_BT_MULTIPLY:
		case GK_BT_MIXTURE:
		default:
			op = LBX_MODULATE;
			break;
		}

		if (i == 0)
			otus->setColourOperationEx(op, LBS_DIFFUSE, LBS_TEXTURE);		
		else
			otus->setColourOperationEx(op);

		otus->setTextureScale(gte.m_scale[0],gte.m_scale[1]);
	}



	if (gma.m_mode & gkMaterialProperties::MA_ALPHABLEND)
	{
		pass->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
		pass->setDepthWriteEnabled(false);
	}

	if (gma.m_mode & gkMaterialProperties::MA_ALPHACLIP)
	{
		pass->setAlphaRejectSettings(Ogre::CMPF_GREATER_EQUAL, 254);
	}

#ifdef OGREKIT_USE_RTSHADER_SYSTEM
	
	if (rtss)
	{
		//pass->setSpecular(ColourValue::Black);
		//pass->setShininess(0.0);

		RTShader::RenderState* rs = 0;
		RTShader::ShaderGenerator* sg = Ogre::RTShader::ShaderGenerator::getSingletonPtr();
		bool ok = sg->createShaderBasedTechnique(gma.m_name, group, 
			Ogre::MaterialManager::DEFAULT_SCHEME_NAME, Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME);

		if (ok && hasNormap)
		{
			rs = sg->getRenderState(RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME, gma.m_name, 0);
			rs->reset();

			for (int i = 0; i < gma.m_totaltex; ++i)
			{
				gkTextureProperties& gte = gma.m_textures[i];

				if (gte.m_mode & gkTextureProperties::TM_NORMAL)
				{
					GK_ASSERT(rs);

					RTShader::SubRenderState* srs= sg->createSubRenderState(RTShader::NormalMapLighting::Type);
				
					RTShader::NormalMapLighting* nsrs = static_cast<RTShader::NormalMapLighting*>(srs);
					if (gte.m_texmode & gkTextureProperties::TX_OBJ_SPACE)
						nsrs->setNormalMapSpace(RTShader::NormalMapLighting::NMS_OBJECT);
					else
						nsrs->setNormalMapSpace(RTShader::NormalMapLighting::NMS_TANGENT);
					nsrs->setNormalMapTextureName(gte.m_name);
					nsrs->setTexCoordIndex(gte.m_layer);

					rs->addTemplateSubRenderState(srs);
				}
			}

			sg->invalidateMaterial(RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME, gma.m_name);
		}
	}
#endif
}
Example #24
0
void EC_OgreSky::CreateSky(bool show)
{
    if (renderer_.expired())
        return;
    RendererPtr renderer = renderer_.lock();  
    DisableSky();
    
    Ogre::SceneManager* scene_mgr = renderer->GetSceneManager();
    
    /*RexTypes::Vector3 v = genericSkyParameters.angleAxis;
    Ogre::Quaternion orientation(Ogre::Degree(genericSkyParameters.angle), Ogre::Vector3(v.x, v.y, v.z));*/
 
    ///\todo Get the sky type and other parameters from the config file.
    switch(type_)
    {
    case SKYTYPE_BOX:
    {
        Ogre::MaterialPtr skyMaterial = Ogre::MaterialManager::getSingleton().getByName(skyBoxParameters.material);
        skyMaterial->setReceiveShadows(false);
        try
        {
            RexTypes::Vector3 v = skyBoxParameters.angleAxis;
            Ogre::Quaternion orientation(Ogre::Degree(skyBoxParameters.angle), Ogre::Vector3(v.x, v.y, v.z));

            scene_mgr->setSkyBox(show, skyBoxParameters.material, skyBoxParameters.distance, skyBoxParameters.drawFirst, orientation);
        }
        catch (Ogre::Exception& e)
        {
            OgreRenderingModule::LogError("Could not set SkyBox: " + std::string(e.what()));
            return;
        }
        
        skyEnabled_ = true;
        break;
    }
    case SKYTYPE_DOME:
        try
        {
            RexTypes::Vector3 v = skyDomeParameters.angleAxis;
            Ogre::Quaternion orientation(Ogre::Degree(skyDomeParameters.angle), Ogre::Vector3(v.x, v.y, v.z));

            scene_mgr->setSkyDome(show, skyDomeParameters.material, skyDomeParameters.curvature, skyDomeParameters.tiling,
                skyDomeParameters.distance, skyDomeParameters.drawFirst, orientation, skyDomeParameters.xSegments,
                skyDomeParameters.ySegments, skyDomeParameters.ySegmentsKeep);
        }
        catch (Ogre::Exception& e)
        {
            OgreRenderingModule::LogError("Could not set SkyDome: " + std::string(e.what()));
            return;
        }

        skyEnabled_ = true;
        break;
    case SKYTYPE_PLANE:
        try
        {
            ///\todo
            Ogre::Plane plane;
            plane.d = skyPlaneParameters.distance;
            plane.normal = Ogre::Vector3::NEGATIVE_UNIT_Z;
            scene_mgr->setSkyPlane(true, plane, skyPlaneParameters.material, skyPlaneParameters.scale, skyPlaneParameters.tiling, true, 
                                    skyPlaneParameters.bow, skyPlaneParameters.xSegments, skyPlaneParameters.ySegments);
        }
        catch (Ogre::Exception& e)
        {
            OgreRenderingModule::LogError("Could not set SkyPlane: " + std::string(e.what()));
            return;
        }
        
        skyEnabled_ = true;
        break;
    case SKYTYPE_NONE:
    default:
        skyEnabled_ = false;
        break;
    }
}
void AerialMapDisplay::assembleScene() {
  if (!dirty_) {
    return; //  nothing to update
  }
  dirty_ = false;
  
  if (!loader_) {
    return; //  no tiles loaded, don't do anything
  }
  
  //  get rid of old geometry, we will re-build this
  clearGeometry();
  
  //  iterate over all tiles and create an object for each of them
  const double resolution = loader_->resolution();
  const std::vector<TileLoader::MapTile> &tiles = loader_->tiles();
  for (const TileLoader::MapTile &tile : tiles) {
    const int w = tile.image().width();
    const int h = tile.image().height();
    //  we here assume that the tiles are uniformly sized...
    const double tileW = w * resolution;
    const double tileH = h * resolution;
    const double origin_x = -loader_->originX() * tileW;
    const double origin_y = -(1 - loader_->originY()) * tileH;

    //  determine location of this tile
    const double x = (tile.x() - loader_->tileX()) * tileW + origin_x;
    const double y = -(tile.y() - loader_->tileY()) * tileH + origin_y;
    //  don't re-use any ids
    const std::string name_suffix =
        std::to_string(tile.x()) + "_" + std::to_string(tile.y()) + "_" +
        std::to_string(map_id_) + "_" + std::to_string(scene_id_);

    Ogre::TexturePtr tex;
    if (tile.hasImage()) {
      //  one material per texture
      std::string matName = "material_" + name_suffix;
      Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().create(
          matName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
      material->setReceiveShadows(false);
      material->getTechnique(0)->setLightingEnabled(false);
      material->setDepthBias(-16.0f,
                             0.0f); /// @todo: what the f**k does this do?
      material->setCullingMode(Ogre::CULL_NONE);
      material->setDepthWriteEnabled(false);

      //  create textureing unit
      Ogre::Pass *pass = material->getTechnique(0)->getPass(0);
      Ogre::TextureUnitState *tex_unit = NULL;
      if (pass->getNumTextureUnitStates() > 0) {
        tex_unit = pass->getTextureUnitState(0);
      } else {
        tex_unit = pass->createTextureUnitState();
      }

      //  only add if we have a texture for it
      tex = textureFromImage(tile.image(), "texture_" + name_suffix);

      ROS_INFO("Rendering with texture: %s", tex->getName().c_str());
      tex_unit->setTextureName(tex->getName());
      tex_unit->setTextureFiltering(Ogre::TFO_BILINEAR);

      //  create an object
      const std::string obj_name = "object_" + name_suffix;
      Ogre::ManualObject *obj = scene_manager_->createManualObject(obj_name);
      scene_node_->attachObject(obj);

      //  configure depth & alpha properties
      if (alpha_ >= 0.9998) {
        material->setDepthWriteEnabled(!draw_under_);
        material->setSceneBlending(Ogre::SBT_REPLACE);
      } else {
        material->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
        material->setDepthWriteEnabled(false);
      }

      if (draw_under_) {
        obj->setRenderQueueGroup(Ogre::RENDER_QUEUE_4);
      } else {
        obj->setRenderQueueGroup(Ogre::RENDER_QUEUE_MAIN);
      }

      tex_unit->setAlphaOperation(Ogre::LBX_SOURCE1, Ogre::LBS_MANUAL,
                                  Ogre::LBS_CURRENT, alpha_);

      //  create a quad for this tile
      obj->begin(material->getName(), Ogre::RenderOperation::OT_TRIANGLE_LIST);

      //  bottom left
      obj->position(x, y, 0.0f);
      obj->textureCoord(0.0f, 0.0f);
      obj->normal(0.0f, 0.0f, 1.0f);

      // top right
      obj->position(x + tileW, y + tileH, 0.0f);
      obj->textureCoord(1.0f, 1.0f);
      obj->normal(0.0f, 0.0f, 1.0f);

      // top left
      obj->position(x, y + tileH, 0.0f);
      obj->textureCoord(0.0f, 1.0f);
      obj->normal(0.0f, 0.0f, 1.0f);

      //  bottom left
      obj->position(x, y, 0.0f);
      obj->textureCoord(0.0f, 0.0f);
      obj->normal(0.0f, 0.0f, 1.0f);

      // bottom right
      obj->position(x + tileW, y, 0.0f);
      obj->textureCoord(1.0f, 0.0f);
      obj->normal(0.0f, 0.0f, 1.0f);

      // top right
      obj->position(x + tileW, y + tileH, 0.0f);
      obj->textureCoord(1.0f, 1.0f);
      obj->normal(0.0f, 0.0f, 1.0f);

      obj->end();

      if (draw_under_property_->getValue().toBool()) {
        //  render under everything else
        obj->setRenderQueueGroup(Ogre::RENDER_QUEUE_4);
      }

      MapObject object;
      object.object = obj;
      object.texture = tex;
      object.material = material;
      objects_.push_back(object);
    }
  }
  scene_id_++;
}
Example #26
0
void OgreWidget::initializeOgre()
{
    mOgreRoot = new Ogre::Root;

    Ogre::RenderSystem *renderSystem = mOgreRoot->getRenderSystemByName("OpenGL Rendering Subsystem");
    mOgreRoot->setRenderSystem(renderSystem);
    mOgreRoot->initialise(false);

    Ogre::NameValuePairList viewConfig;
    QWidget *parentWidget = dynamic_cast <QWidget *>(parent());

    Ogre::String windowHandle = Ogre::StringConverter::toString ((unsigned long)QX11Info::display()) +
            ":" + Ogre::StringConverter::toString ((unsigned int)QX11Info::appScreen()) +
            ":" + Ogre::StringConverter::toString ((unsigned long)parentWidget->winId());


    qDebug() << __PRETTY_FUNCTION__ << "using window handle" << QString::fromStdString(windowHandle);
    viewConfig["parentWindowHandle"] = windowHandle;
    viewConfig["vsync"] = "true"; // this actually works on linux/nvidia-blob/thinkpad!

    mOgreRenderWindow = mOgreRoot->createRenderWindow("OgreRenderWindow", width(), height(), false, &viewConfig);

    mOgreRenderWindow->setActive(true);

    Ogre::SceneManagerEnumerator::MetaDataIterator iter = Ogre::SceneManagerEnumerator::getSingleton().getMetaDataIterator();
    while( iter.hasMoreElements() )
    {
        Ogre::String st = iter.getNext()->typeName;
        qDebug() << "Scene manager type available:" << QString::fromStdString(st);
    }

    mSceneManager = mOgreRoot->createSceneManager(Ogre::ST_GENERIC);
    //    ogreSceneManager = ogreRoot->createSceneManager("TerrainSceneManager"/*Ogre::ST_EXTERIOR_CLOSE*/);
    //    ogreSceneManager->showBoundingBoxes(true);

    // By default, entities cannot be found using a RSQ. This is to make sure that the
    // Lidar's don't catch the rotors, cameras etc. It also means we'll have to set the
    // flags to nonzero for any mesh that should be scannable.
    Ogre::MovableObject::setDefaultQueryFlags(0x00000000);

    mCamera = mSceneManager->createCamera("camera");
    mCamera->setNearClipDistance(.1);
    //mCamera->setPolygonMode(Ogre::PM_WIREFRAME);     /* wireframe */
    mCamera->setPolygonMode(Ogre::PM_SOLID);         /* solid */

    mCameraNode = mSceneManager->getRootSceneNode()->createChildSceneNode("CameraNode", Ogre::Vector3(0, 12, 15));
    mCameraNode->attachObject(mCamera);
    mCamera->lookAt(0,8,0);

    mOgreViewport = mOgreRenderWindow->addViewport(mCamera);
    mOgreViewport->setBackgroundColour(Ogre::ColourValue(0.7, 0.7, 0.7));
    mCamera->setAspectRatio(Ogre::Real(width()) / Ogre::Real(height()));

    if(mOgreRoot->getRenderSystem()->getCapabilities()->hasCapability(Ogre::RSC_INFINITE_FAR_PLANE))
    {
        mCamera->setFarClipDistance(0);   // enable infinite far clip distance if we can
    }

    // Initialize shader generator.
    // Must be before resource loading in order to allow parsing extended material attributes.
    if(!initializeRTShaderSystem(mSceneManager))
    {
        OGRE_EXCEPT(Ogre::Exception::ERR_FILE_NOT_FOUND,
                    "Shader Generator Initialization failed - Core shader libs path not found",
                    "SdkSample::_setup");
    }

    setupTerrain();

    // initialize trajectory line
    mTrajectoryLine = mSceneManager->createManualObject(QString("trajectoryLine_manualobject").toStdString());
    Ogre::SceneNode* mTrajectoryLineNode = mSceneManager->getRootSceneNode()->createChildSceneNode("trajectoryLine_node");

    Ogre::MaterialPtr trajectoryLineMaterial = Ogre::MaterialManager::getSingleton().create("trajectoryLineMaterial", "General");
    trajectoryLineMaterial->setReceiveShadows(false);
    trajectoryLineMaterial->getTechnique(0)->setLightingEnabled(true);
    trajectoryLineMaterial->getTechnique(0)->getPass(0)->setDiffuse(0,0,1,0);
    trajectoryLineMaterial->getTechnique(0)->getPass(0)->setAmbient(0,0,1);
    trajectoryLineMaterial->getTechnique(0)->getPass(0)->setSelfIllumination(0,0,1);
    //    trajectoryLineMaterial->dispose();  // dispose pointer, not the material
    mTrajectoryLineNode->attachObject(mTrajectoryLine);

    emit setupFinished();

    qDebug() << __PRETTY_FUNCTION__ << "done.";
}