2D coordinates in irrlicht

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
julescoder
Posts: 34
Joined: Thu Feb 18, 2010 5:24 pm

2D coordinates in irrlicht

Post by julescoder »

Hi,
I plan to make a 2D game using the Irrlicht engine.

So for in the prototype i have used an orthographic projection (left) with the camera fixed looking down the Y-axis.

Now, the issue is the coordinate system is completely different from the coordinate system in 2D libs where the origin is at the top left screen.

So how can i have the origin at the top left in this fake 2d system in irrlicht instead of at the center?

OR do i have to make do with it and do some translation to get the origin at the top left corner ?
Metalero
Posts: 14
Joined: Tue Sep 07, 2010 4:02 pm

Post by Metalero »

The simplest way is that your camera looks at negative Z. It gives you the same system X-Y, used in 2D.

Now you have the (0,0) in the middle of the screen, so yo only need to "offset" the position of the camera to (Screen_Width/2, Screen_Height/2).

And don´t forget your orthogonal camera´s projections must have the same size of you window Screen)

Here´s a little code for a 460*480 screen

Code: Select all

irr::scene::ICameraSceneNode* mainCamera = NULL;	
mainCamera = System::smgr->addCameraSceneNode(0, irr::core::vector3df(320,-240,-1), irr::core::vector3df(320,-240,100)); 
irr::core::matrix4 orthoMatrix;
orthoMatrix.buildProjectionMatrixOrthoLH(640,480, 0.1f, 1000.f); 
mainCamera->setProjectionMatrix(orthoMatrix, true); 
This shuold works (I´ve not tested the offset staff, coz I use the origin at center... and then I correct sprite position calculation)
Post Reply