74 lines
1.9 KiB
Nim
74 lines
1.9 KiB
Nim
# vim: set et sta sw=4 ts=4 :
|
|
|
|
import
|
|
std/strformat
|
|
|
|
import reasings
|
|
import raylib
|
|
|
|
import
|
|
lib/configuration,
|
|
lib/embeddedfs
|
|
|
|
|
|
# Emscripten specific imports
|
|
proc emscripten_set_main_loop( f: proc() {.cdecl.}, a: cint, b: bool ) {.importc.}
|
|
# proc emscripten_sleep( a: cuint ) {.importc.}
|
|
|
|
var camera = Camera(
|
|
position: Vector3(x: 5, y: 5, z: 10), # Camera position
|
|
target: Vector3(x: 0, y: 0, z: 0), # Camera target it looks-at
|
|
up: Vector3(x: 0, y: 1, z: 0), # Camera up vector (rotation over its axis)
|
|
fovy: 45, # Camera field-of-view apperture in Y (degrees)
|
|
projection: Perspective # Defines projection type, see CameraProjection
|
|
)
|
|
|
|
|
|
var count = 0
|
|
let duration = 3000
|
|
let startPositionX: float32 = 45.0
|
|
let finalPositionX: float32 = 120.0
|
|
var currentPositionX = startPositionX
|
|
|
|
|
|
# This only works with:
|
|
# --passL:"-s EXPORT_FUNCTIONS=_nativeGreet", but it breaks raylib loading.
|
|
# hmmmmm. EXPORT_ALL=1 is also a no go.
|
|
# Maybe it won't be necessary with raylib/opengl input
|
|
#
|
|
#[ proc nativeGreet*(): int {.exportc.} =
|
|
echo "Oh jeez, hello from native nim!"
|
|
return 0 ]#
|
|
|
|
|
|
proc mainLoop() {.cdecl.} =
|
|
defer: closeWindow()
|
|
|
|
initWindow( 800, 600, "raylib nim playground" )
|
|
setTargetFPS( conf.fps )
|
|
|
|
while not windowShouldClose():
|
|
|
|
beginDrawing()
|
|
clearBackground( WHITE )
|
|
beginMode3D( camera )
|
|
|
|
if camera.fovy < finalPositionX:
|
|
camera.fovy = bounceInOut( count.float32, startPositionX,
|
|
finalPositionX - startPositionX, duration.float32 )
|
|
|
|
drawGrid( 10, 1.0f )
|
|
endMode3D()
|
|
|
|
var col = if isCursorOnScreen(): BLUE else: GRAY
|
|
drawText( "OH SNAP IT'S WORKING\n{count}".fmt, 10, 10, 20, col )
|
|
endDrawing()
|
|
|
|
count.inc
|
|
|
|
|
|
when defined( emscripten ):
|
|
emscripten_set_main_loop( mainLoop, 0, true );
|
|
else:
|
|
mainLoop()
|
|
|