"Zoom" in Orthographic View

Problems building or running the engine, queries about how to use features etc.
Post Reply
User avatar
derdragon
Halfling
Posts: 57
Joined: Mon Oct 23, 2006 2:08 am

"Zoom" in Orthographic View

Post by derdragon »

Hi, another hopefully quick question...

If I'm using the Ogre::PT_ORTHOGRAPHIC projection for my camera... is there a way for me to set the "zoom" or range of what I can see from the camera?
User avatar
Kencho
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4011
Joined: Fri Sep 19, 2003 6:28 pm
Location: Burgos, Spain
x 2
Contact:

Post by Kencho »

I think Camera::setFOVy() will work the same way as with perspective cameras.
Image
User avatar
cottonbelly
Gnoblar
Posts: 12
Joined: Fri Mar 23, 2007 11:48 am

Post by cottonbelly »

Hi,

I came across the same problem as derdragon with the orthographic camera, and using the Camera::setFOVy() method doesn't change much to the display.

Does anyone know a way to set equivalent zoom ratios like 1x, 2x... with this kind of camera?

Thanks in advance!
User avatar
AekMuldoon
Halfling
Posts: 74
Joined: Mon Sep 25, 2006 3:44 am
Location: Perth, Australia
Contact:

Post by AekMuldoon »

In orthogonal projection lines or geometry that is placed far away from the camera is still the same size as if it was right next to the camera. Try scaling your whole world down.
bleubleu
Kobold
Posts: 27
Joined: Mon Dec 11, 2006 4:38 am

Post by bleubleu »

Hi!

I know its an old post. But here it goes! The code is in C# with Mogre, but you get the idea. This will work fine for something like an editor/modeler where you want to have orthographic view and be able to zoom in/out easily.

Code: Select all

public Matrix4 BuildScaledOrthoMatrix(float left, float right, float bottom, float top, float near, float far)
{
  float invw = 1 / (right - left);
  float invh = 1 / (top - bottom);
  float invd = 1 / (far - near);

  Matrix4 proj = Matrix4.ZERO;
  proj[0, 0] = 2 * invw;
  proj[0, 3] = -(right + left) * invw;
  proj[1, 1] = 2 * invh;
  proj[1, 3] = -(top + bottom) * invh;
  proj[2, 2] = -2 * invd;
  proj[2, 3] = -(far + near) * invd;
  proj[3, 3] = 1;

  return proj;
}
Then you can use it like this. The ctrl.Width & scale are the width and height of your window/viewport in pixels. This is needed to keep a correct aspect ratio.

Code: Select all

float scale = 0.5f; // Your scale here.

Matrix4 p = this.BuildScaledOrthoMatrix(ctrl.Width  / scale / -2.0f,
                                        ctrl.Width  / scale /  2.0f,
                                        ctrl.Height / scale / -2.0f,
                                        ctrl.Height / scale /  2.0f, 0, 1000);

m_camera.SetCustomProjectionMatrix(true, p);
**EDIT : You can also pan simply by moving the position of the plane :

Code: Select all

Matrix4 p = this.BuildScaledOrthoMatrix(ctrl.Width  / scale / -2.0f + tx,
                                        ctrl.Width  / scale /  2.0f + tx,
                                        ctrl.Height / scale / -2.0f + ty,
                                        ctrl.Height / scale /  2.0f + ty, 0, 1000);
Have fun!

Mat
User avatar
AekMuldoon
Halfling
Posts: 74
Joined: Mon Sep 25, 2006 3:44 am
Location: Perth, Australia
Contact:

Post by AekMuldoon »

thanks this really helps me in my current project ! :)
User avatar
FrameFever
Platinum Sponsor
Platinum Sponsor
Posts: 414
Joined: Fri Apr 27, 2007 10:05 am

Post by FrameFever »

@BleuBleu

can you please explain me the BuildScaledOrthoMatrix function?
How do you build the Matrix, did you use a tutorial for this?
it looks cryptic for me.
User avatar
walaber
OGRE Expert User
OGRE Expert User
Posts: 829
Joined: Sat Oct 02, 2004 2:20 pm
Location: California, USA
Contact:

Post by walaber »

just wanted to add a thank you to this thread, this was exactly what I needed for a project I'm working on!
Go Go Gadget OGRE!!
Image
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19265
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66
Contact:

Post by sinbad »

Just for info, if you use CVS HEAD it's already easier:

Code: Select all

		/** Sets the orthographic window settings, for use with orthographic rendering only. 
		@note Calling this method will recalculate the aspect ratio, use 
			setOrthoWindowHeight or setOrthoWindowWidth alone if you wish to 
			preserve the aspect ratio but just fit one or other dimension to a 
			particular size.
		@param w, h The dimensions of the view window in world units
		*/
		virtual void setOrthoWindow(Real w, Real h);
User avatar
AekMuldoon
Halfling
Posts: 74
Joined: Mon Sep 25, 2006 3:44 am
Location: Perth, Australia
Contact:

Post by AekMuldoon »

We are not "cutting edge" (tm) enough to use the HEAD :)
Good to know though, thanks for improving this area.
User avatar
FrameFever
Platinum Sponsor
Platinum Sponsor
Posts: 414
Joined: Fri Apr 27, 2007 10:05 am

Post by FrameFever »

where does I find this funtion, can I scale with this function the frustum?
User avatar
FrameFever
Platinum Sponsor
Platinum Sponsor
Posts: 414
Joined: Fri Apr 27, 2007 10:05 am

Post by FrameFever »

okay, I got it, build the source, and it works now fine.

but, thats a strange feeling, I implemented orthoview, and now I delete my code and use the official code.
claustre
Goblin
Posts: 278
Joined: Thu Mar 23, 2006 10:35 am
Location: Toulouse, France
Contact:

Post by claustre »

I think there is a simple relation between the fov angle and the width of the world portion seen through your camera :

Code: Select all

fov = 2*atan(w/2*near*aspect)
This way you can simulate zoom by increasing/decreasing fov...
petersvp
Gnoblar
Posts: 22
Joined: Fri Mar 08, 2013 12:50 pm
Location: Bulgaria

Re: "Zoom" in Orthographic View

Post by petersvp »

Too old topic, but I will add to it. I ended my zoom this way:

Code: Select all

    Ogre::Matrix4 mt = camera->getViewMatrix();
    float z = 2;
    mt[0][0] *= z;
    mt[1][1] *= z;
    camera->setCustomViewMatrix(true,mt);
In my case it didn't worked with the projection matrixx, but in most cases it should. The z var is the zoom factor.
Post Reply