problem with projection

Started by
3 comments, last by staticVoid2 16 years, 3 months ago
I'm having a problem with projection when converting 3d points in a camera object, the camera faces in the negative z axis direction. I have the 3d points that are converted into the cameras coordinate system but the problem is when the coordinates have a z value greater than 0 or when they lie behind the camera it creates an inverse image. I display the 2d converted points on a x and y axis that are centered on the screen. here's the code I use to project the 3d points:

      result.x = (field_of_view * point.x) / (distance_from_plane - point.z);
      result.y = (field_of_view * point.y) / (distance_from_plane - point.z);


where field_of_view is usualy 1000 and distance_from_plane is usualy 0. once i get the result i just draw it to the screen like: final.x = screen_center.x + result.x final.y = screen_center.y - result.y If I could upload an image or somthing you would see the problem clearer but i'm not sure how to, or if you can.
Advertisement
Just snap a screenshot of your app, you can use something like FRAPS if you'd like. Then go to imageshack.us and upload your pic, then copy and paste the link here so we can see it.
here's the first image where the position of the camera is somthing like (10, 10, 200) and rotation is (0, 0, 0):

Free Image Hosting at www.ImageShack.us

here the position is (10, 10, -200) and rotation still (0, 0, 0):

Free Image Hosting at www.ImageShack.us

as you can see i havent implemented bsp trees or anything yet but you can see the two blue triangles on the top right are where the bottom left sides were in the first picture, it's sort of an inverse image?? the cube shape is placed on the origon with a size of 100 i think.
You forget the Culling-step.

ZNear < Z < ZFar ;if fail, cull.

P = Cot(0.5 * FieldOfView)

X2 = X * P
Y2 = Y * P * AspectRatio

-Z < X2 < Z ;if fail, cull.
-Z < Y2 < Z ;"

Peter

[Edited by - Shadebob on January 16, 2008 2:03:39 PM]
Peter
any good articles on clipping?

This topic is closed to new replies.

Advertisement