Feature required for 2 games

Post your questions, suggestions and experiences regarding game design, integration of external libraries here. For irrEdit, irrXML and irrKlang, see the
ambiera forums
Post Reply
[ghost]
Posts: 14
Joined: Sat Apr 16, 2011 8:00 pm

Feature required for 2 games

Post by [ghost] »

Hi,

I saw many posts related to 2D image rotation issue with implementations of new image classes to handle rotations,but this will make things much complex when the game should be scalable, the best way to handle transformations is to have the video driver behaving as Graphics class in java ,at last it should easily support all transformation changes (translate/scale/rotate..) in the actual implementation I saw that changing the transformation matrix of video driver don't affect 2d rendering.
I think this isn't a hard task for somebody that knows very good irrlicht engine and will be a big plus for 2D game programming using Irrlicht engine.
Also I want to thank you guys for this engine, it works very well and also the code is very good organized and easy to understand and use even for somebody that don't really know 3D programming.
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Post by Lonesome Ducky »

This isn't a hard task for anyone that has a basic knowledge of 3d transformations. It's not very difficulty at all to fake 2d with 3d, and doing it that way makes it so you can just use matrix4 for scaling and rotation. In fact (don't quote me on this) I think irrlicht might even use 3d to render 2d deep down.
[ghost]
Posts: 14
Joined: Sat Apr 16, 2011 8:00 pm

Post by [ghost] »

It is logical that Irrlicht use 3D to render 2D , the engine use opengl/directx calls to render images(textures),but I don't understand why I should make my work harder faking 2D using 3D ,also I'll make this fake somebody will do it again why we can't easily add this in the irrlicht engine and everybody use it easily ? I tried using matrix4 to handle transforms but it don't work,they reset the transform matrix for 2D rendering,I'm not the only one that tried this , see the above post:

http://irrlicht.sourceforge.net/phpBB2/ ... be42edae61


// draw tank
const core::matrix4& oldMat = driver->getTransform(video::ETS_VIEW);
core::matrix4 newMat = oldMat;
newMat = newMat.setTextureRotationCenter( 1.57079633 );

driver->setTransform(video::ETS_VIEW, newMat);

driver->draw2DImage(tankImages, core::position2d<s32>(m_vPosition.X, m_vPosition.Y),
*m_pTankIcon, 0, video::SColor(255,255,255,255), true);

driver->setTransform(video::ETS_VIEW, oldMat);
ChaiRuiPeng
Posts: 363
Joined: Thu Dec 16, 2010 8:50 pm
Location: Somewhere in the clouds.. drinking pink lemonade and sunshine..

Post by ChaiRuiPeng »

[ghost] wrote:It is logical that Irrlicht use 3D to render 2D
why? im pretty sure hardware accelerated graphics which is what openGL does and is just one of the backends of irrlicht, uses SIMD, so it doesn't matter if 2d or 3d, still same speed. only difference is not using last or whatever vector component in operation.

it would be illogical to completely recreate irrlicht just to not include functionality for 3d because some people will only use 2d.
ent1ty wrote: success is a matter of concentration and desire
Butler Lampson wrote: all problems in Computer Science can be solved by another level of indirection
at a cost measure in computer resources ;)
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Post by Lonesome Ducky »

It really takes minimal effort to use one of the code snippets provided for 2d images with rotation or even create your own. Irrlicht can already be used very successfully for 2D games, I've used it for a few myself. If you don't want to use a code snippet or come up with your own, you may do best to use SDL or Allegro.
[ghost]
Posts: 14
Joined: Sat Apr 16, 2011 8:00 pm

Post by [ghost] »

[ChaiRuiPeng] : it would be illogical to completely recreate irrlicht just to not include functionality for 3d because some people will only use 2d.
I never said to recreate irrlicht!
All I want is to have video driver transformations working for 2D image rendering ,I mean this code working properly:

driver->setTransform(video::ETS_VIEW, newMat);

driver->draw2DImage(tankImages, core::position2d<s32>(m_vPosition.X, m_vPosition.Y),
*m_pTankIcon, 0, video::SColor(255,255,255,255), true);

You're right Ducky It takes minimal effort to make a fix for these transforms to work as they should, I'll fix this in my irrlicht copy, I was intended to have this issue fixed in the public irrlicht code but seems it takes longer to convince peoples that the above code should work fine, when they are thinking that the fix is not needed if they have workarounds to make transformations working. Thank you guys for your quick replay and advices.
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Post by Lonesome Ducky »

Well, irrlicht is a sourceforge project. You could always delve into the source, come up with a solution to the problem, and submit it.
Sylence
Posts: 725
Joined: Sat Mar 03, 2007 9:01 pm
Location: Germany
Contact:

Post by Sylence »

[ghost] wrote:why we can't easily add this in the irrlicht engine and everybody use it easily ?
Because Irrlicht is a 3D engine?
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Post by serengeor »

Sylence wrote:
[ghost] wrote:why we can't easily add this in the irrlicht engine and everybody use it easily ?
Because Irrlicht is a 3D engine?
I can't agree with you, on this. Irrlicht would only benefit having mostly used 2d features, as it would be a lot easier to prototype some stuff, or even use it in real apps without having to merge it with other libraries.

Or irrlicht should get rid of any 2d functionality/gui and focus only on 3d stuff.
Working on game: Marrbles (Currently stopped).
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Yes, this proposal (taking care of the transformation matrix) could be a god idea. However, we need to make sure that the current API does fit with this scheme and the current way of 2d rendering also can make use of it.
Moreover, using the view matrix seems to be a strange idea, world matrix sounds better?!
[ghost]
Posts: 14
Joined: Sat Apr 16, 2011 8:00 pm

And the fix

Post by [ghost] »

For anyone that want to easy manipulate 2D images below is a small change that should be done in the irrlicht sources and a short example of image rotation. I think it will be great to have this in the irrlicht public sources if this don't break anything else.

In setRenderStates2DMode() method from video driver source file(in my case COpenGLDriver.cpp) add glLoadMatrixf(Matrices[ETS_WORLD].pointer()).

Code: Select all

                        glMatrixMode(GL_MODELVIEW);
			glLoadIdentity();
			glTranslatef(0.375f, 0.375f, 0.0f);
			[b]glLoadMatrixf(Matrices[ETS_WORLD].pointer());[/b]
Now all transforms can be done in the game sources using world transformation matrix:

Code: Select all

matrix4 oldTransform = getVideoDriver()->getTransform(ETS_WORLD);
	
	const int imgW = dest.LowerRightCorner.X - dest.UpperLeftCorner.X;
	const int imgH = dest.LowerRightCorner.Y - dest.UpperLeftCorner.Y;
	const int centerX = dest.UpperLeftCorner.X + imgW/2;
	const int centerY = dest.UpperLeftCorner.Y + imgH/2;
	
	matrix4 newTransform = oldTransform;
	newTransform.setTranslation(vector3df(centerX,centerY,0));
	newTransform.setRotationDegrees(vector3df(0,0,90));
	
	core::rect<s32> a(-imgW/2,-imgH/2,imgW/2,imgH/2);
	getVideoDriver()->setTransform(ETS_WORLD, newTransform);

	getVideoDriver()->draw2DImage(m_texture,a,src,NULL,col,true);
	getVideoDriver()->draw2DRectangleOutline(a,SColor(255,255,0,0));
	getVideoDriver()->setTransform(ETS_WORLD,oldTransform);
[/code][/b]
Post Reply