+void motion(int x, int y) {\r
+ if (moving) {\r
+ angle = angle + (x - startx);\r
+ angle2 = angle2 + (y - starty);\r
+ startx = x;\r
+ starty = y;\r
+ glutPostRedisplay();\r
+ }\r
+ if (lightMoving) {\r
+ lightAngle += (x - lightStartX)/40.0;\r
+ lightHeight += (lightStartY - y)/20.0;\r
+ lightStartX = x;\r
+ lightStartY = y;\r
+ glutPostRedisplay();\r
+ }\r
+}\r
+\r
+/**\r
+ * Recursive function to draw a square by drawing smaller and smaller\r
+ * divisions of the square, determined by drawFloorRecurse.\r
+ * @param recurseLevel Current level of recursion, only pass 0\r
+ * @param x1 top-left x\r
+ * @param z1 top-left z\r
+ * @param x2 bottom-left x\r
+ * @param z2 bottom-left z\r
+ */\r
+void drawSquare(int recurseLevel, float x1, float z1, float x2, float z2) {\r
+\r
+ if ( drawFloorRecurse != recurseLevel ) {\r
+ // Calculate middle points\r
+ float xm = (x1 + x2) / 2.0;\r
+ float zm = (z1 + z2) / 2.0;\r
+\r
+ // Increment recursion level\r
+ int rnew = recurseLevel + 1;\r
+\r
+ // Split into four sub-quads\r
+ drawSquare(rnew, x1, z1, xm, zm);\r
+ drawSquare(rnew, x1, zm, xm, z2);\r
+ drawSquare(rnew, xm, zm, x2, z2);\r
+ drawSquare(rnew, xm, z1, x2, zm);\r
+\r
+ } else {\r
+ // Draw square.\r
+ // **NOTE: Is the polygon facing in the right direction?\r
+ glBegin(GL_QUADS);\r
+ glVertex3f(x1, 0.0, z1);\r
+ glVertex3f(x1, 0.0, z2);\r
+ glVertex3f(x2, 0.0, z2);\r
+ glVertex3f(x2, 0.0, z1);\r
+ glEnd();\r
+ }\r