rem Soft3D, example 1.
rem By JSM.

import "Soft3D.lib"
import "Speed.lib"
import "Keycodes.lib"

set redraw off
set window 32, 32, 640, 480

rem init with 45 degree field of view and rendering z in the range
rem [0.1 .. 64.0]. the z range tells at what distances something
rem should no longer be rendered.
proc S3D_Init 45.0, 0.1, 64.0

rem load mesh. a mesh fill the same function as an image. you can
rem use the same mesh for any number of objects.
faceMesh = S3D_LoadMesh("assets/m300.off")

yaw# = 180.0
pitch# = 0.0
roll# = 0.0

rem create an object using the mesh.
obj = S3D_CreateObj(faceMesh)
rem do not mind this call right now. the mesh does not have its
rem center where it should be, so we just change its pivot. the
rem numbers were taken from a text file describing the mesh.
proc S3D_SetObjPivot obj, 0.334258, 0.373673, 0.669599
rem set position as x, y and z.
proc S3D_SetObjPosition obj, 0.0, 0.0, 1.5
rem set orientation with the yaw, pitch and roll system.
proc S3D_SetObjOrientation obj, yaw, pitch, roll
rem set shader that the object should use. light mapping will come in
rem another example, very sweet in NaaLaa.
proc S3D_SetObjShader obj, S3D_FLAT

do
	rem switch between the three different shader types using keys
	rem 1, 2 and 3.
	if keydown("1", true) then proc S3D_SetObjShader obj, S3D_NONE
	if keydown("2", true) then proc S3D_SetObjShader obj, S3D_FLAT
	if keydown("3", true) then proc S3D_SetObjShader obj, S3D_SMOOTH

	rem change yaw, rotation around y axis, with left and right.
	if keydown(VK_LEFT) then yaw = max#(yaw - 2.0, 90.0)
	if keydown(VK_RIGHT) then yaw = min#(yaw + 2.0, 270.0)

	rem change pitch, rotation around x axis, with up and down
	if keydown(VK_UP) then pitch = max#(pitch - 2.0, -45.0)
	if keydown(VK_DOWN) then pitch = min#(pitch + 2.0, 45.0) 

	rem update object with possibly new orientation.
	proc S3D_SetObjOrientation obj, yaw, pitch, roll

	rem clear screen.
	set color 128, 128, 200
	cls

	rem render all objects, just one in this example.
	proc S3D_Render

	rem instructions.
	set color 255, 255, 255
	set caret 0, 0
	wln "1  - no shading"
	wln "2  - flat shading"
	wln "3  - smooth shading"
	wln
	wln "Change yaw with left and righ keys"
	wln "Change pitch with up and down keys"

	redraw

	proc SPD_HoldFrame 60
until keydown(27, true)
