PDA

View Full Version : How to set the positon of the projection plane in OpenGL?



hawaii
05-03-2007, 02:07 AM
Dear everyone,

Who knows how to set the position of the projection plane in OpenGL, or, is there a way to set focus value when using OpenGL?

I am how working on an algorithm, which needs this value. But I don't know how to do this :( I hope who knows this could tell me. Thank you very much!

:)

Jens Scheddin
05-03-2007, 06:07 AM
Originally posted by hawaii:
Dear everyone,

Who knows how to set the position of the projection plane in OpenGL, or, is there a way to set focus value when using OpenGL?

I am how working on an algorithm, which needs this value. But I don't know how to do this :( I hope who knows this could tell me. Thank you very much!

:) The projection matrix does not have a position. The position of the observer comes with the modelview matrix.

There is no such thing as a focus in standard OpenGL, because the camera is treated as an infinitely small point. Like a pinhole camera. If you want a point of focus, you should have a look at the "depth of field" effect, which simulates a real camera lens.

knackered
05-03-2007, 06:41 AM
god knows what you're asking for, but in case you're talking about specifying a frustum that has a different projection plane to the near plane, then here's some code to do it:-

void createFrustum(double left, double right, double bottom, double top, double nearDist, double farDist, double projDist)
{
double m[16];

double x, y, a, b, c, d;
double width = right-left;
double height = top-bottom;
double depth = farDist-nearDist;

x = (2.0*projDist) / width;
y = (2.0*projDist) / height;
a = (right+left) / width;
b = (top+bottom) / height;
c = -(farDist+nearDist) / depth;
d = -(2.0*farDist*nearDist) / depth;

#define M(A,B) m[(B)*4+(A)]
M(0,0) = x; M(0,1) = 0.0; M(0,2) = a; M(0,3) = 0.0;
M(1,0) = 0.0; M(1,1) = y; M(1,2) = b; M(1,3) = 0.0;
M(2,0) = 0.0; M(2,1) = 0.0; M(2,2) = c; M(2,3) = d;
M(3,0) = 0.0; M(3,1) = 0.0; M(3,2) = -1.0; M(3,3) = 0.0;
#undef M

glMatrixMode(GL_PROJECTION);
glLoadMatrixd(m);
glMatrixMode(GL_MODELVIEW);
}

RigidBody
05-03-2007, 07:09 AM
holy cow! this is the first time that i see you post code- what's wrong, knackered?

knackered
05-03-2007, 07:25 AM
I've posted code before...not very frequently, but a handful of times.
I'm procrastinating on a problem of my own, so I've done all the hoovering, all the washing, re-arranged my front room, and pasted code onto a forum. What else can I do to distract me from the real issue at hand???

RigidBody
05-03-2007, 07:31 AM
hm...hoovering, washing, rearranging the front room...you're way ahead of myself.

by the way, what's the real issue? that we all die someday?

knackered
05-03-2007, 07:39 AM
re-factoring some code written while doing a balancing act.

RigidBody
05-03-2007, 07:44 AM
how many lines?

knackered
05-03-2007, 07:47 AM
too many. way too many.

RigidBody
05-03-2007, 07:57 AM
anything i can do to take some of the pain from you?

knackered
05-03-2007, 08:03 AM
nobody can help me now....I'm on my own in this hell.

RigidBody
05-03-2007, 08:08 AM
on your own, maybe, but not alone.

knackered
05-03-2007, 08:23 AM
you are actually beginning to scare me now, rigidbody.
even your name is taking on a whole new meaning.

RigidBody
05-03-2007, 08:36 AM
in which sense?

knackered
05-03-2007, 09:13 AM
the biblical sense?

RigidBody
05-03-2007, 09:53 AM
ehm- no, not rigid in a religious way. i do not pay church taxes anymore, and i haven't started my own religion either.

knackered
05-03-2007, 10:10 AM
phew, that's a relief.

hawaii
05-03-2007, 10:17 PM
Thank you very much for your kindly replies, now I know how to deal with the problem from your posts.

Thanks again:)

knackered
05-04-2007, 02:16 AM
Woah woah woah there...
How has any of this helped?

zed
05-04-2007, 02:23 AM
um excuse me but didnt your mum tell u its rude to butt into other ppls conversations

dorbie
05-04-2007, 03:02 AM
It might help if you explain what you are trying to do.

Asymmetric frustum, stereo rendering, depth of field?

The word focus has no firm meaning in basic graphics rendering.

Give us info on the algorithm, we're all grown up, we can handle it.

foobar
05-04-2007, 08:06 AM
<insult deleted by moderator>, he is trying to do exactly what he says, set the position of the projection plane. In OpenGL the projection plane is set by the near parameter value to glFrustum. Unfortunately this means you can't change the focal length without affecting z-buffer mapping.

knackered
05-04-2007, 08:13 AM
then he got his answer on the 2nd reply, [insult response deleted by knackered].
incidentally, opengl imposes no such limitations. a matrix is a matrix.

