! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien.enums arrays classes.struct combinators.short-circuit
-continuations destructors formatting grouping io.backend io.pathnames kernel math
-math.functions.private math.vectors namespaces raylib sequences threads
-vocabs.metadata ;
+USING: accessors alien.enums arrays combinators.short-circuit
+continuations destructors formatting grouping io.backend io.pathnames
+kernel math math.functions.private math.vectors namespaces raylib
+sequences vocabs.metadata ;
IN: raylib.demo.mesh-picking
screen-width screen-height "raylib [models] example - mesh-picking" init-window ;
: make-camera ( -- camera )
- Camera3D <struct>
+ Camera3D new
20 30 20 <Vector3> >>position
0 10 0 <Vector3> >>target
0 1.6 0 <Vector3> >>up
45 >>fovy
- CAMERA_PERSPECTIVE >>type ;
+ CAMERA_PERSPECTIVE >>projection ;
: resource ( fname -- path )
"raylib.demo.mesh-picking" "_resources" vocab-file-path swap append-path normalize-path ;
TUPLE: hit-state name color nearest-hit ;
: <hit-state> ( -- obj )
"None" WHITE
- RayCollision <struct>
+ RayCollision new
most-positive-finite-float >>distance
f >>hit
hit-state boa ;
: draw-cursor ( hit-state -- )
dup nearest-hit>> hit>> [
[
- [ nearest-hit>> position>> ] [ color>> ] bi
+ [ nearest-hit>> point>> ] [ color>> ] bi
'[ 0.3 0.3 0.3 _ draw-cube ]
[ 0.3 0.3 0.3 RED draw-cube-wires ] bi
]
[
nearest-hit>>
- [ position>> dup ] [ normal>> ] bi v+ RED draw-line-3d
+ [ point>> dup ] [ normal>> ] bi v+ RED draw-line-3d
] bi
]
! LOG_ALL set-trace-log-level
[
make-camera :> camera
- Ray <struct> :> ray
+ Ray new :> ray
init-assets :> ( tower triangle )
f :> bary!
ray handle-ground-hit
ray triangle first3 handle-triangle-hit
- [ dup nearest-hit>> position>> triangle first3 vector3-barycenter bary! ] [ f bary! ] if
+ [ dup nearest-hit>> point>> triangle first3 vector3-barycenter bary! ] [ f bary! ] if
ray tower [ model>> ] [ bbox>> ] bi handle-mesh-hit hit-mesh-bbox!
nearest-hit>> dup hit>> [
70 :> ypos
[ distance>> "Distance: %3.2f" sprintf 10 ypos 10 BLACK draw-text ]
- [ position>> first3 "Hit Pos: %3.2f %3.2f %3.2f" sprintf 10 ypos 15 + 10 BLACK draw-text ]
+ [ point>> first3 "Hit Pos: %3.2f %3.2f %3.2f" sprintf 10 ypos 15 + 10 BLACK draw-text ]
[ normal>> first3 "Hit Norm: %3.2f %3.2f %3.2f" sprintf 10 ypos 30 + 10 BLACK draw-text ]
tri
bary [ first3