Jump to content

le net starter


cassius
 Share

Recommended Posts

I normaly use Blitzmax, but thought I would give le net a try. I know the basics of c#.

Can someone point me to a scene loader example?

 

if not I will have to try to translate my bmax code to le net.

amd quad core 4 ghz / geforce 660 ti 2gb / win 10

Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++

Link to comment
Share on other sites

//	====================================================================
//	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();
           }
       }
   }
}

AV MX Linux

Link to comment
Share on other sites

Or, using Leadwerks .NET:

 

using Leadwerks;

class LoadAScene
{
   static void Main(string[] args)
   {
       try
       {
           Engine.Initialize(800, 600);
           Window.Caption = "LoadAScene";
           FileSystem.AbstractPath = @"D:\GameDevel";
           Framework.Initialize();

           Scene scene = Scene.Load("abstract::tunnels.sbx");

           Framework.Camera.Position = Vector3.Parse(scene.Keys["cameraposition"]);
           Framework.Camera.Rotation = Vector3.Parse(scene.Keys["camerarotation"]);

           while (!Keyboard.IsKeyHit(Key.Escape) && !Window.HasRequestedClose)
           {
               if (Window.HasFocus)
               {
                   Framework.Update();
                   Framework.Render();
                   Graphics.Flip();
               }
           }
       }
       catch (LeadwerksException lex)
       {
           Debug.Alert(lex.Message);
       }
       finally
       {
           Framework.Dispose();
           Engine.Dispose();
       }
   }
}

Link to comment
Share on other sites

Roland.

I get an error message on the line below.

The only change I made was to load in my own level instead of tunnels

It was somthing about protected code being corrupt.

 

TVec3 campos = StringToVec3(LE.GetEntityKey(scene, "cameraposition"));

 

What is the best way to replace the spinning cube listing with your code?

 

 

Thanks lazlo. Will your version always be maitained?

amd quad core 4 ghz / geforce 660 ti 2gb / win 10

Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++

Link to comment
Share on other sites

Roland.

I get an error message on the line below.

The only change I made was to load in my own level instead of tunnels

It was somthing about protected code being corrupt.

 

TVec3 campos = StringToVec3(LE.GetEntityKey(scene, "cameraposition"));

 

What is the best way to replace the spinning cube listing with your code?

 

 

Thanks lazlo. Will your version always be maitained?

Hard to say what your error is without having the SBX file you are using.

Here is the code I showed including the Visual Studio project. Its working fine here.

I assume you are using latest SDK 2.45

 

Unrar the rar file in your SDK directory. It will created a folder Examples.

Open the Examples\LoadAScene\LoadAScene.sln in Visual Studio and see that tunnels.sbx is loaded OK.

Then change to you scene file and see what happens.

AV MX Linux

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...