/* for convolution */
#define FILTER_SIZE 7
+static GLint WinWidth = 500, WinHeight = 500;
static GLuint CylinderObj = 0;
static GLuint TeapotObj = 0;
static GLuint Object = 0;
static GLuint BaseTexture, SpecularTexture;
static GLboolean DoSpecTexture = GL_TRUE;
+static GLboolean ButtonDown = GL_FALSE;
+static GLint ButtonX, ButtonY;
+static GLfloat Xrot0, Yrot0;
+
+
/* performance info */
static GLint T0 = 0;
static GLint Frames = 0;
{
GLfloat h = 30.0;
GLfloat w = h * width / height;
+ WinWidth = width;
+ WinHeight = height;
glViewport( 0, 0, width, height );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glMaterialf(GL_FRONT, GL_SHININESS, Shininess);
printf("Shininess = %g\n", Shininess);
break;
+ case 'a':
case ' ':
ToggleAnimate();
break;
}
+static void
+MouseMotion(int x, int y)
+{
+ const float k = 300.0;
+ if (ButtonDown) {
+ float dx = x - ButtonX;
+ float dy = y - ButtonY;
+ Xrot = Xrot0 + k * dy / WinWidth;
+ Yrot = Yrot0 + k * dx / WinHeight;
+ glutPostRedisplay();
+ }
+}
+
+
+static void
+MouseButton(int button, int state, int x, int y)
+{
+ if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) {
+ ButtonDown = GL_TRUE;
+ ButtonX = x;
+ ButtonY = y;
+ Xrot0 = Xrot;
+ Yrot0 = Yrot;
+ }
+ else if (button == GLUT_LEFT_BUTTON && state == GLUT_UP) {
+ ButtonDown = GL_FALSE;
+ }
+}
+
+
static void Init( int argc, char *argv[] )
{
GLboolean convolve = GL_FALSE;
{
glutInit( &argc, argv );
glutInitWindowPosition(0, 0);
- glutInitWindowSize( 500, 500 );
+ glutInitWindowSize(WinWidth, WinHeight);
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
glutKeyboardFunc( Key );
glutSpecialFunc( SpecialKey );
glutDisplayFunc( Display );
+ glutMotionFunc(MouseMotion);
+ glutMouseFunc(MouseButton);
if (Animate)
glutIdleFunc( Idle );