Rotate gui images
Rotate gui images
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?
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?
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;
};
lordcool
I also needed a compass. I posted a full working example based on Viteks code
http://irrlicht.sourceforge.net/phpBB2/ ... 131#105131
I also needed a compass. I posted a full working example based on Viteks code
http://irrlicht.sourceforge.net/phpBB2/ ... 131#105131
-
- Posts: 260
- Joined: Thu Apr 17, 2008 1:38 pm
- Location: Brasopolis - Brazil
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:
to this new form:
If I'm wrong, please tell. And thanks!
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;
}
Code: Select all
void setCompassTexture(video::ITexture* texture)
{
Mesh.getMaterial().setTexture(0,texture);
}
Professional Software Developer and Amateur Game Designer