Jump to content

New LETKControl (beta)


klepto2
 Share

Recommended Posts

Hi, here is a new Version of the LE-TKControl (binary only currently).

 

The Sample has a subfolder containing all needed assemblies (excluding regular SDK dlls).

 

Whats new:

- Framework compatibility

- Polled Input

 

What to do:

- Cleanup the code

- Fix some minor issues (update timing)

- Porting it to WPF

- Add some overloads to the current polled input functions

 

Changes:

- Namespace has changed to Klepto.Controls because i have added it to my own GameEngine. I will go back to Leadwerks Namespace as soon as it is stable enough

- Instead of 1 Render Event there are now 3 Events (Pre, Main and After) makes handling of Framework drawing easier

- Handles the Framework rendering automatically if you use rendercontext.InitFramework(useLua)

 

Download : LESDK Control.zip

 

Have Fun!

  • Upvote 1
  • Intel® Core™ i7-8550U @ 1.80 Ghz 
  • 16GB RAM 
  • INTEL UHD Graphics 620
  • Windows 10 Pro 64-Bit-Version
Link to comment
Share on other sites

Sweet, thanks for this!

 

 

Are you going to maintain both WinForm and WPF always, because I'm not a big fan of working with WPF. I'm newer to it but it just seems clumsy to work with when compared to WinForms and I'd hate for this to only work with WPF some day.

 

 

[edit]

This line doesn't seem to show the dialog for me. It just sits there doing nothing. It's strange that it doesn't error out and if I'm stepping through it it just never comes back after that. It's like it's opening the dialog but I can't visually see it.

 

if (openDlg.ShowDialog() == DialogResult.OK)

Link to comment
Share on other sites

This happens if you don't have all LE dlls in the bin/Debug or bin/Release folder. Copy the engine.dll, newton.dll and jointlibrary.dll into these folder.

 

I will maintain both, Forms and WPF. WPF is just the Forms control hostet in WPF. I also had trouble to come into WPF but once you get into it its beautyfull. OK useless for Editors which needs highperformance, but other applications are done much easier and faster with WPF.

  • Intel® Core™ i7-8550U @ 1.80 Ghz 
  • 16GB RAM 
  • INTEL UHD Graphics 620
  • Windows 10 Pro 64-Bit-Version
Link to comment
Share on other sites

It doesn't seem like MoveMouse() of the control is working in this certain case. In your example program when you click on an area, the camera rotates right away. Ideally in editors and games that doesn't happen. The clicking down usually doesn't generate a jerking movement to that position. To solve this I tried the following, but when stepping through after calling MoveMouse() and checking the MouseX() and MouseY() of the control they were left unchanged.

 

if(RenderContext.MouseHit(MouseButtons.Left) == 1)
           {
               //Leadwerks.Mouse.Hide();
               RenderContext.MoveMouse(100, 100);
           }

           if (RenderContext.MouseDown(MouseButtons.Left))
           {               
               //Camera look
               mx = Maths.Curve(RenderContext.MouseX() - 100, mx, 1);
               my = Maths.Curve(RenderContext.MouseY() - 100, my, 1);

               RenderContext.MoveMouse(100, 100);

               camrotation.X = camrotation.X + my / 5.0f;
               camrotation.Y = camrotation.Y - mx / 5.0f;

               Leadwerks.Framework.Layers.Main.Camera.Rotation = camrotation;
           }

 

I just subtract from 100 instead of using 1/2 the width and height for 2 reasons. One, is to avoid the division when it's not really required, and the other is to avoid rounding issues when the control isn't an even number. Either way, this code results in the camera going insane and spinning. Any ideas?

 

[edit]

 

The mouse always seems to go to the middle on left mouse button pressed down too, which doesn't really make much sense given the code above. It should be going to 100,100 (which isn't the middle of my control). It's almost like somewhere it's hardcoded to move the mouse back to the center of the control, so when I move it to 100, 100 it's always calculating the difference between the control center and 100,100 (what I move it to) and that's why it's moving like crazy. If that's the case, it doesn't really seem like that should be happening.

Link to comment
Share on other sites

ups, you're right. the MouseMove indead is hardcoded to the middle of the screen. I knew why i called it beta ;)

Well, ok, it was one of the last commands i added so i was a bit unconcentrated.

 

Fixed Control assembly: Klepto.Controls.dll

  • Intel® Core™ i7-8550U @ 1.80 Ghz 
  • 16GB RAM 
  • INTEL UHD Graphics 620
  • Windows 10 Pro 64-Bit-Version
Link to comment
Share on other sites

I probably should have said one other minor thing, but MouseHit returns and int and MouseDown/Up returns a bool. Not a big deal now, but whenever you put another fix it, it would be cool if MouseHit could also return bool.

 

