rear point perspective

Started by
7 comments, last by fir 10 years, 4 months ago

when i transform 3d (x,y,z) points onto the 2d screen I just use

something (exactly) like that

if( z > 1.0 )
{
screen_x = (x/z)*500;
screen_y = (y/z)*500;
}

but now i need to cast 3d line segments onto 2d,

Is there some formula to transform both points (it is front and rear if there is the case) to 2d then just draw a line in 2d to achieve that?

much tnx

Advertisement
You project (that is the technical word) both points the way you described, and then join them in 2d. If one of the points is behind the observer (z <= 0), it gets a little trickier: It's probably best if you clip the segment to the view frustum before projection, which would prevent that from happening in the first place.

You project (that is the technical word) both points the way you described, and then join them in 2d. If one of the points is behind the observer (z <= 0), it gets a little trickier: It's probably best if you clip the segment to the view frustum before projection, which would prevent that from happening in the first place.

ye i think i should project both then draw 2d line (I got a routine to draw 2d with 2d clipping so i can use it)- but how exactly project the rear or z==0 point?

AFAIK, it's not possible to do what you're asking. If one of your points is in front of the camera and one is behind the camera, and you try to join them up, then you will not get the desired behaviour.

The trick is to do clipping in 3D space. There exists a 3D line segment from point A (in front of the camera) and point B (behind the camera). You can calculate a point C which is the point where the line segment intersects the near plane and project that point into 2D instead. Then your 2D line drawing joins up the projected point A to the projected point C which will appear as you want it to.

Or, save yourself a little hassle and do your line drawing in 3D instead of in 2D and let the graphics hardware handle all the projection and clipping for you. I'd strongly recommend this route unless you have a compelling reason to do your line drawing in 2D.

AFAIK, it's not possible to do what you're asking. If one of your points is in front of the camera and one is behind the camera, and you try to join them up, then you will not get the desired behaviour.

The trick is to do clipping in 3D space. There exists a 3D line segment from point A (in front of the camera) and point B (behind the camera). You can calculate a point C which is the point where the line segment intersects the near plane and project that point into 2D instead. Then your 2D line drawing joins up the projected point A to the projected point C which will appear as you want it to.

Or, save yourself a little hassle and do your line drawing in 3D instead of in 2D and let the graphics hardware handle all the projection and clipping for you. I'd strongly recommend this route unless you have a compelling reason to do your line drawing in 2D.

Ye i could do 3d cut but it will be slow. I am not sure if such

simple rear point cast should be impossible, maybe it will be

something like the same as front point cast but with -z... ?

i could do 3d cut but it will be slow

(x y z) need to be in camera space when perspective projection is applied. In camera space the near clipping plane is an axis aligned plane at the given distance from the eye point. Computing a ray-to-plane intersection with it can therefore be done as a 1D operation.

i could do 3d cut but it will be slow

(x y z) need to be in camera space when perspective projection is applied. In camera space the near clipping plane is an axis aligned plane at the given distance from the eye point. Computing a ray-to-plane intersection with it can therefore be done as a 1D operation.

Indeed youre right, good point, it is in camera space, but can you maybe say me how to clip that?

I got two points front and rear and the clippning

plane would be z = 1.0...

well I think i should take

m = front_to_plane__z_dist / front_to_rear__z_dist

then scale

front_to_rear__x_dist , front_to_rear__y_dist

by it and add it to front_x , front_y

and this should work?

Will be this perspective correct? Still i am not quite sure

if simple transformation applied to rearpoint is not

possible.. but will check this way

... can you maybe say me how to clip that?

With 2 points p1, p2 giving a straight line segment, a ray can be formulated so that the ray's independent parameter, t, restricts the ray to have only points on the said segment:

r( t ) := p1 + t * ( p2 - p1 ) w/ 0 <= t <= 1

When both points are given in camera space then the ray is given in camera space, too. With n being the distance of the near clipping plane along z, we can first check whether both points (and hence the entire line segment) would be culled

p1z < n AND p2z < n then culled

or else both are inside the view volume

p1z >= n AND p2z >= n then project into 2D as is

or else clipping is needed (i.e. one point is on this and the other point is on the other side of the plane).

If clipping is needed, then the segment intersects the clipping plane. The plane has z = n everywhere, so the intersection point must have z = n, too. The z co-ordinate of the ray should hence be

rz( tn ) = p1z + tn * ( p2z - p1z ) == n

Solving this for tn can be done analytically

tn = ( n - p1z ) / ( p2z - p1z )
and be computed numerically as long as p2z - p1z is not zero (if it is zero then the line segment lies totally inside the clipping plane and can be used as is). Computing the ray's x and y co-ordinates with the found tn gives you the other both co-ordinates of the intersection point.
r( tn )
So replace those one point p1, p2 that has its z less than n with r(tn), and continue as usual.

allright

This topic is closed to new replies.

Advertisement