Friday, April 22, 2011

Autopilot and Stardust.



Now the autopilot works well: you select your destination with the mouse,  then the autopilot aligns your ship with the target, thrust the engine until you've made an half of the voyage, and finally brake near the destination... there's something to refine but it works!
I've also added "stardust" to give more depth to the starship speed.. the dust is white for now: i've choose this colour so you can see it into the low-resolution video :). Now it looks like the old Braben's game "Frontier"
I'm thinking how to brake the ship.. using the inertial behaviour is a bit annoying: you've to align the ship to the current speed direction and brake.. if you brake too much the ship moves backward (you can see it at the end of the video), and if you do not align well you create some side movement. In one phrase: it's very difficult to stop a ship manually using an inertial engine.
So it should be less realistic but more usable a brake that doesn't changes the speed direction but his lenght. If i divide the x,y,z component of speed by i.e. 1.01, i don't need to align the ship to brake and i can make some more complex maneuvers...

Happy easter to everybody.

Monday, April 18, 2011



Time to improve (and rewrite) the autopilot.. now i can select an object using the mouse, the next step is to move my ship to the selected destination.
The autopilot is a state-machine that has a lot of step, but you can summarize it into two big "macros":
  1. align the ship to a selected direction
  2. move the ship (or stop it).
This is the first step: the alignment phase. I need to align to a specific direction regardless of the initial orientation of the ship.
I need a function that give me the thrust power of the engine from the angle between direction and final orientation: the more distant i am, more power the engine should provide. Otherwise, when the angle is small, the engine should provide less energy.
A good solution is to use the dot product between destination vector and right/up vector. The dot product between u and v is defined like |u||v|cos(angle) where angle is angle between u and v. If u and v are unitary, the cross product give me the angle.

For yaw, the cross product between destination and right is a function that is = 0 when right is normal to direction (and it's true when direction is equal to destination..), is > 0 when direction lies left to the destination, <0 when direction lies right. Perfect for my needs!
Finally, i've to normalize for angles > 90 degrees:

if (angle > 90)
{
   if (dotproduct > 0)
      dotproduct=1;
   else
      dotproduct=-1;
}

For pitch is the same, but i use the up vector instead right.
The result is shown in the video.
There's some "freeze": is an issue of my laptop (i've some problem with vista and the hard disk drivers..), not of the game :)

Monday, April 11, 2011

Camera roll and mouse gesture

At least the camera control is almost finished: now you can pitch, yaw and roll, so you can do almost all movement into space.
So i've started to work to the mouse gesture: i've a GUI, and now is time to create some interaction between the mouse and the 3d world.
In this video you can see the ineractions between pointer and mesh.. when you left click in any mesh, its bounding box is displayed. Notice: when two mesh are aligned (i.e. the station and the planet) when you click on both, the engine selects the nearest.