Also, Leadwerks.Mouse.Hide() doesn't seem to hide the cursor. That might be something for the Leadwerks.dll though.

 

[EDIT]

nevermind on the mouse hide. It's working.

 

Thanks for the fast turn around on that!

Link to comment
Share on other sites

One thing I always disliked was that LE didn't have a MouseUp method that fired just once after coming from a MouseDown. I've always had to do this myself, which gets old after doing it a hundred times. Do you think it might be something you could put in the control? Maybe it could be called MouseRelease() or something to make more sense.

Link to comment
Share on other sites

There still seems to be a problem somewhere. After calling MoveMouse(50, 50) visually the mouse seems to be moving, but calling MouseX() & MouseY() still give the old mouse coords. Is something not updating until the next frame or something?

 

origx = RenderContext.MouseX();
origy = RenderContext.MouseY();

RenderContext.MoveMouse(50, 50);

// if I check RenderContext.MouseX() or MouseY() they aren't 50, 50, but are what they were before the move

Link to comment
Share on other sites

Ok, here we go last update for today ;)

 

changes:

MouseX/ MouseY will update now after mousemove

experimental MouseRelease

 

the behaviour of MouseHit and MouseDown is different. Whereas MouseDown just checks if a button is pressed, Mousehit returns the number of clicks since the last time the given button was clicked.

Klepto.Controls.dll

  • Intel® Core™ i7-8550U @ 1.80 Ghz 
  • 16GB RAM 
  • INTEL UHD Graphics 620
  • Windows 10 Pro 64-Bit-Version
Link to comment
Share on other sites

MouseZ() in the RenderContext doesn't seem to be working correctly. I did a small test with LE in C where I just printed out the value of MouseZ() to screen and it just keeps accumulating. If I do the same thing in the RenderContext it seems to kind of loop back around after around 450ish.

 

Sorry for finding so many bugs, but these are all the features I need :)

Link to comment
Share on other sites

Question about the FPS. With nothing loaded it says 32, and when I have a light, 1 model, and a cube I get about the same. Is that FPS correct? If it's not, do you know how much of a FPS hit the control takes when compared to running the LE window in C#?

 

I'm curious because .NET controls can be put on top of your control to give a quick and dirty UI, and when docked to the .NET window resizing to anysize is easy as pie, so would be cool to use that for a game even. A simple game anyway.

Link to comment
Share on other sites

Thought I'd post code that will give what most editors do in terms of moving around. Once the MouseZ() issue is resolved I'll add that also.

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Leadwerks;

namespace EditorTest
{
   public partial class Form1 : Form
   {
       private readonly Vector3 camrotation = new Vector3();
       private float move;
       private float mx;
       private float my;
       private int mz;
       private int origx;
       private int origy;
       private float strafe;
       private bool rightMouseDown = false;

       private Mesh xAxis;

       public Form1()
       {
           InitializeComponent();
       }

       // it all starts here
       private void RenderContext_Init(object sender, EventArgs e)
       {
           RenderContext.InitFramework(false);
           RenderContext.RefreshRate = 60;
           RenderContext.Start();

           Leadwerks.Framework.StatisticMode = StatisticMode.Detailed;

           Leadwerks.Framework.Layers.Main.Camera.Position = new Vector3(0, 0, -4);
       }

       private void RenderContext_Render(object sender, EventArgs e)
       {

       }

       private void RenderContext_AfterRender(object sender, EventArgs e)
       {
           Drawing.Blend = BlendType.Alpha;
           Drawing.Text(mx + ";" + my, 0, 250);
           Drawing.Text(RenderContext.MouseZ().ToString(), 0, 300);
           Drawing.Blend = BlendType.None;
       }

       private void RenderContext_PreRender(object sender, EventArgs e)
       {
           if(RenderContext.MouseHit(MouseButtons.Right) == 1)
           {
               // save off the orignal location of the mouse so we can put it back here when done
               origx = RenderContext.MouseX();
               origy = RenderContext.MouseY();

               // bug: seems the mouse is getting visible after the first frame so we need to do this here and in MouseDown below
               Leadwerks.Mouse.Hide();
               Cursor.Hide();

               RenderContext.MoveMouse(50, 50);
           }

           if (RenderContext.MouseDown(MouseButtons.Right))
           {
               Leadwerks.Mouse.Hide();
               Cursor.Hide();

               // camera look
               mx = Maths.Curve(RenderContext.MouseX() - 50, mx, 1);
               my = Maths.Curve(RenderContext.MouseY() - 50, my, 1);

               // move the camera back to our preset location for camera movement
               RenderContext.MoveMouse(50, 50);

               // add the delta to the rotation
               camrotation.X = camrotation.X + my / 5.0f;
               camrotation.Y = camrotation.Y - mx / 5.0f;

               Leadwerks.Framework.Layers.Main.Camera.Rotation = camrotation;

               rightMouseDown = true;
           }
           else if ((!RenderContext.MouseDown(MouseButtons.Right)) && rightMouseDown)
           {
               rightMouseDown = false;

               // move the mouse back to where it was
               RenderContext.MoveMouse(origx, origy);

               Leadwerks.Mouse.Show();
               Cursor.Show();
           }

           move =
               Maths.Curve(
                   (float)
                   (Convert.ToDouble(RenderContext.KeyDown(Key.W)) - Convert.ToDouble(RenderContext.KeyDown(Key.S))),
                   move, 1);

           //int scroll = RenderContext.MouseZ() - mz;
           //mz = RenderContext.MouseZ();
           //move += scroll;

           strafe =
               Maths.Curve(
                   (float)
                   (Convert.ToDouble(RenderContext.KeyDown(Key.D)) - Convert.ToDouble(RenderContext.KeyDown(Key.A))),
                   strafe, 1);

           Leadwerks.Framework.Layers.Main.Camera.Move(new Vector3(strafe / 10.0f, 0, move / 10.0f));
       }

