Hi everyone. I'm currently setting up an ICE compound to use Xbox 360 controller as input device. It got me thinking - there's a lot of stuff that's relevent to ICE with game programming. Lots of stuff dealing with 3d vectors, matrices, etc. While matrices are very slowly starting to sink in, they're still a bit too advanced for me. Especially when dealing with rotation matrix. While I'm starting to get why they are useful, I'm still a bit unclear as to how they are implemented.
For instance, here's how to create a 3rd person camera - http://msdn.microsoft.com/en-us/library ... o.31).aspx
Code: Select all
1.Decide on a camera offset vector from the avatar. An offset of the form (0, N, −N) will put the camera above and behind the avatar at a 45-degree angle.
Vector3 thirdPersonReference = new Vector3(0, 200, -200);
Code: Select all
3.Create the rotation Matrix with CreateRotationY, using the avatar's current rotation as its parameter.
Matrix rotationMatrix = Matrix.CreateRotationY(avatarYaw);
Code: Select all
4.Transform a copy of the camera offset vector by using the Transform method and the rotation Matrix.
// Create a vector pointing the direction the camera is facing.
Vector3 transformedReference =
Vector3.Transform(thirdPersonReference, rotationMatrix);
Code: Select all
5.Calculate the camera's position as the avatar's position, and calculate the transformed camera offset.
// Calculate the position the camera is looking from.
Vector3 cameraPosition = transformedReference + avatarPosition;
Add the offset position plus the avatar's pos. When you transform the vector, it is always around 0,0,0 so you need to add the avatar's position to keep it "attached"
Code: Select all
6.Create a view Matrix with the CreateLookAt method. The avatar's current position will be the cameraTarget parameter.
view = Matrix.CreateLookAt(cameraPosition, avatarPosition,
new Vector3(0.0f, 1.0f, 0.0f));
Code: Select all
7.Create a new projection Matrix with CreatePerspectiveFieldOfView. The projection Matrix controls how camera coordinate values are transformed to screen coordinates.
Viewport viewport = graphics.GraphicsDevice.Viewport;
float aspectRatio = (float)viewport.Width / (float)viewport.Height;
proj = Matrix.CreatePerspectiveFieldOfView(viewAngle, aspectRatio,
nearClip, farClip);
I'm still a bit lost and not exactly sure how this works, but I think it's very useful and want to understand it. Please help explain it better.
-Edited the title.
Thanks,
-Dave