Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

877312 Posts in 32856 Topics- by 24295 Members - Latest Member: raithza

May 19, 2013, 06:01:42 AM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)Changing the Projection Matrix mid-scene (openGL and C++)
Pages: [1]
Print
Author Topic: Changing the Projection Matrix mid-scene (openGL and C++)  (Read 1054 times)
dspencer
Level 2
**


View Profile
« on: March 10, 2009, 11:06:58 AM »

Hi,
I'm using openGL with C++ for a project. I have a video camera on a movable entity. This camera shows up on your screen as an image on a TV, located slightly to the right of the center of the screen. To draw the scene being viewed by the camera, I'm setting the Perspective matrix to a slightly right aligned glFrustum(). However, this makes figuring out the coords I need for the scene that exists around the TV image is quite difficult. Furthermore, I would liek to be able to change the location of the image without entirely redoing this code.

So, the question is - is it ok to change the Perspective matrix in openGL in the middle of a scene? I'm under the impression that this is a very bad idea. If it is bad, why? Also, how else might I do this?

Thanks for your help
« Last Edit: March 19, 2009, 09:22:54 PM by Derek » Logged
rogerlevy
Guest
« Reply #1 on: March 10, 2009, 11:21:52 AM »

As far as I know it's perfectly legal to do this and this would be one use it was intended for.  You could first draw your TV in the foreground (with the TV's details specified in local coordinates), push the p. matrix, translate it, draw the inner tv image, then pop it back.  Pretty easy.
Logged
Saint
Level 3
***



View Profile WWW
« Reply #2 on: March 10, 2009, 11:25:06 AM »

No this is not a bad idea at all and in my opinion no different from changing between perspective projection when rendering a scene and orthographic projection when rendering GUI. You can of course change the viewport or compensate for the change in the modelview matrix or geometry, but there is nothing principally wrong with changing the perspective matrix mid-scene.  Smiley

Don't overdo it, though, I've seen cases where people used the projection and modelview matrices at random, not caring about the matrix mode, and that kind of neglects the point of having different modes.
Logged
Ivan
Owl Country
Level 10
*


alright, let's see what we can see

Valaam0
View Profile
« Reply #3 on: March 10, 2009, 11:26:17 AM »

The projection matrix uses a stack just like the modelview matrix. So whatever operations you're doing is using the current state of the projection matrix stack, so there's no problem as long as you push the current matrix onto the stack, and then pop it afterwards (just remember to set the matrix mode to projection when you push the stack, a common mistake)
Logged

http://polycode.org/ - Free, cross-platform, open-source engine.
dspencer
Level 2
**


View Profile
« Reply #4 on: March 10, 2009, 11:55:53 AM »

That is just lovely! Thanks again for the prompt replies!
Logged
Will Vale
Level 4
****


will@secondintention.com
View Profile WWW Email
« Reply #5 on: March 11, 2009, 10:43:43 PM »

Setting the viewport might be easier though Smiley
Logged
Zaphos
Guest
« Reply #6 on: March 12, 2009, 02:13:23 AM »

Technically the minimum stack depth for the projection matrices is 2, while for modelview it's 32 ... so might want to be careful pushing with that stack.  Not sure if that minimum stack depth is an actual limit in practice, though?
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic