Example #1
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();

}
Example #2
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);
 }
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_++;
}