|
|
I want share three macros to manipulate vectors on screen. I know there is
already Screen_Object in screen.inc include file but I can't use it to
manipulate selected vertices in mesh.
// screen.inc extension by ABX
// 12/04/2002
// Calculate 3D vector equivalent for specified camera parameters and
// screen coordinates. Put it in specified Distance from camera. For
// Distance_Type = yes use Distance as distance between result and
// camera location (placing on sphere around camera location).
// For Distance_Type = no use Distance as distance between camera
// location and plane contaning result and parallel to camera plane
// (placing on plane in front of camera). Input vector is 2D from
// <-.5,-.5> to <.5,.5>
#macro Screen_To_Vector( V2 )
#local V = V2 * <Camera_Aspect_Ratio,1,0> ;
vtransform( V , transform{ Camera_Transform translate CamD } )
#end
#macro Screen_To_Vector_At_Distance( V2 , Distance , Distance_Type )
#local V = Screen_To_Vector( V2 ) ;
( CamL + Distance * ( Distance_Type ? vnormalize( V - CamL ) : ( V - CamL ) /
vlength( CamD ) ) )
#end
// Calculate coordinates on screen for specified 3D vector )
// Screen itself is from <-.5,-.5> to <.5,.5>
#macro Vector_To_Screen( V2 )
#local Dir = vnormalize( V2 - CamL ) ;
#local VD = vdot( vnormalize(CamD) , Dir );
#if ( VD = 0 ) #error "Error : Vector on viewer plane" #end
#local V = vtransform(
- vlength(CamD) * Dir / VD ,
transform{
Camera_Transform
translate CamD
translate -CamL
inverse
}
) ;
< V.x/Camera_Aspect_Ratio , V.y >
#end
// ABX
Post a reply to this message
|
|