Rotate gui images

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
belfegor
Posts: 383
Joined: Mon Sep 18, 2006 7:22 pm
Location: Serbia

Rotate gui images

Post 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?
Small FPS demo made using Irrlicht&NewtonDEMO
InfoHERE
Its at very early stage but i think im crazy enough to finish it all alone.
belfegor
Posts: 383
Joined: Mon Sep 18, 2006 7:22 pm
Location: Serbia

Post by belfegor »

Yes/No would be good answer as well. :cry:
Small FPS demo made using Irrlicht&NewtonDEMO
InfoHERE
Its at very early stage but i think im crazy enough to finish it all alone.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post 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.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post 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;
};
belfegor
Posts: 383
Joined: Mon Sep 18, 2006 7:22 pm
Location: Serbia

Post by belfegor »

Big thanks and hail to almighty vitek
Small FPS demo made using Irrlicht&NewtonDEMO
InfoHERE
Its at very early stage but i think im crazy enough to finish it all alone.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post 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.
lordcool
Posts: 15
Joined: Thu Jul 13, 2006 8:33 am

Post by lordcool »

awesome!! thx!! vitek. :P
drac_gd
Posts: 132
Joined: Sun Apr 09, 2006 8:43 pm

Post 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
Auradrummer
Posts: 260
Joined: Thu Apr 17, 2008 1:38 pm
Location: Brasopolis - Brazil

Post 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!
Professional Software Developer and Amateur Game Designer ;-)
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

That is correct. The SMaterial interface has changed quite a bit.

Travis
Post Reply