package modeler;


import net.java.games.jogl.*;

import javax.vecmath.*;

public class RotateManip extends Manip {

	public RotateManip(Transformation t) {

	  this.t = t;
  }

  Vector3f tempVec = new Vector3f();
  public void dragged(Vector2f mousePosition, Vector2f mouseDelta) {

	double rotAngle = 180 * mouseDelta.y;
    
	System.out.println("Dragged " + rotAngle);
	
	switch (axisMode) {
	    case PICK_X:
	  	t.R.x += rotAngle;
	      break;
	    case PICK_Y:
	    t.R.y += rotAngle;
	      break;
	    case PICK_Z:
	    t.R.z += rotAngle;
	      break;
	    case PICK_OTHER:
	  	// Implement trackball rotation for extra credit
	      break;
    }
  }

   public void glRender(GLDrawable d, double scale) {

    GL gl = d.getGL();
    gl.glDisable(GL.GL_LIGHTING);
    //gl.glDisable(GL.GL_DEPTH_TEST);

    gl.glPushMatrix();
    glTransformCollapsed(gl, t);

    gl.glScaled(scale, scale, scale);

    gl.glLineWidth(3);
    
    gl.glColor4d(1, 0, 0, 1);
    gl.glLoadName(PICK_X);
    gl.glPushMatrix();
    gl.glRotatef( t.R.z, 0,0,1);
    gl.glRotatef( t.R.y, 0,1,0);
    glRenderCircle(X_AXIS, gl);
    gl.glPopMatrix();
    
    gl.glColor4d(0, 1, 0, 1);
    gl.glLoadName(PICK_Y);
    gl.glPushMatrix();
    gl.glRotatef(t.R.z, 0,0,1);
    glRenderCircle(Y_AXIS, gl);
    gl.glPopMatrix();
    
    gl.glColor4d(0, 0, 1, 1);
    gl.glLoadName(PICK_Z);
    glRenderCircle(Z_AXIS, gl);

    gl.glPopMatrix();
    gl.glLineWidth(1);
    //gl.glEnable(GL.GL_DEPTH_TEST);
  }

}