Jump to content
  • Advertisement
Sign in to follow this  
Wizumwalt

how to rotate from last position?

This topic is 4723 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

My model renders ok now and I seem to have a bit more control w/ my translation and rotations when I drag my mouse around, but what is happening now is ... 1) I click the left mouse button and drag on my model and it rotates. 2) I let up on the left mouse button to stop rotating. 3) I then click again on the canvas to rotate some more ... This is where the problem occurs. My model snaps back to the position it was in when I loaded it (centered around 0, 0, 0), before it starts to rotate again. Meaning I can't do two mouse drags one after the other w/o getting that jerky reset like display. I'm using Java JOGL but I can understand OpenGL written in any other lang as well. --- my display method ... gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // reset the modelview matrix gl.glColor3f(1.0f, 1.0f, 1.0f); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glLoadIdentity(); // viewing transformation glu.gluLookAt(0.0, 0.0, 0.0, 0.0, 0.0, -100.0, 0.0, 1.0, 0.0); // modeling transformation gl.glScalef(xScale, yScale, zScale); gl.glTranslatef(xTrans, yTrans, zTrans); gl.glRotatef(xRot, 1.0f, 0.0f, 0.0f); gl.glRotatef(yRot, 0.0f, 1.0f, 0.0f); gl.glRotatef(zRot, 0.0f, 0.0f, 1.0f); gl.glEnable(GL.GL_BLEND); gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); model.draw(active_id); model.drawInfo(); gl.glDisable(GL.GL_BLEND); --- Any help much appreciated.

Share this post


Link to post
Share on other sites
Advertisement
Are you saving your xRot, yRot, and zRot variables so that upon release of your mouse button, the rotation information is not lost?

Share this post


Link to post
Share on other sites
No, I'm not, and this really has me confused. My current (and messed up) event capture method for mouseDragged and mouseClicked look like the following. I know they are not complete, but I'm confused on adding mouse x and y with angles of rotation.

---
public void mouseClicked(MouseEvent me) {
int x = me.getX(); // this is where the pointer is now
int y = me.getY();

if (SwingUtilities.isLeftMouseButton(me)) {
// not sure what to do when the left mouse button is pushed down
}
}


public void mouseDragged(MouseEvent me) {
int x = me.getX(); // this is where the pointer is now
int y = me.getY();

if (SwingUtilities.isLeftMouseButton(me)) {
yRot = x;
xRot = y;

this.gldrawable.display();
}
}

Share this post


Link to post
Share on other sites
On mouseClicked, save the x and y to other class variables.
On mouseDragged, check the current x and y, subtract the saved x and y, and set the xRot and yRot to the difference.

(That gives you a proper means of setting the rotation; else it just depends on where you put the mouse, not the distance dragged).

On mouseReleased, calculate xRot and yRot as before in mouseDragged, and save that rotation in other class variables. Then you need to go back and factor that in to mouseDragged - the total rotation is the saved rotation from before, plus the distance of movement on the current drag.

Oh, and watch out for gimbal lock :)

Share this post


Link to post
Share on other sites
This just isn't working out right. Here's what I have and still getting pretty much the same results ... which is, when I click and drag, ok, but then click again and the model jumps to a completely different angle. Did I mess up somewhere's from the instructions?


public void mouseClicked(MouseEvent me) {
// saving x, y to class vars
clickedX = me.getX();
clickedY = me.getY();
}

public void mouseDragged(MouseEvent me) {
if (SwingUtilities.isLeftMouseButton(me)) {
// getting current x, y
int currentX = me.getX();
int currentY = me.getY();

// subtracting saved x, y (from the mouseClicked is correct?)
// and saving new rotation
xRot = currentX - clickedX;
yRot = currentY - clickedY;

// factoring in x, y from mouseReleased
xRot += xRotSaved;
yRot += yRotSaved;

this.gldrawable.display();
}
}

public void mouseReleased(MouseEvent me) {
// calculating x, y as before in mouseDragged
int currentX = me.getX();
int currentY = me.getY();

// saved in class vars
xRotSaved = currentX - clickedX;
yRotSaved = currentY - clickedY;
}

Share this post


Link to post
Share on other sites
Quote:
(That gives you a proper means of setting the rotation; else it just depends on where you put the mouse, not the distance dragged).


When I click on the model, drag it, then release the mouse ... I will usually then click on the model again, but not from the same point where I released the mouse. Is that what this is saying/doing?

I need to rotate the model, release the mouse, eat part of my burrito, then go back to my mouse and place it somewhere's on the model, and drag it some more so that the drag looks seamless as if they were both part of the same drag.

Share this post


Link to post
Share on other sites
I hope it's ok to do this. I'm just trying to get my reply back in view so maybe someone can help w/ the problem I've got in this thread.

Any help much appreciated.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I dont know much about GL, but one thing do know from GUI coding is that when your saving your location in mousedragged, that is over writing the previous save of when the mouse is clicked. Typically in a rotation in 3d your going to click and then drag. So saving it again is redundant and might be causing your error -- this code may be executing multiple times while your dragging; Java definition of mouse dragged is as follows: "The "mouse dragged" event. This MouseEvent occurs when the mouse position changes while a mouse button is pressed." -- which to me means that as long as the position is changing the code is re-executed and since your moving it a lot the coordinates arent going anywhere and reseting to zero.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!