[SOLVED] Draw a real square in orthographic projection

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
Post Reply
User avatar
emersonmx
Gnoblar
Posts: 6
Joined: Sat Dec 22, 2012 3:37 am
Location: Parelhas - RN, Brazil

[SOLVED] Draw a real square in orthographic projection

Post by emersonmx »

I'm having a problem with orthographic projection when I try draw a square. I create the square manualy, but the result is a rectangle that is proportional to window size! When I resize the window, the "square" size change too.
I found an example that shows do this in OpenGL using a simple calculation on the aspect ration when window size change. I try using the camera aspect ration method to change aspect ration on window resize, but I could not reproduce the same result. Can someone explain to me what to do to reproduce the same result in the OpenGL application on Ogre?

If someone can show me how to do this I would be very grateful. Thank you in advance.
Attachments
2DEx.zip
(9.43 KiB) Downloaded 28 times
Last edited by emersonmx on Sun Sep 08, 2013 4:00 am, edited 2 times in total.
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 534

Re: Draw a real square in orthographic projection

Post by Kojack »

You can turn on auto aspect ratio calculation on a camera. That will make sure that everything stays square.
Off the top of my head the function is camera->setAutoAspectRation(true);
But I don't have ogre in front of me, so the name might be slightly different.
User avatar
emersonmx
Gnoblar
Posts: 6
Joined: Sat Dec 22, 2012 3:37 am
Location: Parelhas - RN, Brazil

Re: Draw a real square in orthographic projection

Post by emersonmx »

Actually, it does not work for this case ... I've tried this ... :(
I guess I'll have to use some workaround.
User avatar
emersonmx
Gnoblar
Posts: 6
Joined: Sat Dec 22, 2012 3:37 am
Location: Parelhas - RN, Brazil

Re: Draw a real square in orthographic projection

Post by emersonmx »

I do not know if this is the correct way to do this, but it works. :mrgreen:

I use setProjectionType and setOrthoWindow together to get something like this.
together.png
together.png (4.23 KiB) Viewed 1080 times
you need to use both methods, else but will look like something like this.
separate.png
separate.png (4.21 KiB) Viewed 1080 times
A Snippet of camera setup of this pong game.

Code: Select all

camera_ = scene_manager_->createCamera("camera");
camera_->setNearClipDistance(0.1);
camera_->setProjectionType(Ogre::PT_ORTHOGRAPHIC);
camera_->setOrthoWindow(window_->getWidth(), window_->getHeight());
Ogre::SceneNode* camera_node =
    scene_manager_->getRootSceneNode()->createChildSceneNode("camera");
camera_node->attachObject(camera_);
camera_node->setPosition(window_->getWidth() / 2.f,
                         window_->getHeight() / 2.f,
                         1);
I set the camera to the center of the window (320, 240) because I like that the origin (0, 0) is at the bottom left of the window xD
Attachments
2DEx.zip
New code with modifications
(5.49 KiB) Downloaded 25 times
Image
Post Reply