From 9e2d449d926c6bd15d8a37942573444f376fc2ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Madar=C3=A1sz?= Date: Thu, 10 Aug 2023 21:52:43 +0200 Subject: [PATCH] lua stuff --- MAKE.bat | 10 ++++++++ demos/lua/99-draw.lua | 56 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 demos/lua/99-draw.lua diff --git a/MAKE.bat b/MAKE.bat index c671ed1..27841f1 100644 --- a/MAKE.bat +++ b/MAKE.bat @@ -260,6 +260,8 @@ if "%1"=="help" ( echo %0 [docs] ; generate tools/docs/docs.html file echo %0 [cook] ; cook .zipfiles with tools/cook.ini cookbook echo %0 [sync] ; sync repo to latest + echo %0 [fwk] ; prepare files for fwk PR + echo %0 [lua] ; execute lua script with v4k echo %0 [pull] ; pull changes from 'latest' upstream echo %0 [git] ; prepare for commit echo %0 [push] ; prepare for commit, stage changes and commit them @@ -316,6 +318,14 @@ if "%1"=="bind" ( exit /b ) + +if "%1"=="lua" ( + pushd engine\bind + luajit "..\..\%2" + popd + exit /b +) + rem generate documentation if "%1"=="docs" ( rem set symbols... diff --git a/demos/lua/99-draw.lua b/demos/lua/99-draw.lua new file mode 100644 index 0000000..91f7fde --- /dev/null +++ b/demos/lua/99-draw.lua @@ -0,0 +1,56 @@ +-- this will run on vanilla luajit.exe, provided that v4k.dll and this file are all present in same folder + +local v4k=require('v4k') + +-- specify location of cookbook +v4k.cook_config("../../tools/cook.ini"); + +-- create 75% sized + MSAAx2 anti-aliased window +v4k.window_create(75.0, v4k.WINDOW_MSAA2) + +-- set window title +v4k.window_title("hello luajit") + +-- config girl +local girl = v4k.model('kgirl/kgirls01.fbx', 0) +local girl_frame = 0 +local girl_pivot = v4k.mat44() +v4k.rotationq44(girl_pivot, v4k.eulerq(v4k.vec3(0,0,0))) +v4k.scale44(girl_pivot, 2,2,2) + +-- config & play music +local music = v4k.audio_stream('larry.mid') -- 'wrath_of_the_djinn.xm' +v4k.audio_play(music, 0); + +-- config camera +local cam = v4k.camera() + +-- main loop +while v4k.window_swap() == 1 do + -- fps camera + local grabbed = v4k.input(v4k.MOUSE_L) == 1 or v4k.input(v4k.MOUSE_R) == 1 + v4k.window_cursor( v4k.ui_active() == 1 or v4k.ui_hover() == 1 and 1 or (not grabbed) ) + if( v4k.window_has_cursor() ~= 1 ) then + local wasdec3 = v4k.vec3(v4k.input(v4k.KEY_D)-v4k.input(v4k.KEY_A),v4k.input(v4k.KEY_E)-(v4k.input(v4k.KEY_C)),v4k.input(v4k.KEY_W)-v4k.input(v4k.KEY_S)) + local look2 = v4k.scale2(v4k.vec2(v4k.input_diff(v4k.MOUSE_X), -v4k.input_diff(v4k.MOUSE_Y)), 0.2) + local move3 = v4k.scale3(wasdec3, cam.speed) + v4k.camera_move(cam, wasdec3.x,wasdec3.y,wasdec3.z) + v4k.camera_fps(cam, look2.x,look2.y) + end + + -- draw grid/axis + v4k.ddraw_grid(0) + v4k.ddraw_flush() + + -- animate girl + local delta = v4k.window_delta() * 30 -- 30fps anim + girl_frame = v4k.model_animate(girl, girl_frame + delta) + + -- draw girl + v4k.model_render(girl, cam.proj, cam.view, girl_pivot, 0) + + -- showcase ui + if v4k.ui_panel("luajit", 0) == 1 then + v4k.ui_panel_end() + end +end