// ====================================================================
// This file was generated by LEBuilder
// http://leadwerks.com/werkspace
// ====================================================================
using System;
using LeadwerksEngine;
using System.Globalization;
namespace LoadAScene
{
class LoadAScene
{
private const int ScreenWidth = 800;
private const int ScreenHeight = 600;
private const string MediaDir = "D:/GameDevel";
private const string AppTitle = "LoadAScene";
/// <summary>
/// Convert string to a TVec3.
/// Values should be separated by SPACE, TAB or ,
/// </summary>
/// <param name="s">Sting to be converted</param>
/// <returns>Resulting TVec3</returns>
static TVec3 StringToVec3(string s)
{
char[] delimiterChars = { ',', ' ', '\t' };
string[] values = s.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries);
IFormatProvider provider = CultureInfo.CreateSpecificCulture("en-US");
NumberStyles style = NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands | NumberStyles.Float;
return new TVec3( float.Parse(values[0],style,provider),
float.Parse(values[1],style, provider),
float.Parse(values[2],style, provider));
}
static void UpdateCallback(TEntity ent)
{
LE.TurnEntity(ent, new TVec3(LE.AppSpeed() * 0.5f));
}
static void ErrOut( string message )
{
Console.WriteLine( message );
}
static void Main(string[] args)
{
try
{
// Initialize
LE.Initialize();
LE.SetAppTitle(AppTitle);
LE.RegisterAbstractPath(MediaDir);
// Set graphics mode
if( LE.Graphics(ScreenWidth,ScreenHeight) == 0 )
{
ErrOut( "Failed to set graphics mode." );
return;
}
// Create framework object and set it to a global object so other scripts can access it
TFramework fw = LE.CreateFramework();
if( !fw.IsValid )
{
ErrOut( "Failed to initialize engine." );
return;
}
// Set Lua framework object
LE.SetGlobalObject( "fw", fw.Handle );
// Set Lua framework variable
IntPtr lua = LE.GetLuaState();
LE.lua_pushobject( lua, fw.Handle );
LE.lua_setglobal( lua, "fw" );
LE.lua_pop( lua, 1 );
// Load Scene
TEntity scene = LE.LoadScene("abstract::tunnels.sbx");
TVec3 campos = StringToVec3(LE.GetEntityKey(scene, "cameraposition"));
TVec3 camrot = StringToVec3(LE.GetEntityKey(scene, "camerarotation"));
// Position camera as in scene file
TCamera camera = LE.GetLayerCamera( LE.GetFrameworkLayer(0) );
LE.PositionEntity( camera, campos );
LE.RotateEntity(camera, camrot);
// Until user hits Escape
while( !LE.KeyHit() && !LE.AppTerminate() )
{
if( !LE.AppSuspended() )
{
LE.UpdateFramework();
LE.RenderFramework();
LE.Flip( 0 );
}
}
}
// Catch Exceptions
catch( Exception e )
{
Console.WriteLine( e.Message ) ;
}
// Terminate
finally
{
LE.Terminate();
}
}
}
}