|
@@ -116,6 +116,32 @@ Class Camera Extends Entity
|
|
|
Return _projMatrix
|
|
|
End
|
|
|
|
|
|
+ #rem monkeydoc Converts a point from world coordinates to viewport coordinates.
|
|
|
+ #end
|
|
|
+ Method ProjectToViewport:Vec2f( worldVertex:Vec3f )
|
|
|
+
|
|
|
+ Local clip_coords:=ProjectionMatrix * InverseMatrix * New Vec4f( worldVertex,1.0 )
|
|
|
+
|
|
|
+ Local ndc_coords:=clip_coords.XY/clip_coords.w
|
|
|
+
|
|
|
+ Local vp_coords:=Cast<Vec2f>( Viewport.Size ) * (ndc_coords * 0.5 + 0.5)
|
|
|
+
|
|
|
+ Return vp_coords
|
|
|
+ End
|
|
|
+
|
|
|
+ #rem monkeydoc Converts a point from viewport coordinates to world coordinates.
|
|
|
+ #end
|
|
|
+ Method UnprojectFromViewport:Vec3f( viewportCoords:Vec2f )
|
|
|
+
|
|
|
+ Local vp_coords:=viewportCoords / Cast<Vec2f>( Viewport.Size ) * 2.0 - 1.0
|
|
|
+
|
|
|
+ Local clip_coords:=New Mat4f( Matrix ) * -ProjectionMatrix * New Vec4f( vp_coords,-1.0,1.0 )
|
|
|
+
|
|
|
+ Local world_coords:=clip_coords.XYZ/clip_coords.w
|
|
|
+
|
|
|
+ Return world_coords
|
|
|
+ End
|
|
|
+
|
|
|
Protected
|
|
|
|
|
|
#rem monkeydoc @hidden
|