Simple Camera Manipulation (Math)

final float dx = Mouse.getDX() * 0.1f, dy = Mouse.getDY() * 0.005f * 0, sdy = Mouse.getDWheel() * 0.1f;
				offset += sdy;
				pitch += dy;
				y += dx;
				
				double vert = offset * Math.sin(pitch),
						horiz = offset * Math.cos(pitch);
				
				double offsetx = offset * Math.sin(Math.toRadians(y)),
						offsety = offset * Math.cos(Math.toRadians(y)),
						p = 180 - y;
				
				this.getPosition().x = (float) (element.getPosition().x - offsetx);
				this.getPosition().y = (float) (element.getPosition().y + vert);
				this.getPosition().z = (float) (element.getPosition().z - offsety);

While this code works, I need to rotate the camera towards the center focus. The camera currently spins around the center object (called element, this being the camera). I disabled the y transformation currently by multiplying by 0.

As per “p = 180 - y;”, my understanding is that this fixes the rotation, but it causes my camera to always face somewhere not looking at my element. Thusly, “p = y;” doesn’t follow the camera, but brings it into the center of the view.

Could anyone help shine light on this subject?
<3

If you want to implement an arcball camera, then the only thing you have to do is this to get a camera/view matrix for OpenGL, which I assume you are using:
(pseudo-code)


translate(0, 0, -distance)
rotate(<angle around the x axis>)
rotate(<angle around the y axis>)
translate(-target.x, -target.y, -target.z)

Where “distance” is the radius of the arcball and “target” is the center of the arcball (i.e. the point which the camera is looking at)
Each transformation above uses post-multiplication, like the glRotatef/glTranslatef functions do.

It turns out negating the values and negating the y value works. Hmm…

I appreciate your reply, but I am not working with matrices in that manor.