Sunday, December 8, 2013

Progress Update:

We are still making progress with the toon shader.

Since we had the gyro and accelerometer movement working for the ship, we next tried to have the camera move with the ship in front of it. We have the camera moving along a parametric path, which will allow the game to keep track of laps and allow us to scale the difficulty based on how long the player has survived.

We used a solid green plane as the ground and tried keeping the ship in front of the camera by taking the camera position and translating that position by 4 times the unit vector representing the direction the camera is pointing. This is the location where the ship would be. We then had to account for the fact that when the camera turns, the ship will need to rotate so that it is facing forward with respect to the camera. The angle of rotation needed was found by taking the inverse cosine of the dot product between the ships original facing direction and the direction the camera is facing. This was the result we got (Note: its a top down view since from the camera's perspective its hard to distinguish movement without any other items on the surface, and the path is shrunk to fit the whole movement on the screen):


Since the ship was doing a strange rotation, we knew there was something wrong. We noted that the directions the ship would face only accounted for 180 degrees of motion. This meant that the angle being returned from the inverse cosine of the dot product was never negative. To fix this, the cross product of the two vectors was taken as well. If the result had a positive y value (meaning up), then its a rotation counter-clockwise and the angle remains positive. If the result had a negative y value (meaning down), then its rotation is clock-wise and so the angle is made negative. This was the result after this change:

Success!

Side note: We are still trying to figure out what is causing the strange lighting change while it moves.

No comments:

Post a Comment