• Advertisement
Sign in to follow this  

Render 3D - Camera - Up Vector

This topic is 4324 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, I am writing my first 3D engine and i need your assistance I am not using OpenGL or DirectX (just basic software rendering, i want to learn) Basically, what i am trying to do is render some 3D points to a 2D monitor from different camera locations and camera target vectors What i have done: I have my 3D Points (lets call them P1, P2, P3...) I have my Camera - my camera contains the camera position, and the target position lets call camera C) Using the Camera, C, i constructed a Plane, with the normal of a vector constructed from the target position and the camera position I project all my 3D points onto the Plane, now all my points lie on the Plane What i need to do and dont know how to do: Convert the 3D coords of the points onto the Plane to 2D coordinates To do that, i plan to do this... Right now my equation of Plane: Plane = Ax + By + Cz + d, where (A, B, C) is the target vector I should change the equation of the Plane to this form: Plane = (x1,y1,z1) + sX + tY, where (x1,y1,z1) is the camera position, Y is the UP VECTOR of the plane and X RIGHT VECTOR of the plane (or cross product of Y and the Normal), then (s,t) will be the 2D coords The problems is, i do not know hot to determine the UP VECTOR or the RIGHT VECTOR, if i have one i can determine the other, but i dont have both :S...I do not plan to have roll in this program Also: I would like to have some hints on how to control the camera...just like in CS style, where when u walk forward u move the plan closer to the target, and when you move your mouse up the target position will move up as well Thanks! [Edited by - aznium on April 18, 2006 8:34:33 PM]

Share this post


Link to post
Share on other sites
Advertisement
Can you just use (0, 1, 0) for your up vector? Then cross with forward to get right.

It sounds like you are trying to recreate the graphics pipeline in software. If that is the case, you should probably use matrices (world, view, projection) combined with perspective division. If that is not the case, plz explain your problem again. And I would love to see your 3D monitor, mines only 2D :)

Moving the camera around: If you detect horizontal mouse movement, rotate your forward vector about the up axis, then recompute your right axis. For vertical movement, rotate your forward vector about the right axis, then recompute your up axis.
Careful though, this method will allow you to do backflips. To disallow this, do not change the up vector...
Again, careful though, if your forward vector approaches your up vector, you will get gimbal lock. To keep this from happening, limit the forward vector such that it cannot be the same as the up vector.

Share this post


Link to post
Share on other sites
lol . typed 3D monitor by mistake =\ its fixed now

thanks for quick reply

could you explain "(world, view, projection) combined with perspective division." in more detail

i read it in wikipedia but i dont seem to understand it completely =
espcially perspective division

thanks.

Share this post


Link to post
Share on other sites
Quote:
Original post by blaze02
Again, careful though, if your forward vector approaches your up vector, you will get gimbal lock. To keep this from happening, limit the forward vector such that it cannot be the same as the up vector.
Just wanted to mention that gimbal lock really isn't a problem with FPS-style camera control; you don't need to place any limitations on the forward vector (other than constraining it to prevent the aforementioned 'backflip').

Share this post


Link to post
Share on other sites
and how would u rotate a vector on an axis

could u give me the maths for that?

thanks

Share this post


Link to post
Share on other sites
Quote:
Original post by aznium
and how would u rotate a vector on an axis

could u give me the maths for that?
Writing a software renderer is extremely math-intensive. Things like matrix transformations, rotations, and homogenous coordinates are all prerequisites for such an endeavor.

On the one hand, a software renderer is a good way to learn this material because it forces you to understand it in a deep way, whereas with APIs such as OpenGL and DirectX you can often 'squeak by' without really knowing what you're doing. On the other hand, if you try to jump in without some basics under your belt, you might just end up getting frustrated.

There are lots of good materials available for learning basic 3D math (there's a thread on the topic in math & physics right now that you might consider checking out).

Share this post


Link to post
Share on other sites
yes im doing it so i can really understand the stuff deeply

which thread are u refering?

too bad my maths isnt that strong :S ... still in hs...

can i do it with the equation of a circle in 3d space to rotate a point on an axis?

and when u meant gimbal lock, do u mean something like where im (0,500,0) and im looking down at the origin?

thanks.

Share this post


Link to post
Share on other sites
Quote:
Original post by aznium
yes im doing it so i can really understand the stuff deeply

which thread are u refering?
Here is the thread I had in mind. I guess there's not that much info there at the moment, but there are a couple of links you might find useful.
Quote:
too bad my maths isnt that strong :S ... still in hs...
Well, you've got plenty of time to learn :)
Quote:
can i do it with the equation of a circle in 3d space to rotate a point on an axis?
Not sure what you mean, but pretty much all 3D rotation is derived from a single axis-angle formula, which you'll learn as you study the material.
Quote:
and when u meant gimbal lock, do u mean something like where im (0,500,0) and im looking down at the origin?
Not really, but you'll also learn what gimbal lock is as you go (if you're curious now, just google the term and check out a few of the hits).

Share this post


Link to post
Share on other sites
Quote:
Well, you've got plenty of time to learn :)


actually im writing this program thats due like next week...just doing some extra 3d stuff lol

can u give me the formula for 3d rotation, or a tutorial where i can learn from?

thanks

Share this post


Link to post
Share on other sites
Quote:
Original post by aznium
can u give me the formula for 3d rotation, or a tutorial where i can learn from?
Here is the formula, and in perhaps slightly more readable form here. In practice rotations are usually carried out via a matrix-vector multiplication; the matrix form of the axis-angle rotation can be found here (you may need to transpose this, depending on whether you're using row or column vectors).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement