Player cannot look straight up or down

The problem is getting the point that the player is looking at. i solved this by converting the direction the player is looking to radians then using sin and cos to get the point said distance in front of them. Like this:

	public static Vector3f getMouseLook(float d) {
		
		float x = Camera.vector.x;
		float y = Camera.vector.y+Camera.height;
		float z = Camera.vector.z;
		//note that the x and y direction are flop flopped due to the way they get rendered
		float xdir = (float) ((Camera.rotation.y-90)*Math.PI)/180;
		float ydir = (float) (-Camera.rotation.x*Math.PI/180);
		
		float x1 = (float) ((d*Math.cos(xdir)));
		float y1 = (float) ((d*Math.sin(ydir)));
		float z1 = (float) ((d*Math.sin(xdir)));
		
		return new Vector3f(x1+x,y1+y,z1+z);
		
	}

well for some reason as i start to look up or down (somewhere around 75-80 degrees) the spot will stop going up/down. does anyone know why or have a better method to refer me to?
if you look at some of my newer videos of the game on youtube (http://www.youtube.com/user/gopro2027) you can probably see what i mean

Haven’t even glanced at your code. But if you’re generating a look direction then using a fixed up direction then attempting to generate a matrix via lookat is degenerate when look approaches up or -up since the cross product approaches zero.

I don’t know what that mean dude… I’m in algebra II.

Visualize a line in the direction of up and a line in the direction of look, as those two lines approach one another there isn’t enough information to compute a matrix from them.

Switching over to quaternions would be the most permanent fix.

Usually mouse look will only calculate the rotations on X and Y axes, Roll will be ignored here. Assuming [icode]dx[/icode] and [icode]dy[/icode] are the displacements in X and Y axes of mouse movement, you can calculate mouse look like this.


public void calculateMouseLook(float dx, float dy)
{
    // Rotate on the X axis, up and down, so use dy
    Camera.rotation.y += dy;

    // Rotate on the Y axis, left and right, so use dx
    Camera.rotation.x += dx;
}

This is very simple, in LWJGL, you can get dx and dy from the Mouse class.

Like Longarmx stated, quaternions are the way to go for camera orientation.

Since the OP isn’t familiar with basic concepts of vectors…saying use quaternions isn’t going to be very helpful.

That’s very true. So I would recommend this channel: thebennybox

Best tutorials on modern techniques and OpenGL

Everyone suggests him. Why doesn’t every programmer know of him now?

But to be less off-topic, the video you linked is great explanation of vectors. Warning, cross product can seem really messy (still better than quaternions, though… Ugh)!

Quaternions are straight forward. It just the resources suck.

Wikipedia on quaternions " quaternions form a four-dimensional associative normed division algebra over the real numbers, and therefore also a domain."
I already want to cry :frowning:

Didn’t I just say the resources suck? Wikipedia math pages tend to be too formal. If you understand complex number then you can understand vectors and quaternions. Quaternions are just complex numbers extended into 3 spatial dimensions.

Seeing as no one is directly solving his problem…

public static Vector3f getMouseLook(float d) {
	float x = Camera.vector.x;
	float y = Camera.vector.y+Camera.height;
	float z = Camera.vector.z;
	//note that the x and y direction are flop flopped due to the way they get rendered
	float xdir = (float) ((Camera.rotation.y-90)*Math.PI)/180;
	float ydir = (float) (-Camera.rotation.x*Math.PI/180);

	float x1 = (float) ((d*Math.cos(xdir)) * Math.cos(ydir));
	float y1 = (float) ((d*Math.sin(ydir)));
	float z1 = (float) ((d*Math.sin(xdir)) * Math.cos(ydir));

	return new Vector3f( x1+x, y1+y, z1+z );
}

Should work. However, you shouldn’t need a distance variable in your function; It wont change the outcome.

@orange451 thank you sir. Sorry i just now saw your post as java-gaming doesn’t update me (probably does but i dont see it), but your reply fixed it perfectly :slight_smile: