Anyone have a World to Screen func -clipping?

Blitz3D Forums/Blitz3D Programming/Anyone have a World to Screen func -clipping?

Tom(Posted 2004) [#1]
Hi,

Anyone have a function to do what CameraProject does without clipping?

Cheers
Tom


DJWoodgate(Posted 2004) [#2]
I don't know the maths for projection (though its probably straightforward enough) so I would probably try the easy way out (if you can call it that)...

Temporarily reset the camera near and far ranges to very low and high values (but within floating point precision). Now only stuff on or behind the camera plane will be clipped. For stuff behind the camera I suppose you could tform the point to the camera, then if z is less than zero negate z and tform the point back to world before projecting, which should give you the position that point would be at behind the camera projected on the screen in the appropriate position, because it's now pretending it's in front of the camera. I guess you could do something similar to move points that happen to fall on or near the camera plane away from it slightly - If (after negating Z if necessary), z is closer than your super small camera near value then set it to this value.

Edit...

Here is a function which seems to work more or less but that link Klaas posted below is probably worth further investigation because this still has issues with points that lie on the plane. I seem to recall running into this before.

Function ProjectNoClip(camera,x#,y#,z#,near#,far#)
	CameraRange camera,0.001,1000000
	TFormPoint x,y,z,0,camera
	z = TFormedZ()
	If z < 0 Then z = -z
	If z < 0.001 Then z = 0.001
	TFormPoint TFormedX(),TFormedY(),z,camera,0
	CameraProject camera,TFormedX(),TFormedY(),TFormedZ()
	CameraRange camera,near,far
End Function


In fact setting the near value (and Z value adjustment) to 0.01 seems to stabilise it a bit, so its probably a floating point accuracy issue. However points on the plane far from the camera will still not be dealt with properly so beware. Hmmm, Maybe you could try increasing the near value (and the Z value adjustment) based on distance, that should settle it down. Of course this will effect the actual position of the projected coordinates, but as these will be far off the screen anyway hopefully not much of a concern as long as the vector to those coordinates from a point that is in view is more or less right.


Klaas(Posted 2004) [#3]
maybe this one helps

http://colos1.fri.uni-lj.si/~sis/GRAFIKA/ALGORITMI/2D_CLIPPING/transform.html