Jump to content
  • Advertisement

Stefan Fischlschweiger

  • Content count

  • Joined

  • Last visited

Community Reputation

788 Good

About Stefan Fischlschweiger

  • Rank
  1. Stefan Fischlschweiger

    Spaceship steering problem

    Yes, thanks, that did the trick. I probably had it wrong in my head because earlier iterations of my movement system, both physics and non-physics based required the Z component to be zeroed out here to prevent unwanted rolling. The vector components being out of order in the AddTorque line has a reason though. It's required so that steering input from the mouse and actual turning match up in direction
  2. Stefan Fischlschweiger

    C# Spaceship steering problem

    Hey guys. I haven't been here for a long time. Reason being that I didn't really code in that time. Now I've returned to my project and ran into some problem. Last time I've worked on it, I've switched my physics engine from bullet to jitter due to unresolvable problems, but there's now an issue with my steering code. In essence, depending on what direction I'm facing relative to the initial orientation the actual change in direction differs more or less from the actual input. For example, I'f I turn 90 degrees left or right it becomes impossible to turn up or down. Now, in order to make the spaceship turn, this is the code for it: Within InputSystem I calculate cursor offset from the screen center and then from it a multiplier that is then used by MovementSystem: var mouseOffsetMagnitude = Math.Abs(_mouseOffset.Length()); if(mouseOffsetMagnitude < 10) rot.TurnMultiplier = Vector3.Zero; else if (mouseOffsetMagnitude > _screenCenter.Y*0.8) { rot.TurnMultiplier = Vector3.Zero; } else { var multiX = _mouseOffset.X/(_screenCenter.Y*0.8); var multiY = _mouseOffset.Y/(_screenCenter.Y*0.8); rot.TurnMultiplier = new Vector3((float) multiY, (float) -multiX, 0); } MovementSystem takes this multiplier, which is then multiplied by the ships steering torque and a constant to get the torque vector for steering. The torque vector is also transformed by the ships orientation to ensure it's facing the correct way and then fed into Jitter to make the ship actually turn: var torqueVector = Vector3.Transform(rot.TurnMultiplier*phys.SteeringTorque*0.00025f, body.Orientation.FromJMatrix()); body.AddTorque(new JVector(0.0f, torqueVector.Y, -torqueVector.X)); Currently roll is not used, hence the 0 value in the last line.
  3. Stefan Fischlschweiger

    When you realize how dumb a bug is...

      Why would you leave your PC on for weeks continously anyway? ^^
  4. So, as some of you might have noticed from previous posts I'm working on a space sim sort of game.   In the past I've moved to use BulletSharp for physics (mainly for collision ^^)   Now I want to get my mouse based steering to work.   Basically what I'm doing right now is (pseudocode): InputSystem { GetMousePosition; GetMouseOffsetFromScreenCenter(mousePosition); CalculateTurnMultiplier(mouseOffset) RotationComponent.turnMulti = turnMulti; } MovementSystem { torqueVector = (turnMulti*steeringTorque*scaling) transformed by rigidBody.Orientation rigidBody.ApplyTorque(torqueVector); } This does turn the ship, but in all kinds of weird ways.   The steering behaviour I want is actually like this: [attachment=31472:spaceshipturning.png]   Kind of like in freelancer.   Now, I've already figured out on how to get my desired TurnMultiplier (how hard the ship shall turn), but the calculation of the correct torque to put into BulletSharp is giving me headaches.   My theory is that, when I move the cursor away from the screen center I need to add more torque based on how fast I'm already turning and vice versa. But this just doesn't want to compute in my head.
  5. I'm now trying to move away from the Almirante engine ECS I've been using so far and implement my own.   I've now got a GameObject class: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MetastormDX.Engine.Objects { internal class GameObject { internal uint Id; internal string Tag; internal Dictionary<Type, Component> Components; internal GameObject() { Components = new Dictionary<Type, Component>(); Create(); } internal GameObject(IEnumerable<Component> components) { foreach (var component in components) { AddComponent(component); } Create(); } internal void AddComponent(Component component) { component.Create(); Components.Add(component.GetType(), component); } internal void RemoveComponent(Type componentType) { Components.Remove(componentType); } internal T GetComponent<T>() where T : Component { Component component; Components.TryGetValue(typeof(T), out component); return component as T; } private void Create() { } private void Kill() { foreach (var component in Components) { component.Value.Destroy(); } Components = null; } } } Everything shall be an instance of this class, instead of having many derived classes for all kinds of objects (like ships, stations, planets, guns, lights, etc..) with the object being defined by the Components attached to it.  For example, a planet would have at least a TransformComponent and a RenderComponent, but no VelocityComponent as it doesn't move.   The TransformComponent class currently looks like this: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using SharpDX; namespace MetastormDX.Engine.Objects.Components { internal class TransformComponent : Component { internal bool HasParent; internal TransformComponent ParentTransformComponent; internal Vector3 WorldPosition; internal Vector3 LocalPosition; internal Quaternion WorldOrientation; internal Quaternion LocalOrientation; internal TransformComponent() { HasParent = false; WorldPosition = Vector3.Zero; WorldOrientation = Quaternion.Zero; } internal override void Create() { if (!HasParent) { LocalPosition = Vector3.Zero; LocalOrientation = Quaternion.Zero; ParentTransformComponent = null; } } } } Now as you can see objects can be in a parent-child relation, like guns attached to ship or station.   I've started writing a MovementSystem class which is (obviously) resposible for moving all the objects around that can move: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using MetastormDX.Engine.Core; using MetastormDX.Engine.Objects.Components; namespace MetastormDX.Engine.Objects.Systems { internal class MovementSystem : GameSystem { internal List<GameObject> RegisteredGameObjects; internal override void Initialize() { } internal override void Execute(GameTime gameTime) { Parallel.ForEach(RegisteredGameObjects, (currentObject) => { var transform = currentObject.GetComponent<TransformComponent>(); var velocity = currentObject.GetComponent<VelocityComponent>(); }); } } } Now, my question here is: How would I go about making child objects move with their parents and, more importantly, how I can make sure that they are moved in the correct order. That is, first the objects which are only parents, then their childs and so on down the heirarchy, in case there are 3 or more layers in a parent-child chain?
  6. Stefan Fischlschweiger

    Client/Server rendering

    Since all the client handles is user input, rendering and sound output I'd have the server send each client something like this: struct DrawCall { Vector2 position, int Layer, uint SpriteID } The renderer in the client would then pull the sprite texture from it's assets by ID and draw it in the given location.   Please note that I never tried myself at a 2D engine so this suggestion is probably not really the optimal solution
  7. Stefan Fischlschweiger

    What the hell happened to Windows touchpad support? (driver rant)

    I have a Synaptic PS/2 Touchpad in my 2011 Acer Aspire 7750G and it showes the code SYN1B16 in both Device Manager and AIDA64
  8. Stefan Fischlschweiger

    When you realize how dumb a bug is...

    So I recently fixed 2 bugs that were bugging me for months (pun entirely intended) and really derp-worthy   So I am trying to get rid of D2D for sprite rendering and made my own code for creating an rendering quads, just they never showed up on screen. In the end it turned out I simply forgot to do vertexStream.Position = 0; indexStream.Position = 0; before creating the buffers from the streams.   Then I noticed a memory leak and spent countless hours trying to track it down. In the end it was as simple as putting TextLayout.Dispose(); into the MeasureString method I wrote using DirectWrite, which gets called several times per frame - D'oh!
  9. Stefan Fischlschweiger

    Creating a custom sprite class

    You can go even simpler: Use a single triangle and generate the vertices in the shader aka Full Screen Triangle
  10. Stefan Fischlschweiger

    Creating a custom sprite class

    If all you're doing with sprites is this single window sized texture then you can look into Screen Aligned Quads to do this entirely in the shader without need for a custom sprite class 
  11. Maybe you run into DirectX limits here, what if you try to break the model into parts and render them seperately?
  12. Appearently resizing requires a little bit more to do before when using deferred contexts.   Quote from MSDN:    
  13. Stefan Fischlschweiger

    Scale vertices to pixels

    D'oh, finally realized I completely derped and forgot to reset the position on the vertex and index streams before writing to the buffers on quad creation ^^
  14. Stefan Fischlschweiger

    Scale vertices to pixels

    Actually, when I look at the position and texture coordinate values in the vertex shader stage are completely bogus. Either 0 or NaN or impossibly small with exponents down to E-47. And some don't show anything in the Input Buffers windows of the graphics debugger at all
  15. Stefan Fischlschweiger

    Scale vertices to pixels

    So, my current implementation looks like this:   I've got a Quad class which contains a vertex and an index buffer as well as an SRV for the texture and is initialized based on the desired position and size: using System; using SharpDX; using SharpDX.Direct3D11; using SharpDX.DXGI; using Buffer = SharpDX.Direct3D11.Buffer; using Device = SharpDX.Direct3D11.Device; namespace DX11Renderer.Graphics { public class Quad : IDisposable { public Buffer VertexBuffer; public Buffer IndexBuffer; public ShaderResourceView Texture; public InputLayout Layout; public Quad(Device device, byte[] signature, Vector2 position, Vector2 size) { var vertices = new[] { new Vector4(position, 0, 1), new Vector4(position.X + size.X, position.Y, 0, 1), new Vector4(position + size, 0, 1), new Vector4(position.X, position.Y + size.Y, 0, 1) }; var uvs = new[] { new Vector2(0), new Vector2(0, 1), new Vector2(1, 1), new Vector2(1, 0) }; var indices = new[] {0, 1, 2, 2, 3, 0}; var vertexStream = new DataStream((Utilities.SizeOf<Vector4>() + Utilities.SizeOf<Vector2>()) * 4, true, true); var indexStream = new DataStream(sizeof(int)*6, true, true); for (int i = 0; i < 4; i++) { vertexStream.Write(vertices[i]); vertexStream.Write(uvs[i]); } for (int i = 0; i < 6; i++) { indexStream.Write(indices[i]); } VertexBuffer = new Buffer(device, vertexStream, new BufferDescription(Utilities.SizeOf<Vector4>()*4 + Utilities.SizeOf<Vector2>() * 4, ResourceUsage.Default, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0)); IndexBuffer = new Buffer(device, indexStream, new BufferDescription(sizeof(int) * 6, ResourceUsage.Default, BindFlags.IndexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0)); Layout = new InputLayout(device, signature, new[] { new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0), new InputElement("TEXCOORD", 0, Format.R32G32_Float, 16, 0) }); } public void Dispose() { VertexBuffer.Dispose(); IndexBuffer.Dispose(); } } } I create a Quad e.g. in my UIElementButton class like this: _buttonQuad = new Quad(GameServices.GetService<RendererD3D11>().D3DDevice, GameServices.GetService<RendererD3D11>().Shaders["QuadShader"].Signature, Vector2.Zero, new Vector2(256, 64)); _buttonQuad.Texture = ShaderResourceView.FromFile(GameServices.GetService<RendererD3D11>().D3DDevice, @"Content\Interface\Menu\Button.dds"); Which is then send to the DrawQuad method in the QuadRenderer class: public void DrawQuad(Quad quad, Shader shader, Device d3DDevice) { _context.VertexShader.SetConstantBuffer(0, _cBuffer); _context.UpdateSubresource(ref _transform, _cBuffer); _context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; _context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(quad.VertexBuffer, 24, 0)); _context.InputAssembler.SetIndexBuffer(quad.IndexBuffer, Format.R32_UInt, 0); _context.InputAssembler.InputLayout = quad.Layout; _context.VertexShader.Set(shader.VertexShader); _context.PixelShader.Set(shader.PixelShader); _context.PixelShader.SetSampler(0, _sampler); _context.PixelShader.SetShaderResource(0, quad.Texture); _context.OutputMerger.SetDepthStencilState(_state); _context.DrawIndexed(6, 0, 0); } FYI, Sampler is AnisotropicWrap and DepthStencilState is Disabled The data is then to be rendered on the GPU using this simple Shader: cbuffer QuadBuffer: register(b0) { float4x4 projection; } Texture2D Texture; SamplerState textureSampler; struct VSQuadIn { float4 position: POSITION; float2 texcoord: TEXCOORD; }; struct VSQuadOut{ float4 position : SV_Position; float2 texcoord: TexCoord; }; VSQuadOut VertexShaderFunction(VSQuadIn In) { VSQuadOut Out; Out.texcoord = In.texcoord; Out.position = mul(In.position, projection); return Out; } float4 PixelShaderFunction(VSQuadOut input) : SV_TARGET { float4 textureColor = Texture.Sample(textureSampler, input.texcoord); textureColor.a = 1; return textureColor; } technique fsQuad { pass Pass1 { VertexShader = compile vs_4_0 VertexShaderFunction(); PixelShader = compile ps_4_0 PixelShaderFunction(); } }; ------- But when I run the game the Quads don't render and when I take a look using the graphics debugger there's nothing showing up on the Input Assembler and VertexShader stages at all
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!