Beispiel #1
0
void MouseMoveEvent(int x, int y)
{

	if (isStartTrackBall)
	{
		GLfloat theta;
		M3DVector3f p1, p2, n;
		int width = glutGet(GLUT_WINDOW_WIDTH);
		int height = glutGet(GLUT_WINDOW_HEIGHT);

		MousePtToSphereVec(p1, mMouseX, mMouseY, width, height);
		MousePtToSphereVec(p2, x, y, width, height);

		mMouseX = x;
		mMouseY = y;

		m3dNormalizeVector3(p1);
		m3dNormalizeVector3(p2);
		theta = acos(m3dDotProduct3(p1, p2)) ;

		//theta = m3dGetAngleBetweenVectors3(p1, p2);

		m3dCrossProduct3(n, p1, p2);
		m3dNormalizeVector3(n);

		M3DMatrix44f tempRotation;
		m3dLoadIdentity44(tempRotation);
		GLfloat dis = m3dGetDistance3(p1, p2);
		if (dis != 0.0f)
		{
			m3dRotationMatrix44(tempRotation, theta, m3dGetVectorX(n), m3dGetVectorY(n), m3dGetVectorZ(n));
		}
		m3dMatrixMultiply44(mRotation, tempRotation, mRotation);

		glutPostRedisplay();

		
	}
	
}
void Selection::draw_area()
{
	int width = glutGet( GLUT_WINDOW_WIDTH ), height = glutGet( GLUT_WINDOW_HEIGHT );
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
		glLoadIdentity();
		gluOrtho2D(0, width, 0, height);

		glMatrixMode( GL_MODELVIEW );
		glPushMatrix();
			glLoadIdentity();

			/*** 画矩形 ***/
			glColor4f(1.0, 1.0, 0, 0.2);
			glEnable( GL_BLEND );
			glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
			glRectf( m3dGetVectorX(left_bottom), m3dGetVectorY(left_bottom), m3dGetVectorX(right_top), m3dGetVectorY(right_top));
			

			/*** 画矩形虚线 ***/
			glEnable( GL_LINE_STIPPLE );
			glColor4f(1, 0, 0, 0.5);
			glLineStipple(3, 0xAAAA);

			glBegin( GL_LINE_LOOP );
			glVertex2f(m3dGetVectorX(left_bottom), m3dGetVectorY(left_bottom));
			glVertex2f(m3dGetVectorX(right_top), m3dGetVectorY(left_bottom));
			glVertex2f(m3dGetVectorX(right_top), m3dGetVectorY(right_top));
			glVertex2f(m3dGetVectorX(left_bottom), m3dGetVectorY(right_top));
			glEnd();

		glPopMatrix();
	glPopMatrix();
	glDisable( GL_LINE_STIPPLE );
	glDisable( GL_BLEND );
}