Support for 2D transform

Post your questions, suggestions and experiences regarding to Image manipulation, 3d modeling and level editing for the Irrlicht engine here.

Support for 2D transform

Postby WuZhenwei » Tue Aug 26, 2014 3:04 am

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?
WuZhenwei
 
Posts: 5
Joined: Fri Apr 18, 2014 11:08 am

Re: Support for 2D transform

Postby CuteAlien » Tue Aug 26, 2014 7:29 pm

It's under discussion regulalry. We need some solution for that, but couldn't agree yet on an implementation.
IRC: #irrlicht on irc.freenode.net
Code snippets, patches&stuff: http://www.michaelzeilfelder.de/irrlicht.htm
Free racer created with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
User avatar
CuteAlien
Admin
 
Posts: 8528
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany

Re: Support for 2D transform

Postby chronologicaldot » Sun Aug 31, 2014 5:27 am

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.
User avatar
chronologicaldot
Competition winner
 
Posts: 560
Joined: Mon Sep 10, 2012 8:51 am

Re: Support for 2D transform

Postby Mel » Mon Sep 01, 2014 8:08 am

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
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
User avatar
Mel
Competition winner
 
Posts: 2271
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: Support for 2D transform

Postby Max Power » Sat Dec 20, 2014 1:01 pm

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.
Max Power
 
Posts: 98
Joined: Wed Mar 14, 2012 10:09 am

Re: Support for 2D transform

Postby chronologicaldot » Sat Jan 10, 2015 9:28 pm

Late reply, sorry.

Here's the simple way:
cpp 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 ) );
 

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.
User avatar
chronologicaldot
Competition winner
 
Posts: 560
Joined: Mon Sep 10, 2012 8:51 am

Re: Support for 2D transform

Postby Mel » Sun Jan 11, 2015 2:24 am

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
User avatar
Mel
Competition winner
 
Posts: 2271
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain


Return to Everything 2d/3d Graphics

Who is online

Users browsing this forum: No registered users and 1 guest