Example #1
0
void Window::processMouseActiveMotion(int x, int y)
{
    Vector3 currPoint;
    Vector3 direction;
    float rotAngle;
    
    switch (Movement) {
        case GLUT_LEFT_BUTTON: {   // rotation
            //std::cout << "GLU LEFT BUTTON" << std::endl;
            currPoint = trackBallMapping(x, y); //map mouse to logical sphere location
            currPoint = currPoint.normalize();
            lastPoint = lastPoint.normalize();
            direction = currPoint - lastPoint;
            float velocity = direction.magnitude();
            if (velocity > 0.0001) {
                Vector3 rotAxis;
                rotAxis = lastPoint.cross(currPoint);
                rotAxis = rotAxis.normalize();
//                rotAngle = lastPoint.angle(currPoint);
                rotAngle = velocity * 0.025;
                Matrix4 lol;
                lol.makeRotateArbitrary(rotAxis, rotAngle);
                if (source == 0) {
                    Globals::objdraw->toWorld = lol.multiply(Globals::objdraw->toWorld);
                    //displayPosition();
                } 
            }
            break;
        }
        case GLUT_RIGHT_BUTTON: {   // x/y translation
            //std::cout << "GLU RIGHT BUTTON" << std::endl;
            currPoint = Vector3(x, y, 0);
            direction.set((currPoint[0] - lastPoint[0]) *  0.001,
                          (currPoint[1] - lastPoint[1]) * -0.001, 0);
            
            Matrix4 lol;
            lol.makeTranslate(direction);
            if (source == 0) {
                Globals::objdraw->toWorld = lol.multiply(Globals::objdraw->toWorld);
               // displayPosition();
            }
            
            break;
        }
        case 3:    { // mouse wheel -- scale
            // std::cout << "MOUSE WHEEL" << std::endl;
            currPoint = Vector3(x, y, 0);
            direction.set(0, 0, (currPoint[1] - lastPoint[1]) * -0.001);
            Matrix4 lol;
            lol.makeTranslate(direction);
            if (source == 0) {
                Globals::objdraw->toWorld = lol.multiply(Globals::objdraw->toWorld);
                // displayPosition();
            }

            break;
        }
            
    }
}
Example #2
0
//TODO: Mouse callbacks!
void Window::mouseCallback(int button, int state, int x, int y)
{
    
    lastpoint = trackBallMapping(x, y);
    switch (button){
        case GLUT_LEFT_BUTTON:
            if (state == GLUT_DOWN){
                movement = GLUT_LEFT_BUTTON;
                
            }
            break;
        case GLUT_RIGHT_BUTTON:
            if (state == GLUT_DOWN){
                movement = GLUT_RIGHT_BUTTON;
                
            }
            break;
        case GLUT_MIDDLE_BUTTON:
            if (state == GLUT_DOWN){
                movement = GLUT_MIDDLE_BUTTON;
            }
            break;
            
    }
    
}
Example #3
0
void Window::onLButtonDown(int button, int state, int x, int y) {
	Movement = ROTATE;

	lastPoint = trackBallMapping(x, y);

	glMatrixMode(GL_MODELVIEW);
}
Example #4
0
void Window::processMouse(int button, int state, int x, int y)
{
    
    //Detect the left-button of the mouse being depressed
    if (button == GLUT_LEFT_BUTTON && glutGetModifiers() == GLUT_ACTIVE_CTRL) {         // right mouse -- x/y trans
        lastPoint = Vector3(x, y, 0);
        Movement = GLUT_RIGHT_BUTTON;
    } else if (button == GLUT_LEFT_BUTTON && glutGetModifiers() == GLUT_ACTIVE_SHIFT) { // mouse wheel -- scale
        lastPoint = Vector3(x, y, 0);
        Movement = GLUT_RIGHT_BUTTON + 1;
    } else if (button == GLUT_LEFT_BUTTON && glutGetModifiers() != GLUT_ACTIVE_CTRL && glutGetModifiers() != GLUT_ACTIVE_SHIFT) { // left
            lastPoint = trackBallMapping(x, y);
            Movement = button;
    }
     
}
Example #5
0
void Window::motionTracker(int x, int y) {
	Vector3 direction;
	float rot_angle;
	Vector3 curPoint;

	switch (Movement) {
	case ROTATE:
		curPoint = trackBallMapping(x, y);
		// sphere location.
		direction = curPoint - lastPoint;
		float velocity = direction.magnitude();
		if (velocity > 0.0001) {
			Vector3 rotAxis;
			rotAxis.cross(lastPoint, curPoint);
			rot_angle = velocity * m_ROTSCALE;
			n.identity();
			engine.setMatrix(engine.getMatrix(), engine.getMatrix().multiply(n.rotate(rot_angle, rotAxis)));
		}
		break;
	}

	lastPoint = curPoint;
}
Example #6
0
//TODO: Mouse Motion callbacks!
void Window::motionCallback(int x, int y)
{
    Vector3 direction;
    float rot_angle;
    Vector3 curPoint;
    float velocity;
    Matrix4 move;
    
    curPoint = trackBallMapping(x, y);
    direction = curPoint - lastpoint;
    
    Vector3 forward = Globals::camera->d - Globals::camera->e;
    forward = forward.normalize();
    Vector3 backward = forward.negate();
    
    Vector3 right = forward.cross(Globals::camera->up);
    Vector3 left = right.negate();
    
    Vector3 up = right.cross(forward);
    up = up.normalize();
    
    Vector3 down = up.negate();
    
    Vector3 lookAt = Globals::camera->d - Globals::camera->e;
    
    
    switch (movement) {
        case GLUT_LEFT_BUTTON:
            
            velocity = direction.magnitude();
            if (velocity > 0.0001){
                Vector3 rotAxis;
                rotAxis = lastpoint.cross(curPoint);
                
                rot_angle = asin(rotAxis.magnitude() / (lastpoint.magnitude() * curPoint.magnitude()));
                rot_angle = rot_angle * 3.1415926 / 180.0;
                rotAxis = rotAxis.normalize();
                
                Matrix4 r;
                r = r.makeRotateArbitrary(rotAxis, 16.0 * rot_angle);
                
                Globals::camera->d = Globals::camera->e + r* lookAt;
                
                lastpoint = curPoint;
            }
            Globals::camera->update();
            
            
            break;
            
        case GLUT_RIGHT_BUTTON:
            
            
            if (direction[0] > 0.0){
                Globals::camera->e = Globals::camera->e + right;
                Globals::camera->d = Globals::camera->d + right;
            }
            if (direction[0] < 0.0){
                Globals::camera->e = Globals::camera->e + left;
                Globals::camera->d = Globals::camera->d + left;
            }
            if (direction[1] > 0.0){
                Globals::camera->e = Globals::camera->e + up;
                Globals::camera->d = Globals::camera->d + up;
            }
            if (direction[1] < 0.0){
                Globals::camera->e = Globals::camera->e + down;
                Globals::camera->d = Globals::camera->d + down;
            }
            Globals::camera->update();
            
            break;
            
        case GLUT_MIDDLE_BUTTON:
            if (direction[1] > 0.0){
                Globals::camera->e = Globals::camera->e + forward;
                Globals::camera->d = Globals::camera->d + forward;
            }
            if (direction[1] < 0.0){
                Globals::camera->e = Globals::camera->e + backward;
                Globals::camera->d = Globals::camera->d + backward;
            }
            Globals::camera->update();
            
            break;
            
    }
    
    
}