klepto2 Posted June 25, 2010 Share Posted June 25, 2010 After revisiting the TKControl again I wasn't able to find a big bug or anything else i have made wrong (ok the refreshrate calculation is buggy) but then i have tried to get the Framework to work with the LETKControl and : Success!!! As said, there is nothing wrong with the Control itself, but something small is needed to get the Control working with the Framework. Here is the code: 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 Leadwerks_FormsFramewerk_Test { public partial class Form1 : Form { private Leadwerks.Buffer buffer; public Form1() { InitializeComponent(); } private void RenderContext_Init(object sender, EventArgs e) { Leadwerks.FileSystem.AbstractPath = @"D:\LESDK232r5"; //Create a render buffer buffer = new Leadwerks.Buffer(RenderContext.Width, RenderContext.Height, (int)(BufferType.Color | BufferType.Depth | BufferType.Normal)); RenderContext.Start(); Leadwerks.Framework.Initialize(true); Leadwerks.Framework.StatisticMode = StatisticMode.Detailed; Leadwerks.Scene scene = Scene.Load("abstract::Test.sbx"); Framework.Layers.Main.Camera.Position = new Vector3(4, 3, -4); Framework.Layers.Main.Camera.Point(new Pivot()); } private void RenderContext_Redraw(object sender, EventArgs e) { //Set the created renderbuffer as current buffer and let LE render to it Leadwerks.Buffer.Current = buffer;//Leadwerks.Buffer.Back; Leadwerks.Framework.Update(); Leadwerks.Framework.Render(); //Set the buffer of the Control as current and draw the flipped image of the 'framework' buffer Leadwerks.Buffer.Current = RenderContext.Buffer; Leadwerks.Drawing.Image(buffer.GetColorTexture(0), 0, RenderContext.Buffer.Height, RenderContext.Buffer.Width, -RenderContext.Buffer.Height); } private void RenderContext_Resize(object sender, EventArgs e) { buffer = new Leadwerks.Buffer(RenderContext.Width, RenderContext.Height, (int)(BufferType.Color | BufferType.Depth | BufferType.Normal)); } private void RenderContext_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Q) Framework.Layers.Main.Camera.Move(new Vector3(0, 1 * Leadwerks.Core.AppSpeed(), 0)); if (e.KeyCode == Keys.Y) Framework.Layers.Main.Camera.Move(new Vector3(0, -1 * Leadwerks.Core.AppSpeed(), 0)); } } } I hope this will help you. I will now try to integrate this a bit more into the control so that you won't need to handle this by your own. Quote Windows 10 Pro 64-Bit-Version NVIDIA Geforce 1080 TI Link to comment Share on other sites More sharing options...
Rick Posted June 25, 2010 Share Posted June 25, 2010 Is there any way to just get this control pre-built? Quote Link to comment Share on other sites More sharing options...
klepto2 Posted June 25, 2010 Author Share Posted June 25, 2010 Its exactly the same control which is contained in the SVN Version. So you don't need a prebuilt one. Quote Windows 10 Pro 64-Bit-Version NVIDIA Geforce 1080 TI Link to comment Share on other sites More sharing options...
Rick Posted June 25, 2010 Share Posted June 25, 2010 ok. I'll try again. The last time I had a black square over the control for some reason. Was just thinking it would be nice if the control was distributed more like a final product. Quote Link to comment Share on other sites More sharing options...
Guest Red Ocktober Posted June 25, 2010 Share Posted June 25, 2010 that's pretty impressive Klepto... the control should work in any dotNET laguage, right? --Mike Quote Link to comment Share on other sites More sharing options...
klepto2 Posted June 25, 2010 Author Share Posted June 25, 2010 Yes it should. Well i havn't tried it yet, but others already have used VB.Net with this control. I'm also working on a WPF Control. But this is a bit more difficult as WPF uses DirectX natively and i need to wrap the Forms Control to a WPF control. Quote Windows 10 Pro 64-Bit-Version NVIDIA Geforce 1080 TI Link to comment Share on other sites More sharing options...
Guest Red Ocktober Posted June 25, 2010 Share Posted June 25, 2010 coool... you've opened up a lot of possibilities for the dotNET guys... and given the Blitz and c++ guys a reason to take a look at C# and VB... --Mike Quote Link to comment Share on other sites More sharing options...
Rick Posted June 25, 2010 Share Posted June 25, 2010 There really is a million different reasons to switch to .NET. Having access to the .NET framework just provides SOOOO much functionality. The down sides would be speed (although probably nothing to major), and cross platform. It can work on Mac and Linux with Mono, but I think most of the portable platforms don't really support it from what I know. Namely iPhone, Andriod. Quote Link to comment Share on other sites More sharing options...
Guest Red Ocktober Posted June 25, 2010 Share Posted June 25, 2010 i'm a lil familiar with dotNET Rick... you don't need to sell me on it... i used to work for a firm and we used vb and c# a lot... like everything else, dotNET has its advantages and disadvantages... as far as mono goes... what do you think your chances are of porting Leadwerks over to run under the current stable release of mono... and have that execute on a macintosh... --Mike Quote Link to comment Share on other sites More sharing options...
Rick Posted June 26, 2010 Share Posted June 26, 2010 So getting an error. The first event fired is Resize(). On the one line in there that creates a buffer I get the following error. "A first chance exception of type 'System.AccessViolationException' occured in Leadwerks.dll" Wouldn't Graphics() need to be called before creating buffers? Quote Link to comment Share on other sites More sharing options...
klepto2 Posted June 26, 2010 Author Share Posted June 26, 2010 Are you using the latest R5 dll? Graphics doesn't need to be called, as it would create an own gfxcontext which we don't want. Quote Windows 10 Pro 64-Bit-Version NVIDIA Geforce 1080 TI Link to comment Share on other sites More sharing options...
Rick Posted June 26, 2010 Share Posted June 26, 2010 The Leadwerks.dll I'm using is the one from http://code.google.com/p/leadwerks-csharp/downloads/list. I think that's the R5 one. Then the engine.dll I'm using looks also to be the R5 one. So not sure what's up there. Interestingly enough, I can get it working if I comment out the resize line. So since Resize() was getting called first and was bombing I created a boolean and check it in resize and if true run that code for the buffer. I set it to true in the Init() method. This seems to work then. Interesting. Also, it seems one of the "bad" things about using the .NET key events is that it does the whole delay until repeating when holding the key. Gives a very choppy feel. I tried using the following in the Redraw() but KeyDown() never returned true. Is there a way to get a smoother keyboard input for this? if(Leadwerks.Keyboard.KeyDown(Key.Q)) Framework.Layers.Main.Camera.Move(new Vector3(0, 1 * Leadwerks.Core.AppSpeed(), 0)); if(Leadwerks.Keyboard.KeyDown(Key.Y)) Framework.Layers.Main.Camera.Move(new Vector3(0, -1 * Leadwerks.Core.AppSpeed(), 0)); Quote Link to comment Share on other sites More sharing options...
klepto2 Posted June 27, 2010 Author Share Posted June 27, 2010 Ok, the buffer thing maybe due to wrong timer initialisation. So it tries to update the buffer before LE is initialised. This should be a minor issue and easy to solve. The issue with using events is a bit more complicated. The problem is that the events and the redraw maybe asyncron. So you press the key, update the camera but the next frame will not be updated. To solve this you can do the following: private bool KeyW = false; private bool KeyS = false; private bool KeyA = false; private bool KeyD = false; private void RenderContext_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) { if (e.KeyCode == Keys.W) KeyW = true; if (e.KeyCode == Keys.S) KeyS = true; if (e.KeyCode == Keys.A) KeyA = true; if (e.KeyCode == Keys.D) KeyD = true; } private void RenderContext_KeyUp(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.W) KeyW = false; if (e.KeyCode == Keys.S) KeyS = false; if (e.KeyCode == Keys.A) KeyA = false; if (e.KeyCode == Keys.D) KeyD = false; } And in the main loop do the standard Move code move = Maths.Curve((float)(Convert.ToDouble(KeyW) - Convert.ToDouble(KeyS)), move, 20); strafe = Maths.Curve((float)(Convert.ToDouble(KeyD) - Convert.ToDouble(KeyA)), strafe, 20); Framework.Layers.Main.Camera.Move(new Vector3(strafe / 10.0f, 0, move / 10.0f)); I will add a similar eventhandling like the original LE Polledinput later. eg: LETKControl.KeyDown(Key.A) or something like this. Quote Windows 10 Pro 64-Bit-Version NVIDIA Geforce 1080 TI Link to comment Share on other sites More sharing options...
TylerH Posted June 28, 2010 Share Posted June 28, 2010 So what exactly did you change to make it work? Quote nVidia 530M Intel Core i7 - 2.3Ghz 8GB DDR3 RAM Windows 7 Ultimate (64x)----- Visual Studio 2010 Ultimate Google Chrome Creative Suite 5 FL Studio 10 Office 15 ----- Expert Professional Expert BMX Programmer ----- Link to comment Share on other sites More sharing options...
ZioRed Posted June 29, 2010 Share Posted June 29, 2010 I'd like Klepto to join the Commit Members on our official SVN and works with us and with the same code so he can personally apply updates instead of working on its own control (even if it's the same as that released on SVN)... just to work all together PS: In the download section of the project there is now also a link for a pre-build version of Leadwerks Controls which contains LETKControl (and eventually will contain new controls if any) Quote ?? FRANCESCO CROCETTI ?? http://skaredcreations.com Link to comment Share on other sites More sharing options...
L B Posted June 30, 2010 Share Posted June 30, 2010 Good stuff. You guys have come a long way I might come back to C# dev eventually, who knows. Quote Link to comment Share on other sites More sharing options...
TylerH Posted July 2, 2010 Share Posted July 2, 2010 What language is your game being written in? Quote nVidia 530M Intel Core i7 - 2.3Ghz 8GB DDR3 RAM Windows 7 Ultimate (64x)----- Visual Studio 2010 Ultimate Google Chrome Creative Suite 5 FL Studio 10 Office 15 ----- Expert Professional Expert BMX Programmer ----- Link to comment Share on other sites More sharing options...
Rick Posted July 5, 2010 Share Posted July 5, 2010 Has anyone done the basic camera look functionality within this control? I can't get it to work. Something like the FPS lua file where it lets you look around with the mouse. Since it's in a control some things like GraphicsWidth/Height() and MoveMouse() won't work. --Camera look gx=Round(GraphicsWidth()/2) gy=Round(GraphicsHeight()/2) dx=Curve((MouseX()-gx)/4.0,dx,3.0/AppSpeed()) dy=Curve((MouseY()-gy)/4.0,dy,3.0/AppSpeed()) MoveMouse(gx,gy) camerapitch=camerapitch+dy camerayaw=camerayaw-dx camerapitch=math.min(camerapitch,90) camerapitch=math.max(camerapitch,-90) fw.main.camera:SetRotationf(camerapitch,camerayaw,0,1) Quote Link to comment Share on other sites More sharing options...
ZioRed Posted July 6, 2010 Share Posted July 6, 2010 For the GraphicsWidth/Height I suspect you should use the control's GetSize() method (a better and more elegant way should be exposing the Size property of the control), since for the mouse move and hits you should try to use the control's MouseMove/Click as klepto's did for keys. Quote ?? FRANCESCO CROCETTI ?? http://skaredcreations.com Link to comment Share on other sites More sharing options...
klepto2 Posted July 21, 2010 Author Share Posted July 21, 2010 Hi, I just want to inform you that i will release a newer Version of this Control Thursday or Friday. There will be a lot of new small functions in the control which will make the handlicng of the Control much easier. A short summary: Handling of PolledInput with the same function like the raw version of Leadwerks MoveMouse, KeyDown, KeyHit, MouseHit, etc. You will be able to assign a Framework directly to the control so the buffer rendering is done internal And this is how the current Cam View code looks like in the control: if (RenderContext.MouseDown(MouseButtons.Left)) { //Camera look mx = Maths.Curve(RenderContext.MouseX() - RenderContext.Width/2, mx, 6); my = Maths.Curve(RenderContext.MouseY() - RenderContext.Height/2, my, 6); RenderContext.MoveMouse(RenderContext.Width/2, RenderContext.Height/2); // Leadwerks.Mouse.Move(RenderContext.Width / 2 , RenderContext.Height / 2 ); camrotation.X = camrotation.X + my/5.0f; camrotation.Y = camrotation.Y - mx/5.0f; Leadwerks.Framework.Layers.Main.Camera.Rotation = camrotation; } move = Maths.Curve( (float) (Convert.ToDouble(RenderContext.KeyDown(Key.W)) - Convert.ToDouble(RenderContext.KeyDown(Key.S))), move, 20); strafe = Maths.Curve( (float) (Convert.ToDouble(RenderContext.KeyDown(Key.D)) - Convert.ToDouble(RenderContext.KeyDown(Key.A))), strafe, 20); Leadwerks.Framework.Layers.Main.Camera.Move(new Vector3(strafe/10.0f, 0, move/10.0f)); This code gives the same smooth results as the original one. Also the MoveMouse method already takes the control offset into acount so no offset is needed. Quote Windows 10 Pro 64-Bit-Version NVIDIA Geforce 1080 TI Link to comment Share on other sites More sharing options...
Rick Posted July 21, 2010 Share Posted July 21, 2010 Yes! I'm in desperate need of this for my component editor. Thank you so much for figuring this out! Quote Link to comment Share on other sites More sharing options...
Rick Posted July 25, 2010 Share Posted July 25, 2010 Any progress on this? I could really use the fixes you made to this control. Quote Link to comment Share on other sites More sharing options...
klepto2 Posted July 25, 2010 Author Share Posted July 25, 2010 sorry Rick, it takes a bit longer as i thought. I need to fix a bug with the release of the control. But i hope that i can upload it today. Quote Windows 10 Pro 64-Bit-Version NVIDIA Geforce 1080 TI Link to comment Share on other sites More sharing options...
Recommended Posts
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.