#include #include #include #include #include #include #include "anaglyph.h" /* Modified by Daniel van Vugt (daniel@computing.edu.au) I have removed all accumulation buffer code, and without needing blending. This works because when you're writing to different colour planes, it's effectively the same as having two separate framebuffers. In fact, blending would just slow it all down and add some ugly bugs. My changes are marked with a "DVV". ----- Anaglyphs implemented in OpenGL without stereo buffer support Adds the two images in the accumulation buffer Note 1. All objects must be drawn as greyscale! 2. This is written for illustrative purposes...not efficiency! */ /* Misc globals */ int debug = FALSE; int fullscreen = FALSE; int currentbutton = -1; float rotatespeed = 0.5; /* Each object can autorotate */ double dtheta = 1.0; /* Camera rotation angle increment */ CAMERA camera; XYZ origin = {0.0,0.0,0.0}; /* Image saving options */ int windowdump = FALSE; int movierecord = FALSE; /* Model types */ #define MESH 1 #define BOX 2 #define SPHERE 3 #define PULSAR 4 #define KNOT 5 #define TRITORUS 6 #define LORENZ 7 int modeltype = MESH; /* Glasses filter types */ #define REDBLUE 1 #define REDGREEN 2 #define REDCYAN 3 #define BLUERED 4 #define GREENRED 5 #define CYANRED 6 int glassestype = REDBLUE; int main(int argc,char **argv) { int i; int mainmenu,modelmenu,speedmenu,cameramenu,glassesmenu; /* Parse the command line arguments */ for (i=1;i 100) glVertex3f((x0-0.95)/5,(y0-1.78)/5,(z0-26.7)/5); } glEnd(); } /* Create the geometry for a tritorus */ void MakeTriTorus(void) { int m = 51; int i,j,k; double u,v,u1,v1,delta=0.001; XYZ p[4],n[4],p1,p2; glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); glColor3f(1.0,1.0,1.0); glBegin(GL_QUADS); for (i=0;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; } } /* Calculate the unit normal at p given two other points p1,p2 on the surface. The normal points in the direction of p1 crossproduct p2 */ 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); }