zed
05-04-2007, 03:08 PM
Give us info on the algorithm, we're all grown up, we can handle it. btw theres code in the opengl FAQ on how to extract the near clip plane from opengl

V-man
05-04-2007, 07:24 PM
Originally posted by foobar:
, he is trying to do exactly what he says, set the position of the projection plane. In OpenGL the projection plane is set by the near parameter value to glFrustum. Unfortunately this means you can't change the focal length without affecting z-buffer mapping. That's so obvious, it can't be the answer.
He is working on an algorithm which needs the focal length.

dorbie
05-04-2007, 10:34 PM
foobar, I deleted your insult, watch your tone in future please.

There's a huge assumption in your reply that has absolutely no basis in the original post, not only is it a wild guess but it's very likely to be wrong unless you know something we don't.

The original poster needs to supply more information and be much more specific.

dorbie
05-04-2007, 10:40 PM
V-man, there is nothing obvious about foobar's zbuffer non-sequitur.

knackered
05-05-2007, 06:26 AM
hawaii is long gone. Like Batman into the night.
I fear we shall never know what his grand plan was.

remdul
05-05-2007, 11:48 AM
What I understood of this thread is that hawaii wants to know how to set up his projection matrix, all in a polite manner. English doesn't seem to be his native language, yet he took the time to format it properly.

---

Am I the only one concerned about the OpenGL forums descending into an anarchic melee? This used to be a neutral place. I for one have become a lot more reluctant to post my questions here.

I think it is a real shame that the some of the most knowledgeable people around here seem to be the culprits.

knackered
05-05-2007, 01:58 PM
I don't know what you're talking about. Nobody was in any way aggressive (except for foobar).
Hawaii got his answer and was perfectly happy. He thanked me and went on his merry way.
If you think this is anarchic, you've lived a very sheltered life.
If you're referring to dorbie, then he has a point - focus does have no meaning in OpenGL. He's got an enquiring mind, just wanted to know more about what hawaii wanted to achieve. He was polite, but firm. Hawaii (and you) should be delighted someone took a real interest in his question. It's a clear demonstration of the exceptional value of this forum, not the opposite as you're trying to claim.

remdul
05-06-2007, 09:27 AM
I'm not disputing the value of this forum at all, I was just worried about the somewhat hostile attitude of some posters recently, and felt I had to say this. I wasn't referring to Dorbie.

Thanks.

dorbie
05-07-2007, 01:21 AM
remdul, I don't think any of this was intended as mean spirited, you have to hang out here a bit before you realize how special it is to see knackered post code. The rest of the chatter was just OT banter, I don't think anyone had a go at the original poster, if they had I would have acted accordingly. As for hawaii, he's welcome back any time to flesh out the details.

RigidBody
05-07-2007, 02:17 AM
Originally posted by dorbie:
how special it is to see knackered post code. that's exactly what i thought.


Originally posted by dorbie:
The rest of the chatter was just OT banterwhich i hope didn't offend anyone. i really think we should have an offtopic thread here where people can chill out...if we had such a thread, the other threads would probably be "cleaner"

knackered
05-07-2007, 12:52 PM
charming, anyone would think I never contribute anything round here.
Actually, fair point.

RigidBody
05-08-2007, 12:44 AM
oh nooo- that's not what i wanted to say. i've seen lots of contribution from you- but rarely code.

and i have to admit, of all of your posts, the ones in which you reply to someone who asks if somebody can post code to solve his special problem are way more entertaining and therefore stay in my mind for a longer time ;)

dorbie
05-14-2007, 02:30 AM
Yep, more often than not knackared is getting hot & bothered at someone for daring to ask for code! You'd think they were reaching over onto his hard drive and stealing his precious bodily fluids :-)

(If you don't get the reference just move on, it's still not biblical).

RigidBody
05-14-2007, 03:06 AM
you should not joke about stealing bodily fluids- don't you know the story of boris becker and that russian model whose name i do not remember :p

about giving away code: we've seen more than a few guys here who obviously wanted to have their homework done by the community. one day i even received an email by someone called "jasmin", who wanted me to code something absolutely noobish for her. here i agree with knackered: i do not spend even 5 minutes because somebody else is too lazy to do his homework.

ZbuffeR
05-14-2007, 08:50 AM
Ok, Dr. Strangelove, it was easier than I expected ;)

foobar
05-25-2007, 02:55 PM
Dorbie, everything we needed to know was in the title of his post, hence the highly appropriate, but deleted, description of the 'help' being provided.
(For future reference it is always safe for you to assume I know something you don't :) )

And V-man, perhaps I didn't make it completely clear, in pin-hole projection the focal length is the distance to the projection plane (which is the near plane in OpenGL).

Brolingstanz
05-26-2007, 01:27 AM
I'm procrastinating on a problem of my own, so I've done all the hoovering, all the washing, re-arranged my front room, and pasted code onto a forum. What else can I do to distract me from the real issue at hand???Have you tried washing the dishes? I find that to be very relaxing. I've had some of my greatest inspirations while giving a greasy pan a good scrub.

knackered
05-28-2007, 11:57 AM
Unfortunately I have a dishwasher.