]> gitweb.factorcode.org Git - factor.git/commitdiff
gpu.util.wasd: new utility word "wasd-pixel-ray" that converts a screen pixel positio...
authorJoe Groff <arcata@gmail.com>
Wed, 23 Jun 2010 07:48:17 +0000 (00:48 -0700)
committerJoe Groff <arcata@gmail.com>
Wed, 23 Jun 2010 07:48:17 +0000 (00:48 -0700)
extra/gpu/util/wasd/wasd.factor

index 8251fe21b6dd9723b5d21584fad3a76e06783ba5..9eb50ab941f83a40618885e69c0dbbb03928d719 100644 (file)
@@ -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* ;