       private void Form1_FormClosed(object sender, FormClosedEventArgs e)
       {
           Engine.Terminate();
       }

       private void Form1_Load(object sender, EventArgs e)
       {

       }
   }
}

Link to comment
Share on other sites

Is the code for this control available? I think it was at one point, but thought you guys closed the svn to the public. I would be interested in seeing it as I'm trying to figure out how the framework is used within the 3 render events. I'm trying to make a world that is rendered on top of everything without depth and having issues. I can do it without the framework with the normal C library, but can't seem to get it working in C# with this control which I assume uses the framework.

Link to comment
Share on other sites

Rick, here is a new version:Klepto.Controls.dll

 

Changes:

- Added an AfterFrameworkRender eventhandler, please test if this helps and works

- Fixed MouseZ bug.

 

btw, its no problem that you find bugs :mellow: thats why i call this beta.

 

PS: the FPS thing is something i need to work on. Somehow the TKcontrol limits the rendering speed and the timer is a also a bit weird.

Currently I'm experimenting with BackgroundWorkers which should work better.

 

[Edit]

Changes:

- Changed Timing from timer to backgroundworker. RefreshRate works now correct, set RefreshRate to -1 for fullspeed.

  • Intel® Core™ i7-8550U @ 1.80 Ghz 
  • 16GB RAM 
  • INTEL UHD Graphics 620
  • Windows 10 Pro 64-Bit-Version
Link to comment
Share on other sites

Cool, thanks Klepto. The MouseZ() works great. I'm still not able to get the always on top world though. Not sure if I'm not doing something correctly. Here is the code I'm using.

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Leadwerks;

namespace EditorTest
{
   public partial class Form1 : Form
   {
       private readonly Vector3 camrotation = new Vector3();
       private float move;
       private float mx;
       private float my;
       private int mz;
       private int origx;
       private int origy;
       private float strafe;
       private bool rightMouseDown = false;

       private World topWorld;
       private Camera topCamera;

       private Mesh xAxis;

       public Form1()
       {
           InitializeComponent();
       }

       // it all starts here
       private void RenderContext_Init(object sender, EventArgs e)
       {
           RenderContext.InitFramework(false);
           RenderContext.RefreshRate = 60;
           RenderContext.Start();

           Leadwerks.Framework.StatisticMode = StatisticMode.Detailed;

           Leadwerks.Framework.Layers.Main.Camera.Position = new Vector3(0, 0, -4);

           topWorld = new World();
           Leadwerks.World.Current = topWorld;
           topCamera = new Camera();
           topCamera.ClearMode = CameraClearMode.Depth;

           // load model
           xAxis = Mesh.Load("abstract::x_red.gmf");
           xAxis.Position = new Vector3(0, 0, 0);

           Leadwerks.World.Current = Leadwerks.Framework.Layers.Main.World;

           Light light = Light.CreateDirectional();
           light.Position = new Vector3(0, 1, 0);

           Mesh cube = Mesh.CreateCube();
           cube.Position = new Vector3(0, 0, 0);
       }

       private void RenderContext_Render(object sender, EventArgs e)
       {

       }

       private void RenderContext_AfterRender(object sender, EventArgs e)
       {
           Drawing.Blend = BlendType.Alpha;
           Drawing.Text(mx + ";" + my, 0, 250);
           Drawing.Text(RenderContext.MouseZ().ToString(), 0, 300);
           Drawing.Blend = BlendType.None;
       }

