• Advertisement

lucasite

Member
  • Content count

    58
  • Joined

  • Last visited

Community Reputation

123 Neutral

About lucasite

  • Rank
    Member
  1. Hi everyone, Ive recently been reading about behavior trees for AI and how they work. There's lots of great stuff on here. However Im stuck with a question. Imagine I have an AI truck, that needs to drive to point A, load up some goods, then drive to point B and unload them. These are laid out appropriately as leaf nodes in a behavior tree.   What happens when an action takes a large amount of time? For instance, in each game loop, no other nodes will be tested whilst the drive from point A to point B node continues to execute. But what happens if the truck is attacked by bandits halfway through? There may well be a whole new set of rules for handling this situation, but Im always executing this "transport" node until its complete.   My only thought is rather than have a node that says "drive from point A to point B", it would become "move 5 feet in the direction of point B as long as there's no bandits around...and there's still fuel.....and the driver is not tired". My concern is thats alot of questions to ask, each game loop, for each AI entity.   Is this the right way to handle these long actions, by chopping them up and avoiding them altogether? Or is there a better way for this scenario?   regards   Luca
  2. Hi all, Im just playing around with some networking in c#. Its just a little chat thing running inside xna, just learning really. Here's my problem. 1) I click on a user and request user info. 2) a message type is sent through the socket requesting user info for user X. 3) Some time later, the socket receives some incoming data (the user info). At this point, how can I know that this incoming data, needs to be sent to a specific popup window in screen? What if I open two user info popups in quick succession? Im just wondering if there's some sort of best practice for this? I thinking maybe I need to maintain a request list when data is sent. Each request would have some unique id, associated with some function, callback or window. Then when the socket receives the data, it can scan through the list, find the unique id, and know which function is supposed to be dealing with this data. It would mean sending the unique id across the socket aswell, but that feels expensive. Anyway, thats whats Im thinking of writing. Just wondered if Im completely off base or not. Regards Luca
  3. Unfortunately that didnt help. However it did point me in the right direction. It seems I shouldve been using: var projection = Matrix.PerspectiveFovLH(45.0f, form.ClientSize.Width / (float)form.ClientSize.Height, 1.0f, 1000.0f); I need to investigate the difference between PerspectiveLH and PerspectiveFovLH.
  4. Hi, I need some an extra pair of eyes folks, Ive been going crazy trying to figure this out for a few hours now. I took the sample MiniTri code for Dx11. All I wanted to do was change the code to include a camera. So I added 2 matrices, one for view, one for projection. I also changed the effect file to mul(...) the world/view/projection. But the result is just a black screen. I cant figure it out. The effect file looks correct. Ive compare with out effect files. And the matrices look correct. So I have no idea why its not working. Ive also tried positioning the camera in different locations (incase its a culling issue), still nothing. This is the code: [code]using System; using System.Drawing; using System.Windows.Forms; using SlimDX; using SlimDX.Direct3D11; using SlimDX.DXGI; using SlimDX.Windows; using SlimDX.D3DCompiler; using Device = SlimDX.Direct3D11.Device; namespace Dx11Project1 { static class Program { [STAThread] static void Main() { var form = new RenderForm("SlimDX - MiniTri Direct3D 11 Sample"); var desc = new SwapChainDescription() { BufferCount = 1, ModeDescription = new ModeDescription(form.ClientSize.Width, form.ClientSize.Height, new Rational(60, 1), Format.R8G8B8A8_UNorm), IsWindowed = true, OutputHandle = form.Handle, SampleDescription = new SampleDescription(1, 0), SwapEffect = SwapEffect.Discard, Usage = Usage.RenderTargetOutput }; Device device; SwapChain swapChain; Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.Debug, desc, out device, out swapChain); Factory factory = swapChain.GetParent<Factory>(); factory.SetWindowAssociation(form.Handle, WindowAssociationFlags.IgnoreAll); Texture2D backBuffer = Texture2D.FromSwapChain<Texture2D>(swapChain, 0); var renderView = new RenderTargetView(device, backBuffer); var bytecode = ShaderBytecode.CompileFromFile("MiniTri.fx", "fx_5_0", ShaderFlags.None, EffectFlags.None); var effect = new Effect(device, bytecode); var technique = effect.GetTechniqueByIndex(0); var pass = technique.GetPassByIndex(0); var layout = new InputLayout(device, pass.Description.Signature, new[] { new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0), new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 16, 0) }); // setup triangle vertices var stream = new DataStream(3 * 32, true, true); stream.WriteRange(new[] { new Vector4(-5.0f, 0.0f, 0.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f), new Vector4(0.0f, 5.0f, 0.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f), new Vector4(5.0f, 0.0f, 0.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f) }); stream.Position = 0; var vertices = new SlimDX.Direct3D11.Buffer(device, stream, new BufferDescription() { BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SizeInBytes = 3 * 32, Usage = ResourceUsage.Default }); stream.Dispose(); device.ImmediateContext.OutputMerger.SetTargets(renderView); device.ImmediateContext.Rasterizer.SetViewports(new Viewport(0, 0, form.ClientSize.Width, form.ClientSize.Height, 0.0f, 1.0f)); // Setup camera views var view = Matrix.LookAtLH(new Vector3(0.0f, 0.0f, 5.0f), Vector3.Zero, Vector3.UnitY); var projection = Matrix.PerspectiveLH(form.ClientSize.Width, form.ClientSize.Height, 0.0f, 100.0f); MessagePump.Run(form, () => { device.ImmediateContext.ClearRenderTargetView(renderView, Color.Black); // set effect variables var viewVariable = effect.GetVariableByName("View").AsMatrix(); var worldVariable = effect.GetVariableByName("World").AsMatrix(); var projVariable = effect.GetVariableByName("Projection").AsMatrix(); viewVariable.SetMatrix(view); projVariable.SetMatrix(projection); worldVariable.SetMatrix(Matrix.Identity); device.ImmediateContext.InputAssembler.InputLayout = layout; device.ImmediateContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; device.ImmediateContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertices, 32, 0)); for (int i = 0; i < technique.Description.PassCount; ++i) { pass.Apply(device.ImmediateContext); device.ImmediateContext.Draw(3, 0); } swapChain.Present(0, PresentFlags.None); }); bytecode.Dispose(); vertices.Dispose(); layout.Dispose(); effect.Dispose(); renderView.Dispose(); backBuffer.Dispose(); device.Dispose(); swapChain.Dispose(); } } } [/code] And this is the effect file: [code]float4x4 World; float4x4 View; float4x4 Projection; struct VS_IN { float4 pos : POSITION; float4 col : COLOR; }; struct PS_IN { float4 pos : SV_POSITION; float4 col : COLOR; }; PS_IN VS( VS_IN input ) { PS_IN output = (PS_IN)0; float4 worldPosition = mul(input.pos, World); float4 viewPosition = mul(worldPosition, View); output.pos = mul(viewPosition, Projection); output.col = input.col; return output; } float4 PS( PS_IN input ) : SV_Target { return input.col; } technique10 Render { pass P0 { SetGeometryShader( 0 ); SetVertexShader( CompileShader( vs_4_0, VS() ) ); SetPixelShader( CompileShader( ps_4_0, PS() ) ); } } [/code] Is there a way of debugging Slimdx? Finding out whats going on with directx? Im running Win7 x64, so Pix doesnt work if I try.
  5. That was it, thanks Starnick. Id also missed out the setTarget line aswell. So here's the code for anyone else who stumbles across this issue. [code]public void FormResize(object sender, EventArgs e) { var form = (Form)sender as Form; renderView.Dispose(); swapChain.ResizeBuffers(1, form.ClientSize.Width, form.ClientSize.Height, Format.R8G8B8A8_UNorm, SwapChainFlags.None); using (var bb = Resource.FromSwapChain<Texture2D>(swapChain, 0)) renderView = new RenderTargetView(device, bb); device.ImmediateContext.OutputMerger.SetTargets(renderView); device.ImmediateContext.Rasterizer.SetViewports(new Viewport(0, 0, form.ClientSize.Width, form.ClientSize.Height, 0.0f, 1.0f)); }[/code]
  6. Hi all, I have written the following code to handle my form resizing: [code]public void FormResize(object sender, EventArgs e) { var form = (Form)sender as Form; renderView.Dispose(); swapChain.ResizeBuffers(1, form.ClientSize.Width, form.ClientSize.Height, Format.R8G8B8A8_UNorm, SwapChainFlags.None); renderView = new RenderTargetView(device, backBuffer); device.ImmediateContext.Rasterizer.SetViewports(new Viewport(0, 0, form.ClientSize.Width, form.ClientSize.Height, 0.0f, 1.0f)); }[/code] but it throws an exception the next time the draw method begins: "External component has thrown an exception." Im sure I read somewhere that I need to dispose the RenderTargetView first. And as far as I can see, the swapchain and viewport are the only places that refers to sizes. Can anyone spot what Im doing wrong? regards Luca
  7. Thankyou so much apatriarca. This worked a treat.
  8. Yes, thats not a problem, Im using floats. So Ive put this function together, but its still not behaving correctly. private void UpdatePosition(double gameTime) { var spdX = _ship.Speed / (_destination.Position.X - _ship.Position.X); var spdY = _ship.Speed / (_destination.Position.Y - _ship.Position.Y); var travelledX = gameTime * spdX; var travelledY = gameTime * spdY; // calculate min distance to travell travelledX = Math.Min(travelledX, (_destination.Position.X - _ship.Position.X)); travelledY = Math.Min(travelledY, (_destination.Position.Y - _ship.Position.Y)); _ship.Position.X = (float)(_ship.Position.X + travelledX); _ship.Position.Y = (float)(_ship.Position.Y + travelledY); } I still think Im calculating the spdX and spdY values incorrectly. But Im not sure why. They should be proportionate shouldnt they?
  9. But that assumes I know velocity.x and velocity.y. What if I dont, what if I only know my overall velocity? Edit: Actually this would work if I could proportion my overall velocity into the x,y. maybe: velocity.x = (1 / (finish.x-start.x)) * velocity velocity.y = (1 / (finish.y-start.y)) * velocity would that work?
  10. Hi all, here's my problem. I have a start position (0,0) and finish position (100,200). If an object travels at 1 pixel per second, at what position will the object be after 5 seconds. Now I can work out the distance from start to finish as: distance = (finish.x - start.x) + (finish.y - start.y) And I know that speed multipled by time = distance travelled. But Im completely stuck on how to convert that into a new position. Upon a straight line is easy, but Im stuck in 2d coordinates. Can anyone point me in the right direction, or offer some friendly help? Luca
  11. But RawInput only has one keyboard event, SlimDX.RawInput.Device.KeyboardInput. How can I access the keydown/keyup events from here?
  12. Ahh brilliant, yes thats what I need. And there's a SlimDx already, how did I miss that. One last question, is it possible to trap two key presses at once, for example alt-enter? Or alternatively for the mouse, a left button held down whilst mouse moving?
  13. Hi, Ive read everywhere that we shouldnt be using DirectInput anymore. So Im trying to find the correct alternative. Trying to tie up keys to my camera, Ive noticed the following conditions: form.KeyUp event - camera movement only occurs when I release the key form.KeyPress event - doesnt seem to trigger for all keys (not function keys anyway) and only provides a numeric char value form.KeyDown event - only handles one key press at a time. (I havent looked at mouse yet, but I assume I should be registering the form.mousemove event) These seem very clumsy though, and Im wondering if Im looking in the right place. Should I maybe use win32 apis to capture keyboard and mouse actions? Any thoughts? Luca
  14. Hi, I created a class to render a simple triangle (using sample code) and that renders fine. But it doesnt use any Matrices or camera. So I started to change the class. Created a new camera object, included a new effect file, passed in effect params to set view/projection/world.But the result is a black screen, and I cannot figure out why. It must be something really obvious, can anyone spot it? using System; using Buffer = SlimDX.Direct3D10.Buffer; using Device = SlimDX.Direct3D10.Device; using SlimDX; using SlimDX.Direct3D10; using SlimDX.DXGI; using SlimDX.Windows; namespace Beta { public class WorldTriangle : IFrameworkObject { const int sizeOfStream = 32; const int numVertices = 3; private Effect effect; private EffectTechnique technique; private EffectPass pass; private InputLayout layout; private Buffer vertices; public WorldTriangle(GraphicsDevice graphicsDevice) { this.effect = Effect.FromFile(graphicsDevice.Device, "Effects\\WorldTriangle.fx", "fx_4_0", ShaderFlags.None, EffectFlags.None, null, null); layout = new InputLayout(graphicsDevice.Device, effect.GetTechniqueByIndex(0).GetPassByIndex(0).Description.Signature, new[] { new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0), new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 16, 0) }); var stream = new DataStream(numVertices * sizeOfStream, true, true); stream.WriteRange(new[] { new Vector4(0.0f, 0.5f, 0.5f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f), new Vector4(0.5f, -0.5f, 0.5f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f), new Vector4(-0.5f, -0.5f, 0.5f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f) }); stream.Position = 0; vertices = new SlimDX.Direct3D10.Buffer(graphicsDevice.Device, stream, new BufferDescription() { BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SizeInBytes = numVertices * sizeOfStream, Usage = ResourceUsage.Default }); stream.Dispose(); } public void Render(GraphicsDevice graphicsDevice, Camera camera) { graphicsDevice.Device.InputAssembler.SetInputLayout(layout); graphicsDevice.Device.InputAssembler.SetPrimitiveTopology(PrimitiveTopology.TriangleList); graphicsDevice.Device.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertices, sizeOfStream, 0)); effect.GetVariableByName("Projection").AsMatrix().SetMatrix(camera.Projection); effect.GetVariableByName("View").AsMatrix().SetMatrix(camera.View); effect.GetVariableByName("World").AsMatrix().SetMatrix(Matrix.Identity); effect.GetTechniqueByIndex(0).GetPassByIndex(0).Apply(); graphicsDevice.Device.Draw(numVertices, 0); } public void Dispose() { Dispose(true); } private void Dispose(bool calledExplicitly) { if (calledExplicitly) { vertices.Dispose(); layout.Dispose(); effect.Dispose(); } } } } The camera has been set to position 0,0,10, looking at 0,0,0. public Matrix Projection { get { return Matrix.PerspectiveFovLH(45.0f, width / (float)height, 1.0f, 1000.0f); } } public Matrix View { get { return Matrix.LookAtLH(Position, Target, up); } } The effect file is pretty simple: float4x4 World; float4x4 View; float4x4 Projection; struct VertexShaderInput { float4 Position : POSITION; float4 col : COLOR; }; struct VertexShaderOutput { float4 Position : SV_POSITION; float4 col : COLOR; }; VertexShaderOutput VertexShaderFunction(VertexShaderInput input) { VertexShaderOutput output; float4 worldPosition = mul(input.Position, World); float4 viewPosition = mul(worldPosition, View); output.Position = mul(viewPosition, Projection); output.col = input.col; return output; } float4 PixelShaderFunction(VertexShaderOutput input) : SV_Target { return input.col; } technique10 Render { pass P0 { SetGeometryShader( 0 ); SetVertexShader( CompileShader( vs_4_0, VertexShaderFunction() ) ); SetPixelShader( CompileShader( ps_4_0, PixelShaderFunction() ) ); } } One other question, when setting the device viewport, should the maxZ value correspond to the same Zfar in the camera? I noticed from the examples its always 1. device.Rasterizer.SetViewports(new Viewport(0, 0, form.ClientSize.Width, form.ClientSize.Height, 0.0f, 1.0f));
  15. [SlimDx] Multiple render viewports

    Quote:Original post by JohnnyCodeAlso do not destroy the window the device was created with Even though its being rendered to a control? So when I init the device, I should use the window handle, but when I render, I should use the control handle? Is that what you mean?
  • Advertisement