main ( -- )


Vocabulary
raylib.demo.mesh-picking

Inputs
None

Outputs
None

Definition


:: main ( -- )
[
make-camera :> camera Ray new :> ray init-assets
:> ( tower triangle ) f :> bary! camera CAMERA_FREE
update-camera 60 set-target-fps
0 mesh-picking-frame set-global
<hit-state> :> the-hit-state f :> hit-mesh-bbox! [
camera CAMERA_FREE update-camera
get-mouse-position camera get-mouse-ray
:> ray the-hit-state dup reset-hit-state
ray handle-ground-hit
ray triangle first3 handle-triangle-hit [
dup nearest-hit>> point>> triangle first3
vector3-barycenter bary!
] [ f bary! ] if ray tower [ model>> ] [ bbox>> ] bi
handle-mesh-hit
hit-mesh-bbox! begin-drawing RAYWHITE
clear-background camera begin-mode-3d
hit-mesh-bbox tower triangle draw-objects
dup draw-cursor ray MAROON draw-ray 10 10 draw-grid
end-mode-3d dup name>> "Hit Object: %s" sprintf 10
30 10 BLACK draw-text nearest-hit>> dup hit>> [
70 :> ypos [
distance>> "Distance: %3.2f" sprintf 10 ypos
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 "Barycenter: %3.2f %3.2f %3.2f"
sprintf 10 ypos 45 + 10 BLACK draw-text
] when*
] [ drop ] if
"Use Mouse to Move Camera" 10 screen-height 20 -
10 GRAY draw-text
"(c) Turret 3D model by Alberto Cano" screen-width
200 - screen-height 20 - 10 GRAY draw-text
10 10 draw-fps end-drawing
] while-raylib-window
] with-window ;