       Leadwerks.Buffer gbuffer;
       private void RenderContext_PreRender(object sender, EventArgs e)
       {
           gbuffer = Leadwerks.Buffer.Current;

           if(RenderContext.MouseHit(MouseButtons.Right) == 1)
           {
               // save off the orignal location of the mouse so we can put it back here when done
               origx = RenderContext.MouseX();
               origy = RenderContext.MouseY();

               // bug: seems the mouse is getting visible after the first frame so we need to do this here and in MouseDown below
               Leadwerks.Mouse.Hide();
               Cursor.Hide();

               RenderContext.MoveMouse(50, 50);
           }

           if (RenderContext.MouseDown(MouseButtons.Right))
           {
               Leadwerks.Mouse.Hide();
               Cursor.Hide();

               // camera look
               mx = Maths.Curve(RenderContext.MouseX() - 50, mx, 1);
               my = Maths.Curve(RenderContext.MouseY() - 50, my, 1);

               // move the camera back to our preset location for camera movement
               RenderContext.MoveMouse(50, 50);

               // add the delta to the rotation
               camrotation.X = camrotation.X + my / 5.0f;
               camrotation.Y = camrotation.Y - mx / 5.0f;

               Leadwerks.Framework.Layers.Main.Camera.Rotation = camrotation;

               rightMouseDown = true;
           }
           else if ((!RenderContext.MouseDown(MouseButtons.Right)) && rightMouseDown)
           {
               rightMouseDown = false;

               // move the mouse back to where it was
               RenderContext.MoveMouse(origx, origy);

               Leadwerks.Mouse.Show();
               Cursor.Show();
           }

           move =
               Maths.Curve(
                   (float)
                   (Convert.ToDouble(RenderContext.KeyDown(Key.W)) - Convert.ToDouble(RenderContext.KeyDown(Key.S))),
                   move, 1);

           int scroll = RenderContext.MouseZ() - mz;
           mz = RenderContext.MouseZ();
           move += scroll;

           strafe =
               Maths.Curve(
                   (float)
                   (Convert.ToDouble(RenderContext.KeyDown(Key.D)) - Convert.ToDouble(RenderContext.KeyDown(Key.A))),
                   strafe, 1);

           Leadwerks.Framework.Layers.Main.Camera.Move(new Vector3(strafe / 10.0f, 0, move / 10.0f));
       }

       private void Form1_FormClosed(object sender, FormClosedEventArgs e)
       {
           Engine.Terminate();
       }

       private void Form1_Load(object sender, EventArgs e)
       {

       }

       private void RenderContext_AfterFrameworkRender(object sender, EventArgs e)
       {
           Leadwerks.World.Current = topWorld;
           topCamera.Matrix = Leadwerks.Framework.Layers.Main.Camera.Matrix;
           Leadwerks.Buffer.Clear(BufferType.Depth);
           Leadwerks.World.Render();
           Leadwerks.World.Current = Framework.Layers.Main.World;
       }
   }
}

Link to comment
Share on other sites

  • 2 weeks later...

Hm... I tried the sample project but obviously the Render, PreRender, AfterRender, etc. events are only fired once at startup. I also just see a white background with a red border and a red cross in the middle oO

I copied all dlls to where they should be.

 

Any ideas?

 

E: Okay, the output window says: (translated to english)

An exception (first chance) of type "System.DllNotFoundException" occurred in OpenTK.dll.

An exception (first chance) of type "System.TypeInitializationException" occurred in OpenTK.dll.

An exception (first chance) of type "System.DllNotFoundException" occurred in OpenTK.dll.

An exception (first chance) of type "System.AccessViolationException" occurred in Leadwerks.dll.

An exception (first chance) of type "System.NullReferenceException" occurred in LeadwerksControlSample.exe.

 

I don't get why it says DllNotFound. Where am I supposed to put the dlls? I tried the bin/Debug and bin/Release folders, the SDK dir, the project dir and the solution dir but none works.

Link to comment
Share on other sites

Hi

 

I hope i can help you.

 

1. You need to download the package from the first post as it includes all needed references like OpenTK, Leadwerks.dll etc.

2. Download tha latest version of the Control here : http://leadwerks.com/werkspace/index.php?/topic/2429-new-letkcontrol-beta/page__view__findpost__p__22982

3. Make sure you have set all References set correctly: you need a Reference to Leadwerks.dll and a reference to the 3 delivered OpenTK dlls.

 

If you have done this, you should be able to run the sample.

  • Intel® Core™ i7-8550U @ 1.80 Ghz 
  • 16GB RAM 
  • INTEL UHD Graphics 620
  • Windows 10 Pro 64-Bit-Version
Link to comment
Share on other sites

Sorry for triple-posting, but there seems to be something wrong with Key.LeftShift. Neither RenderContext.KeyDown( Key.LeftShift ) nor RenderContext.KeyHit( Key.LeftShift ) do ever return true... any other Keycode I tried did.

 

Edit: Okay, all the left and right ctrl, shift and alt-keys don't work for me. Could be something with the german keyboard but I'm not sure.

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...