#include #include #include #include #include #include "skyvision.h" /* Experiment with skyvision projections */ /* Flags */ int debug = FALSE; int windowdump = FALSE; int showconstruction = FALSE; int currentbutton = -1; double rotatespeed = 1; double dtheta = 1; CAMERA camera; XYZ origin = {0.0,0.0,0.0}; double cuberange = 1.5; PIXELA thetex[5][512][512]; #define FLAT 1 #define ANGLE 2 #define SHARP 3 int facemode = ANGLE; #define MESH 1 #define CUBE 2 #define SPHERE 3 #define RANDOM 4 int modeltype = SPHERE; #define FRONT 1 #define RIGHT 2 #define LEFT 3 #define TOP 4 #define BOTTOM 5 #define ALL 6 int viewtype = ALL; int main(int argc,char **argv) { int i; int mainmenu,modelmenu,viewmenu,facemenu; /* Parse the command line arguments */ for (i=1;i 0) dx = 1; if (dy < 0) dy = -1; else if (dy > 0) dy = 1; if (currentbutton == GLUT_LEFT_BUTTON) RotateCamera(-dx,dy,0); else if (currentbutton == GLUT_MIDDLE_BUTTON) RotateCamera(0,0,dx); xlast = x; ylast = y; } /* Normalise a vector */ void Normalise(XYZ *p) { double length; length = sqrt(p->x * p->x + p->y * p->y + p->z * p->z); if (length != 0) { p->x /= length; p->y /= length; p->z /= length; } else { p->x = 0; p->y = 0; p->z = 0; } } XYZ CrossProduct(XYZ p1,XYZ p2) { XYZ p; p.x = p1.y * p2.z - p1.z * p2.y; p.y = p1.z * p2.x - p1.x * p2.z; p.z = p1.x * p2.y - p1.y * p2.x; return(p); } XYZ CalcNormal(XYZ p,XYZ p1,XYZ p2) { XYZ n,pa,pb; pa.x = p1.x - p.x; pa.y = p1.y - p.y; pa.z = p1.z - p.z; pb.x = p2.x - p.x; pb.y = p2.y - p.y; pb.z = p2.z - p.z; Normalise(&pa); Normalise(&pb); n.x = pa.y * pb.z - pa.z * pb.y; n.y = pa.z * pb.x - pa.x * pb.z; n.z = pa.x * pb.y - pa.y * pb.x; Normalise(&n); return(n); } void CreateSphere(XYZ c,double r,int n) { int i,j; double t1,t2,t3; COLOUR colour = {0.0,0.0,0.0}; XYZ e,p; glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); glLineWidth(3.0); for (j=0;j