3d - Perspective projection - how do I project points which are behind 'camera'? -
i'm writing own software rasterizer in java, , ran trouble it... take @ sample image, please:
this sample draw simple square grid on plane. works fine until move camera close enough points move behind it. after that, they're no longer projected correctly, can see (vertical lines - points should behind camera projected on top of screen).
my transformation matrices , vectors same ones directx using (perspectivefovlh projection, lookatlh camera).
i'm using following transformation method project 3d point:
- 3d vector transformed created.
- vector multiplied viewprojection matrix.
after that, point transformed screen using following method:
// 'vector' input vector in projection space // projection screen double vx = vector.x / vector.z; double vy = vector.y / vector.z; //translate //surfacew width , surfaceh height of rendering window. vx = (( vx + 1.0f) / 2.0f) * surfacew; vy = ((-vy + 1.0f) / 2.0f) * surfaceh; return new vector3(vx, vy, vector.z);
as said earlier, works fine until point moves behind camera. fact is, can figure out when point behind camera (by testing it's z value after final transform), since i'm drawing lines , other line based objects, can't skip point.
then tried setting transformation pipeline according the direct3d transformation pipeline article on msdn.
unfortunately, haven't had luck (same results), highly appreciated, since i'm bit stuck on one.
thank you.
best regards, alex
you need intersect line front clipping plane in 3d space , truncate line draw line segment that's visible:
| | | x------------+-----------o | | | * - camera | | | clipping plane
you've got line xo
x
in front of clipping plane , o
behind it. intersect line clipping plane generate point +
. know of x
, o
visible draw line x
+
.
this way you're not projecting points behind camera.
Comments
Post a Comment