Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 19 Mar 2012
Offline Last Active Today, 10:21 AM

Posts I've Made

In Topic: How to get rid of camera z-axis rotation

24 August 2014 - 01:03 PM

You only need to update the view matrix before rendering as that is where it is used (obviously if you needed the camera or the view matrix for some math reason, i.e. culling, you could grab it sooner). Using the code above, you can call your "UpdateViewMatrix2" as much as you want but it's just going to be a waste if you aren't actually about to use that matrix.

In Topic: Terrain patch border issue

24 August 2014 - 09:30 AM

The general way I've seen people deal with this issue is just adding the 1 pixel padding so your patches overlap at the borders. If you look into World Machine's tiling functionality - that's exactly what it does to solve this problem.

In Topic: How to get rid of camera z-axis rotation

24 August 2014 - 09:09 AM

It's probably the most simple way to prevent Z rotation - not to mention it gives you a very easy way to see the exact rotation parameters of your camera (which is going to be difficult when trying to deconstruct a full rotation matrix). You can also limit either of the axis very simply by changing the min/max values of each axis which comes in handy for gameplay and the like. Also blending values smoothly between cameras, etc.


What lock are you referring to? The Yaw isn't locked at all, that's a full 360 degree circle. The pitch is locked to +/-90 degrees - any more and you end up "upside down". Change the clamp values to be -Pi and Pi and you'll see what I'm saying.


This setup should work fine for both a free camera and first person camera (as well as third person if you decide to go down that route).

In Topic: How to get rid of camera z-axis rotation

23 August 2014 - 04:28 PM

CameraMatrix isn't needed (I edited my post to reflect this). Multiplying ViewMatrix * CameraMatrix would result in an Identity Matrix(A * A' = I), so you should just need the ViewMatrix.


If your camera isn't rotating at all, I'd debug and make sure you see valid accumx/accumy values. accumx should be a value between 0 and 6.28(ish), while accumy should be between -1.57 and 1.57. Also make sure Mod2PI isn't doing anything funky.

In Topic: How to get rid of camera z-axis rotation

23 August 2014 - 01:56 PM

I think the only problem here is how to compensate rotation for camera z-axis?


Is there any way to always keep camera strictly on Z-axis not letting to roll anywhere?


If I can solve this problem, issue will gone.


That's what we're trying to help you with. This should work (I don't have SlimDX installed to test it - which is what I'm assuming you're using).

public void RotateX(float _degree_angle)
	accumx += MathUtil.DegreesToRadians(_degree_angle);
	accumx = MathUtil.Mod2Pi(accumx); // This is the same as the previous wrap around as it just does value % TWO_PI.

public void RotateY(float _degree_angle)
	accumy += MathUtil.DegreesToRadians(_degree_angle);
	accumy = MathUtil.Clamp(accumy, -MathUtil.PiOverTwo, MathUtil.PiOverTwo);

private void UpdateViewMatrix() <- This only needs to be called ONCE per frame, generally right before you set your rendering matrices.
	Matrix cameraMatrix; // This is the camera's position and rotation. It's not the same as the view matrix (in fact, it's the inverse).
	Quaternion cameraRotation = Quaternion.RotateYawPitchRoll(accumx, accumy, 0.0f);
	cameraMatrix = Matrix.RotationQuaternion(cameraRotation) * Matrix.Translation(position);
	ViewMatrix = Matrix.Translation(-position) * Matrix.RotationQuaternion(cameraRotation.conjugate()); // conjugate just gives us the inverse rotation.	

EDIT: You can skip building the "cameraMatrix" if you want. Originally I was going to use the transpose of that matrix as your view matrix, which would work as long as your transform is orthonormal, but decided I'd keep things simple.