
How do i code a Camera Class that doesn't use GLU?
Posted Saturday, 20 June, 2009 - 08:04 by enablerbr ini've been looking around trying to find how to code a camera class. trouble is there doesn't seem to be a single soloution to this. i really want a camera class that not only doesn't use GLU but also allows me to parent a camera to another object if needed. any ideas where to look or code snippets would be welcomed.


Comments
Re: How do i code a Camera Class that doesn't use GLU?
Why do you have need for glu to create camera class?
Re: How do i code a Camera Class that doesn't use GLU?
It is easy to create a camera that doesn't use GLU. The math API in OpenTK is a little ugly (working on it), but it gets the work done. Here is a quick and dirty implementation I cooked up for a project.
It works like this:
TargetPositionandTargetOrientationof the camera.camera.Update(e.Time).GetModelviewMatrixandGetProjectionMatrixto retrieve the relevant matrices and send them to OpenGL - either viaGL.UniformMatrix4if you are using shaders, or viaGL.LoadMatrixif you are using the fixed-function pipeline.Regarding your second question, you will need to create a scene graph: a tree-like structure that indicates the relationships between objects.
Re: How do i code a Camera Class that doesn't use GLU?
thanks the Fiddler. i noticed there is no mention of a WorldMatrix. some of the other types of examples i've seen on the net have a worldmatrix. where would the worldmatrix fit in. sorry for the newbie question.
Re: How do i code a Camera Class that doesn't use GLU?
The world matrix takes you from model space to world space, i.e. it defines the location and orientation of an object in your world. You must then multiply with the view matrix to move from world space into view space (the view matrix defines the location and orientation of the camera in the world).
You can think of it like this: every object in your world has a "world" matrix. The inverse of the world matrix of your active camera is your "view" matrix. The modelview matrix is what you get by multiplying the world matrix of an object with the view matrix of the camera: it takes you directly from object space to view space.
In the above case, if you wish to render a box at (0, 0, 3) (in world coordinates), you simply need to multiply the result of
Matrix4.Translation(0, 0, 3)(i.e. the world matrix) with the result ofcamera.GetModelviewMatrix()(i.e. the view matrix). The result is the modelview matrix for the box, which you can send to OpenGL via LoadMatrix or UniformMatrix4.Re: How do i code a Camera Class that doesn't use GLU?
ahh. i think i'll grab a copy of this book "Beginning OpenGL Game Programming, Second Edition " to help me along. it covers opengl 3.0. is there any other book that might be of help? i already have "3D Math Primer for Graphics and Game Developement".
Re: How do i code a Camera Class that doesn't use GLU?
"Beginning OpenGL Game Programming" is quite good. Between this and google, I think you are covered 100%.
The only OpenGL book I have is the official "red book" for version 1.4. It is quite old, but it is well-written and approachable. I still use it from time to time for legacy stuff, texture parameters and things like that, but the majority of the book covers things deprecated in OpenGL 3.0. (It is quite interesting: OpenGL 3 deprecates only about 200 functions out of 1800, but the resulting API is much, much cleaner.)
Re: How do i code a Camera Class that doesn't use GLU?
i don't think the new red book is out yet. i'll keep an eye out for it. thanks.
Re: How do i code a Camera Class that doesn't use GLU?
thanks for that camera code :) you mention inverse the camera view is the inverse of its individual matrix... i dont see where you do that... is that
-Position? thanksRe: How do i code a Camera Class that doesn't use GLU?
Yes. The thing to keep in mind is that moving the camera in one direction will cause everything to (apparently) move towards the other direction. This is intuitively correct: if camera.X increases by +1 unit, it is the same as if the camera stayed put and everything moved by -1 unit in the x-direction.
The net effect is that you'll have to watch the signs of your camera acceleration/velocity.
Re: How do i code a Camera Class that doesn't use GLU?
Quaternion.Apply does not exist anymore?