View Full Version : vector and vertex ?! and camera rotation

hi everyone http://www.opengl.org/discussion_boards/ubb/smile.gif

if I understand it right the vertex is a point and a vector is a direction from the point or am I wrong ?

and now the camera rotation thing.. how do I create a simple function like the gluLookat but with to points and one up vector ?

exampel:

p1 0,0,-150 // camera position point

p2 0,0,0 // camera lookat point

p3 0,1,0 // camera up vector

how do I calculate the angle to rotate the camera so that it allways will look att the p2 point ? and I meen look att the point not look att that direction from the p1 point.

gluLookat has a lookat vector if I didnīt missunderstand the msdn help file.

satan

02-13-2002, 03:53 AM

just to the vertex and vector thing (to the rotation perhaps somebody else will say something - i am a bit lazy at the moment)

you are right, that a vertex can be understood as a point

but a vector has nothing to do with this (at least not by definition)

a vector has a length and a direction

you can visualize it as an arrow in an 2d or 3d coordinate system (so it has a length and a direction) - visualization for more than 3d are beyond the imagination of most ppl i know (although a vector may have any dimension)

so if you have an vector say (1,0,0) it is an arrow with length 1 pointing allong the positive x-axis

this vector can be located at ANY point in your coord-system (just length and direction are specified not the position)

in order ro understand the concepts of opengl it would be wise to grab some information about vector math and work through

after this it should be easy for you to answer your rotation question yourself

thanks satan http://www.opengl.org/discussion_boards/ubb/smile.gif

I understand the vector and vertex difference now.. but I still donīt know how to calculate the rotation angle for my camera I have tried but the camera lookat point moves so it doesnīt work the way I want it.. and my math sucks!

[This message has been edited by McZ (edited 02-13-2002).]

satan

02-13-2002, 02:52 PM

i am quite new to opengl and working on my camera modell, too, at the moment

of course i can tell you how i implemented it but it really involves some nice http://www.opengl.org/discussion_boards/ubb/smile.gif vector and some not so really nice matrix math

all i could say is do the math

learn this vector and matrix stuff

without you will be lost

3d graphics programming is math

and the basic stuff of both is not so really complicated

take a look at this and try to make your way through

http://mathworld.wolfram.com/Vector.html

just do not give up

p.s.:i explain how i do my camera in the topic unsure about my camera model - take a look there if you want to know how i do it

[This message has been edited by satan (edited 02-13-2002).]

Jambolo

02-13-2002, 10:19 PM

McZ,

gluLookAt does exactly what you want. The first 3 parameters are the location of the camera. The second three are the point that the camera is supposed to look at. The last three are the up vector.

As far as vertex vs. vector...

First, "vertex" is not the right term. What you are really asking about is the difference between a "position" or "location" and a vector, right? Generally, when you see the word "vector", it means a positionless direction and magnitude. But remember this: a location can be represented by a vector and a vector can be represented by a location, so the two are frequently interchanged.

Jambolo: No it doesnīt work the way I wanīt I have allready tried and the camera donīt get where I want it.

exampel:

i have one cube at 0,0,0 and one at 0,0,-40 so I know where the center of the world is and the second cube will only be visible at the second camera pos and it will be the same range to that one as the first else it doesnīt work

first pos

0,0,-150 // cam pos

0,0,0 // look at

0,1,0 // up

second pos

0,-150,0 // cam pos

0,0,0 // look at

0,1,0 // up

if this should work the way I want it to the camera should look att the cube at both the positions the difference will be that the second pos it has rotate 90 degres and the world Z positiv will go to the right

satan

02-14-2002, 02:47 AM

i think that the up vector for the second camera position is wrong

as the superbible says about glulookat:

defines a viewing transformation based on the position of the eye, the position of the centre of the scene, and a vector pointing up FROM THE VIEWER'S PERSPECTIVE

that means up should be perpendicular to view

so if you change your view to point along the positive y-axis (as you do) you must recalculate your upvector - or since you do not want to hear about this math stuff

try it with up=(0,0,1)

I solved the problem http://www.opengl.org/discussion_boards/ubb/smile.gif

the gluLookAt works ok but the problem vas that if I have Z:-150 in gluLookAt it would be the same as if I glTranslatef(0.0f, 0.0f, 150.0f) and then everything was drawn off-screen so thats why it didnīt work http://www.opengl.org/discussion_boards/ubb/smile.gif

Powered by vBulletin® Version 4.2.3 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.