Page 1 of 1

Rotate gui images

Posted: Mon Nov 06, 2006 8:29 pm
by belfegor
I would like to create compas but i cant find any suitable function
to rotate images. I could solve this with rotating planes(but that would be complicated) if it isnt
possible with gui images as they are?

Posted: Thu Nov 09, 2006 6:02 pm
by belfegor
Yes/No would be good answer as well. :cry:

Posted: Thu Nov 09, 2006 7:11 pm
by vitek
No. There is no method provided to rotate a gui image. You should be able to create a gui element that displays a rotating quad. You would need to setup a matrix so you can control the orientation, but it shouldn't be difficult.

Posted: Thu Nov 09, 2006 8:25 pm
by vitek
Ah, I'm bored...

Code: Select all

class CGUICompass : public gui::IGUIElement
{
public:
   CGUICompass(core::rect<s32> rect, gui::IGUIEnvironment* env, gui::IGUIElement* parent)
      : gui::IGUIElement(gui::EGUIET_ELEMENT, env, parent, -1, rect)
   {
      Mesh.Vertices.set_used(4);
      Mesh.Indices .set_used(6);

      video::SColor white(255, 255, 255, 255);

      Mesh.Vertices[0] = video::S3DVertex(-1.f, -1.f, 0.f, 0.f, 0.f, 1.f, white, 0.f, 1.f);
      Mesh.Vertices[1] = video::S3DVertex(-1.f,  1.f, 0.f, 0.f, 0.f, 1.f, white, 0.f, 0.f);
      Mesh.Vertices[2] = video::S3DVertex( 1.f,  1.f, 0.f, 0.f, 0.f, 1.f, white, 1.f, 0.f);
      Mesh.Vertices[3] = video::S3DVertex( 1.f, -1.f, 0.f, 0.f, 0.f, 1.f, white, 1.f, 1.f);

      Mesh.Indices[0] = 0;
      Mesh.Indices[1] = 1;
      Mesh.Indices[2] = 2;
      Mesh.Indices[3] = 2;
      Mesh.Indices[4] = 3;
      Mesh.Indices[5] = 0;

      Mesh.getMaterial().Lighting = false;
      //Mesh.getMaterial().BackfaceCulling = false;
      //Mesh.getMaterial().Wireframe = true;
      Mesh.getMaterial().MaterialType = video::EMT_TRANSPARENT_ADD_COLOR;
   }

   //
   void setCompassTexture(video::ITexture* texture)
   {
      Mesh.getMaterial().Texture1 = texture;
   }

   void setCompassHeading(f32 deg)
   {
      Matrix.makeIdentity();
      Matrix.setRotationDegrees(core::vector3df(0, 0, deg));
   }

   //! render the compass
   virtual void draw()
   {
      video::IVideoDriver* driver = Environment->getVideoDriver();
      if (! (driver && IsVisible))
         return;

      core::rect<s32> oldViewPort = driver->getViewPort();
      driver->setViewPort(getAbsolutePosition());

      // clear the projection matrix
      core::matrix4 oldProjMat = driver->getTransform(video::ETS_PROJECTION);
      driver->setTransform(video::ETS_PROJECTION, core::matrix4());

      // clear the view matrix
      core::matrix4 oldViewMat = driver->getTransform(video::ETS_VIEW);
      driver->setTransform(video::ETS_VIEW, core::matrix4());

      driver->setTransform(video::ETS_WORLD, Matrix);

      driver->setMaterial(Mesh.Material);

      driver->drawMeshBuffer(&Mesh);

      // restore view matrix
      driver->setTransform(video::ETS_VIEW, oldViewMat);

      // restore projection matrix
      driver->setTransform(video::ETS_PROJECTION, oldProjMat);

      // restore the view area
      driver->setViewPort(oldViewPort);
   }

private:
   scene::SMeshBuffer Mesh;
   core::matrix4 Matrix;
};

Posted: Thu Nov 09, 2006 9:42 pm
by belfegor
Big thanks and hail to almighty vitek

Posted: Fri Nov 10, 2006 3:52 am
by vitek
Of course if you want to do it right you'd make a textured circle instead of a quad. The code privided should be enough to get you started.

Posted: Sun Feb 04, 2007 3:28 am
by lordcool
awesome!! thx!! vitek. :P

Posted: Tue Feb 06, 2007 12:20 pm
by drac_gd
lordcool
I also needed a compass. I posted a full working example based on Viteks code
http://irrlicht.sourceforge.net/phpBB2/ ... 131#105131

Posted: Fri May 16, 2008 12:27 am
by Auradrummer
Vitek,

This information about compass must be placed as an tutorial. Is too valuable information.

I noticed that this was made log time ago, and seems that doesn't work very well with newer Irrlicht 1.4. The getMaterial seems to have changed from:

Code: Select all

void setCompassTexture(video::ITexture* texture)
   {
      Mesh.getMaterial().Texture1 = texture;
   } 
to this new form:

Code: Select all

void setCompassTexture(video::ITexture* texture)
   {
      Mesh.getMaterial().setTexture(0,texture);
   } 
If I'm wrong, please tell. And thanks!

Posted: Fri May 16, 2008 5:36 am
by vitek
That is correct. The SMaterial interface has changed quite a bit.

Travis