• Advertisement
  • Popular Tags

  • Popular Now

  • Advertisement
  • Similar Content

    • By elect
      ok, so, we are having problems with our current mirror reflection implementation.
      At the moment we are doing it very simple, so for the i-th frame, we calculate the reflection vectors given the viewPoint and some predefined points on the mirror surface (position and normal).
      Then, using the least squared algorithm, we find the point that has the minimum distance from all these reflections vectors. This is going to be our virtual viewPoint (with the right orientation).
      After that, we render offscreen to a texture by setting the OpenGL camera on the virtual viewPoint.
      And finally we use the rendered texture on the mirror surface.
      So far this has always been fine, but now we are having some more strong constraints on accuracy.
      What are our best options given that:
      - we have a dynamic scene, the mirror and parts of the scene can change continuously from frame to frame
      - we have about 3k points (with normals) per mirror, calculated offline using some cad program (such as Catia)
      - all the mirror are always perfectly spherical (with different radius vertically and horizontally) and they are always convex
      - a scene can have up to 10 mirror
      - it should be fast enough also for vr (Htc Vive) on fastest gpus (only desktops)

      Looking around, some papers talk about calculating some caustic surface derivation offline, but I don't know if this suits my case
      Also, another paper, used some acceleration structures to detect the intersection between the reflection vectors and the scene, and then adjust the corresponding texture coordinate. This looks the most accurate but also very heavy from a computational point of view.

      Other than that, I couldn't find anything updated/exhaustive around, can you help me?
      Thanks in advance
    • By Enerjak
      protected void menuImage_ChildClick(Object sender, EventArgs e) { if(pbxPhoto.Image != null && sender is MenuItem) { MenuItem mi = (MenuItem)sender; pbxPhoto.SizeMode = modeMenuArray[mi.Index]; pbxPhoto.Invalidate(); } } I'm trying to make one click function to handle multiple menus. Using this code does not work when I click the menu buttons after the image is loaded in the picture box. Here is where I set the event handler of both menu items. 
      // // menuStretch // this.menuStretch.Name = "menuStretch"; this.menuStretch.Size = new System.Drawing.Size(152, 22); this.menuStretch.Text = "S&tretch to Fit"; this.menuStretch.Click += new System.EventHandler(this.menuImage_ChildClick); // // menuActual // this.menuActual.Name = "menuActual"; this.menuActual.Size = new System.Drawing.Size(152, 22); this.menuActual.Text = "&Actual Size"; this.menuActual.Click += new System.EventHandler(this.menuImage_ChildClick); Menu Stretch and Menu Actual are ToolStripMenuItems, which don't have an index variable as I've noticed. How do I get this to work? Otherwise I have to make a separate event function per menu item, which, depending on the amount of image properties, could be a a lot. 
    • By Alex Snyder
      What exactly would a gameplay programmer do within a firm? As I look at job postings to get a better idea it seems that they're largely responsible for laying the foundation code for the game. That is to say that they're in charge of making the inventory and weapons systems work. Then someone else would step in and flush it out with all the weapons the game is supposed to have and a third person would step in to make it look pretty. Naturally the programmer would have to maintain, update, and fix these systems as they grew, but most of the work is in lying the foundation upon which everything else is built. Is this a relatively decent understanding of the overarching job role or am I fiercely underestimating it?
    • By drcrack
      It is a combination of fundamental RPG elements and challenging, session-based MOBA elements. Having features such as creating your unique build, customizing your outfit and preparing synergic team compositions with friends, players can brave dangerous adventures or merciless arena fights against deadly creatures and skilled players alike.

      This time with no grinding and no pay to win features.

      We're still looking for:
      1) 3D Character Artist
      2) 3D Environment Artist
      3) Animator
      4) Sound Designer
      5) VFX Artist

      Discord https://discord.gg/zXpY29V or drcrack#4575
    • By Dave Haylett
      Hi there,
      I need a simple(ish) MP3 player for my C# WPF project. Sound isn't a major player in my project, but I do need to be able to play a couple of MP3s at the same time (loaded in as Content).
      I'm currently using the standard MediaPlayer library just to get a placeholder in there, but it does not meet these requirements:
      * Looping - no matter what I try, there's always a split-second break in the sound when it comes to looping (a few of the sounds are short tune loops, and the brief pause when looping really stands out like a sore... ear...!)
      * Mixing - at times I need to play a couple of samples simultaneously, but I don't believe MediaPlayer can support this. Having said this I've not tried invoking more than one MediaPlayer class at the same time.
      Are there any suggestions? I've browsed through NuGet but I'm surprised I can't find anything really useful.
  • Advertisement
  • Advertisement
Sign in to follow this  

C# Spaceship steering problem

Recommended Posts

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

Share this post

Link to post
Share on other sites

It sounds like gimbal lock, but looking at the code I think that the high level concept of constructing a torque to apply should work like you want it to, regardless of orientation.

My initial thought is that the transform step is somehow cancelling out the resulting torque whenever orientation starts significantly differing from your starting value (which is likely Identity?).  Perhaps the torque needs to be applied in local space?  Try just removing the Vector3.Transform line and pass (rot.TurnMultiplier*phys.SteeringTorque*0.00025f) directly to AddTorque and see what happens.

Edited by Nypyren

Share this post

Link to post
Share on other sites

Update:  OK, I examined the physics engine source code and it looks like it expects torques in world space.

Looking at your code again, I'm worried about how you're manipulating the transformed vector on the AddTorque line.  The fact that you're discarding the Z component could be what's causing the gimbal lock (see below for thought experiment).  Ideally I think that your post-transformed torque vector should be passed directly to AddTorque with no further modifications, which means you should be making your tweaks before you transform it.

Thought experiment:  Torque vectors point along the axis of rotation that they would cause.  If you want to rotate the nose to the left/right (yaw), your torque vector will be along the up/down axis of your ship.  If you want to rotate the nose up/down (pitch), your torque vector will be along the ship's right/left axis.  Assuming your base orientation is X=left/right, Y=up/down, and Z=forward/backward axis, if you put your ship into a 90 degree left/right orientation, your ship's front-back will be along the X axis and your ship's left-right axis will now correspond to world space Z axis.  That means if you want to pitch up, your torque vector will need to be along the Z axis.  But since you're zeroing out the Z component when you call AddTorque, this will result in zeroing out your torque vector completely and no torque will be applied.

Edited by Nypyren

Share this post

Link to post
Share on other sites

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

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Advertisement