Support for 2D transform
Support for 2D transform
With current version of Irrlicht, it's quite difficult to rotate a 2D sprite. Although some developers have provided codes that can do this, it's still not very flexible. I think it would be better if irrlicht video driver supports setting a transform matrix in 2D mode. For example, IVideoDriver will have a new function `setTransform2D' and in `setRenderStates2DMode' function, use that matrix instead of identity matrix. Although it involves all kinds of drivers, for each driver it's not a big change. Is that possible and is there any problems with that solution?
Re: Support for 2D transform
It's under discussion regulalry. We need some solution for that, but couldn't agree yet on an implementation.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
-
- Competition winner
- Posts: 688
- Joined: Mon Sep 10, 2012 8:51 am
Re: Support for 2D transform
mm...
I think it'd be nice if images were drawn in the same way as mesh textures in the world, and then you could call something like draw2DImage( texture, matrix=identity ), and thus by default, it draws according to the identity matrix, but otherwise, it changes the drawing orientation. Seems to me it could take advantage of pre-existing parts of the engine and could draw images as it does now if the matrix is the identity matrix.
... Otherwise, we could just create a class that transforms the image for us, but that would create textures and eventually become a memory hog.
Notably, I forgot which thread we were discussing the image transformation in, otherwise I might be more informed.
I think it'd be nice if images were drawn in the same way as mesh textures in the world, and then you could call something like draw2DImage( texture, matrix=identity ), and thus by default, it draws according to the identity matrix, but otherwise, it changes the drawing orientation. Seems to me it could take advantage of pre-existing parts of the engine and could draw images as it does now if the matrix is the identity matrix.
... Otherwise, we could just create a class that transforms the image for us, but that would create textures and eventually become a memory hog.
Notably, I forgot which thread we were discussing the image transformation in, otherwise I might be more informed.
Re: Support for 2D transform
Rotating sprites isn't exactly complex, actually, but it is tricky because the amount of options it may involve, for instance, you can rotate a image changing its texture matrix. Also, currently all the 2D drawing options perform clipping in software to help saving renderstate changes, something that may not happen while rotating images, and such.
I'd go for creating a set of rectangular polygons, rotate them manually, and placing them in the proper coordinates, later you set up a proper view and projection matrix and draw the whole set of quads as a single meshbuffer
I'd go for creating a set of rectangular polygons, rotate them manually, and placing them in the proper coordinates, later you set up a proper view and projection matrix and draw the whole set of quads as a single meshbuffer
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Re: Support for 2D transform
Can someone show me some example code how to deal with rotating sprites in a 2d environment? If I just change texture coordinates, won't the rectangle be too small to display the whole sprite? So I would need enough empty transparent space around every image... How do I even manipulate tex coords when drawing a 2d picture without(?) actual vertices? Custom material shader?..
I'd like to see better 2d support, too. It seems atm Irrlicht is a pretty bad choice for it, but I've learned too much about the engine to switch now. I rather stick with it.
I'd like to see better 2d support, too. It seems atm Irrlicht is a pretty bad choice for it, but I've learned too much about the engine to switch now. I rather stick with it.
-
- Competition winner
- Posts: 688
- Joined: Mon Sep 10, 2012 8:51 am
Re: Support for 2D transform
Late reply, sorry.
Here's the simple way:
And if you only want it in a GUI element, you'd grab() it, clear the scene with sceneManager->clear(), and only draw the node in your GUI element draw() function.
Here's the simple way:
Code: Select all
// Assuming sceneManager is a pointer to ISceneManager...
ISceneNode* node = sceneManager->addCubeSceneNode();
// Assuming videoDriver is a pointer to IVideoDriver
ITexture* texture = videoDriver->getTexture( path_to_image ); // io::path path_to_image
node->setMaterialTexture(0, texture );
node->setRotation( /* radians */ vector3df( core::degToRad(45.f), 0.f, 0.f ) );
Re: Support for 2D transform
I think it wouldn't harm to have a sort of "screen space aligned quad", like a billboard but that you place in screen coordinates, not in 3D coordinates, that you can rotate, scale and translate. That would simplify enormously the task of drawing 2D rotated and scaled textures.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt