From c7a2ef4d4fd187d7e99ca7441176adc96dce7100 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Wed, 23 Jun 2010 00:48:17 -0700 Subject: [PATCH] gpu.util.wasd: new utility word "wasd-pixel-ray" that converts a screen pixel position to a world-space vector, indicating direction from eye location --- extra/gpu/util/wasd/wasd.factor | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/extra/gpu/util/wasd/wasd.factor b/extra/gpu/util/wasd/wasd.factor index 8251fe21b6..9eb50ab941 100644 --- a/extra/gpu/util/wasd/wasd.factor +++ b/extra/gpu/util/wasd/wasd.factor @@ -54,13 +54,22 @@ M: wasd-world wasd-fly-vertically? drop t ; CONSTANT: fov 0.7 +: wasd-fov-vector ( world -- fov ) + dim>> dup first2 min >float v/n fov v*n ; inline + :: generate-p-matrix ( world -- matrix ) world wasd-near-plane :> near-plane world wasd-far-plane :> far-plane - world dim>> dup first2 min >float v/n fov v*n near-plane v*n + world wasd-fov-vector near-plane v*n near-plane far-plane frustum-matrix4 ; +:: wasd-pixel-ray ( world loc -- direction ) + loc world dim>> [ /f 0.5 - 2.0 * ] 2map + world wasd-fov-vector v* + first2 neg -1.0 0.0 4array + world wasd-mv-inv-matrix swap m.v ; + : set-wasd-view ( world location yaw pitch -- world ) [ >>location ] [ >>yaw ] [ >>pitch ] tri* ;