I was working on a port of darkGDK to lua, but I've run into an extremely odd problem. For those of you who don't know how lua works in calling C++ functions, you basically just tell lua to call the function via a few registering commands in which you'll specify what the arguments translate to and what are the return values and such. But anyways, on to the problem.
I converted the terrain example to lua, with one problem. The camera is seriously messed up. Though it VISUALLY looks like you're facing a certain direction the camera will not MOVE in the direction you are looking! It will only move in 4 directions, the closest one to where you're actually looking. I can't even imagine what could create this problem. Here is the err, lua code.
--init.lua is the only lua file actually called from the LuaGDK. use AddContent(<filename>) to include more files here.
AddContent("util.lua") --some extra helpful functions
g_fSpeed = 0.1 -- speed at which camera moves
g_fTurn = 0.03 -- turn speed for mouse look
g_fOldCamAngleX = 0.0 -- to store original x angle
g_fOldCamAngleY = 0.0 -- to store original y angle
g_fCameraAngleX = 0.0 -- to store new x angle
g_fCameraAngleY = 0.0 -- to store new y angle
function Initialize()
-- initial application set up
dbSyncOn () -- turn sync on
dbSyncRate ( 60 ) -- set sync rate to 60
dbBackdropOff () -- switch backdrop off - no need to clear screen
dbSetCameraRange( 0.5, 30000 ) -- set the camera range
dbHideMouse() --I added this, it was annoying with the mouse visible.
-- load images for the terrain
dbLoadImage ( "media\\media\\texture.jpg", 1 ) -- diffuse texture
dbLoadImage ( "media\\media\\detail.jpg", 2 ) -- detail texture
-- create the terrain
dbSetupTerrain () -- set up terrain library
dbMakeObjectTerrain ( 1 ) -- make a new terrain
dbSetTerrainHeightmap ( 1, "media\\media\\map.bmp" ) -- set the terrain height map
dbSetTerrainScale ( 1, 3, 0.6, 3 ) -- set the scale
dbSetTerrainSplit ( 1, 16 ) -- set the split value
dbSetTerrainTiling ( 1, 4 ) -- set the detail tiling
dbSetTerrainLight ( 1, 1.0, -0.25, 0.0, 1, 1, 0.78, 0.5 ) -- set the light
dbSetTerrainTexture ( 1, 1, 2 ) -- set the textures
dbBuildTerrain ( 1 ) -- build the terrain
-- create our skybox
dbLoadObject ( "media\\media\\skybox2.x", 200 ) -- load the skybox model
dbSetObjectLight ( 200, 0 ) -- turn lighting off
dbSetObjectTexture ( 200, 3, 1 ) -- set texture properties
dbPositionObject ( 200, 1000, 2000, 4000 ) -- position the skybox
dbScaleObject ( 200, 30000, 30000, 30000 ) -- and finally scale
-- set starting camera position
dbPositionCamera( 390, 23, 100 )
end
function Think()
-- loop round until escape key is pressed
if ( dbEscapeKey() ) then
SetAppBreak(true)
end
--handle user input
userInput()
-- update the terrain and screen
dbUpdateTerrain()
dbSync()
end
function ShutDown() end --not used
function userInput()
dbControlCameraUsingArrowKeys( 0, g_fSpeed, g_fTurn )
g_fOldCamAngleY = g_fCameraAngleY
g_fOldCamAngleX = g_fCameraAngleX
g_fCameraAngleY = dbWrapValue( g_fCameraAngleY + (dbMouseMoveX() * 0.4) )
g_fCameraAngleX = dbWrapValue( g_fCameraAngleX + (dbMouseMoveY() * 0.4) )
dbYRotateCamera( dbCurveAngle( g_fCameraAngleY, g_fOldCamAngleY, 24 ) )
dbXRotateCamera( dbCurveAngle( g_fCameraAngleX, g_fOldCamAngleX, 24 ) )
local szKey = dbInKey()
if ( szKey == "+" ) then
if ( g_fSpeed < 1000 ) then
g_fSpeed = g_fSpeed + 0.01
end
end
if ( szKey == "-" ) then
if ( g_fSpeed > 0.02 ) then
g_fSpeed = g_fSpeed - 0.01
end
end
local fHeight = dbGetTerrainGroundHeight( 1, dbCameraPositionX(), dbCameraPositionZ() )
dbPositionCamera( dbCameraPositionX(), fHeight + 5.0, dbCameraPositionZ() )
end
It's pretty much identical to the original code, except in lua syntax (Think is the main loop, and Initialize is anything before that.) I took out the show FPS function because I hadn't added the FPS function in yet, I doubt that is what's causing this though.
Please excuse wall of text.