yasp: basic camera operation

Started by
1 comment, last by nkint 13 years, 7 months ago
hi all
yet another stupid post about camera operation, for rotations and pans.

first of all, i'm doing jobs with JOGL, i'm on Eclipse ide, and i have zero knowledge on 3d stuffs, hope not be too lame.

i want to make some nice effects, like the one linked below, but i didn't managed to.

in past with a java framework called prcoessing.org i've used this lib:
http://mrfeinberg.com/peasycam/
(with the java applet and rotation effect i want to make)
really good one!, but now i'm out of that framework and want to try to do it myself, wihtout ready-to-use libs.

i've tried to read the java code but i didn't understand a lot.. i grabbed that they use apache.geometry for rotations, and maybe quaternions.

i have a central object in position 0,0,0 and i've tried to rotate it following -the mouse-drag movement like that:
gl.glRotatef(rot.x,1,0,0); gl.glRotatef(rot.y,0,1,0); // all scene here// blabla 


and rot is a vector with the movement of mouse dragged in screen.

it is really no nice, i don't understand if it's because i'm appling rotation on object and not on camera or because of quaternion (i'm studing..)
and i'm looking for advice or some nice articles that explains some kind of experiments about rotations and pitch.
(in some games pitch and roll are linked for same movment or similar)

thanks!
sorry for confusion
Advertisement
What happens currently when you drag the mouse?

It may be that you need to undo the rotation after you've rendered the object, but I can't say for sure until I know what happens with the current code. If this is the problem, there are two ways of solving this:

Method 1 - Reverse the rotation:

gl.glRotatef(rot.x,1.0f,0.0f,0.0f);gl.glRotatef(rot.y,0.0f,1.0f,0.0f);//Draw object gl.glRotatef(-rot.y,0.0f,1.0f,0.0f);gl.glRotatef(-rot.x,1.0f,0.0f,0.0f);


Method 2 - Push and Pop the Modelview matrix stack:

gl.glMatrixMode(GL.GL_MODELVIEW);gl.glPushMatrix();gl.glRotatef(rot.x,1.0f,0.0f,0.0f);gl.glRotatef(rot.y,0.0f,1.0f,0.0f);//Draw object gl.glPopMatrix();


I normally use the second method. You may also want to try gluLookAt, if that's available in Java. It would be helpful if you could post up the code from when you set up your camera to the end of your rendering function. :)

Sput

P.S. Don't worry too much about quaternions, matrices are far more useful to learn about. I mainly only use quaternions for storage or where I have to apply a rotation quickly.
hi!
thanks for answer
my problem is not about push or pop matrix, the object is in the place i want

Quote:
What happens currently when you drag the mouse?


i've tried this code:
public void mouseDragged(MouseEvent e) {	deltax = e.getX() - (int)mouseDown.x;	deltay = e.getY() - (int)mouseDown.y;	mouseMoved(e);	setRot(new Point3D(deltax, deltay, 0));}public void setRot(r) {	this.r_offset = r;}@Overridepublic void display(GLAutoDrawable drawable) {			//blabla glClear, glLoadIdentity, etc..	//gl.glTranslatef( blabla	gl.glRotatef(r_offset.x,0,1,0);	gl.glRotatef(r_offset.y,1,0,0);			render(gl); //do all scene	}public void render {


(i tried a lots of combinations)

i undesrtand that i'm rotating only 2 axis and so there is something that must be wrong, but i've got only 2 points with mouse and in 3d space i have 3 coordinates.

please, it requires only two minutes, see the website i've posted, there is an applet with movement i want to simulate.
with dragging mouse (only 2 coordinates) they change rotation in space (3 coordinates), but i don't undestand how

This topic is closed to new replies.

Advertisement