Showing posts with label managed. Show all posts
Showing posts with label managed. Show all posts

Thursday, March 20, 2008

Adding Detail Map - Looks Fuzzy

To counteract the blurriness of the terrain, I'll apply a detail map. A detail map is just a plain texture with some details like cracks and bumps. The detail map will be applied 32 times over the terrain, here's what the result looks like (before and after):

closenotfuzzy closefuzzy

It looks a bit more realistic, but it seems to be really noisy and fuzzy when I fly towards it (that is when I fly using the camera controls, not in real life - I didn't take any crystal meth or anything). Here's what it looks like from far away (before and after):

notfuzzy fuzzy3

It's easiest to see the fuzzy noise on the black pit to the right. It's hard to tell from the images but it's worst when you move toward the terrain; pixels on the detail map seem to move about and make it look something like there's interference on a TV channel. When I release my game I'll just include a superficial aerial with it - problem solved.

A lot of these sort of problems can be fixed with manipulating some of the parameters (like how many times the detail map is repeated over the terrain). There are already tons of parameters I've arbitrarily picked and I just run the project to see what it looks like, then change them again - which takes up a bit of time. I'm thinking of writing some sort of Reflection-based ParameterManager class so I can easily cycle through all available parameters at run-time and save/load sets. I'll put that on the back-burner though because my terrain performs horribly at the moment so I'll do some optimisation with Continuous Level Of Detail (CLOD) next time.

Wednesday, March 19, 2008

Proper Camera Rotation

In order to have a better look at the weird artefacts on my terrain, I tried to add a mouse & keyboard controlled camera. Matrix.RotationYawPitchRoll doesn't seem to work for me - if I rotate my camera 90 degrees about the Y axis (yaw) looking to my left then try to rotate about the Z axis (roll) so the view spins clockwise it actually rotates around the X axis (pitch) and ends up looking up and down.

(I suppose I should've said on the first post that I'm writing the game in Managed DirectX with C#).

Anyways, I had this problem before when I was good at geometry so I was sure I could do it again. Unfortunately years of boozing have destroyed any remnants of my secondary school geometry and the results of my sin/cos calculations were that I should go get my old computer out of the shed and get the old code. Here it is if anyone has the same problem:

private void Rotate(float yaw, float pitch, float roll)
{
// We'll create 3 matrices for the combined rotation
Matrix yawMatrix = new Matrix ();
Matrix pitchMatrix = new Matrix ();
Matrix rollMatrix = new Matrix ();

_localMatrix.Translate(_position);

// Reset it's orientation vectors to make sure they're all
// sqare against each other and unit length
_look.Normalize();
_right = Vector3.Cross(_up, _look);
_right.Normalize();
_up = Vector3.Cross(_look, _right);
_up.Normalize();

// The pitch rotation will be done about the x axis (right)
pitchMatrix.RotateAxis(_right, pitch);
// The yaw rotation will be done about the y axis (up)
yawMatrix.RotateAxis(_up, yaw);
// The roll rotation will be done about the z axis (look)
rollMatrix.RotateAxis(_look, roll);

// Rotate the local axis about these matrices so we can tell
// how the object is now oriented after rotation

// Rotate the _look and _right about the yaw rotation
_look.TransformCoordinate(yawMatrix);
_right.TransformCoordinate(yawMatrix);

// Rotate the _up and _right about the roll rotation
_up.TransformCoordinate(rollMatrix);
_right.TransformCoordinate(rollMatrix);

// Rotate the _look and _up about the pitch rotation
_look.TransformCoordinate(pitchMatrix);
_up.TransformCoordinate(pitchMatrix);

// Store this in the local matrix for translation when rendering
_localMatrix.M11 = _right.X;
_localMatrix.M12 = _right.Y;
_localMatrix.M13 = _right.Z;

_localMatrix.M21 = _up.X;
_localMatrix.M22 = _up.Y;
_localMatrix.M23 = _up.Z;

_localMatrix.M31 = _look.X;
_localMatrix.M32 = _look.Y;
_localMatrix.M33 = _look.Z;
}