/* four_windows.c display four windows of data, control and reportwindow */ #include #include #include static int surfacew; /* surface display window handle */ static int velocityw; /* velocity vector display window handle */ static int pressurew; /* pressure display window handle */ static int forcew; /* force vector display window handle */ static int controlw; /* control window handle */ static int reportw; /* report window handle */ static float theta = 22.0; /* object rotation about X axis */ static float phi = 16.0; /* object rotation about Z axis */ static float chi = 0.0; /* object rotation about Y axis */ static int width = 300; /* window width */ static int height = 300; /* window height */ static int cwidth = 200; /* control width */ static int grid_on = 0; /* display grid points */ static int cells_on = 0; /* display cells */ static int vectors_on = 0; /* display vectors */ static int xm; /* mouse x */ static int ym; /* mouse y corrected */ static int nx = 4; /* grid sizes */ static int ny = 4; static int nz = 4; static double t = 0.0; /* simulation time */ static double dt = 0.1; /* simulation step time */ /* function prototypes */ static void draw_box(float x1, float x2, float y1, float y2, float z1, float z2); static writeText(GLfloat x, GLfloat y, GLfloat z, GLfloat size, char * msg); static void draw_grid(void); static void draw_cells(void); static void draw_vectors(void); static void display_surface(void); static void display_velocity(void); static void display_pressure(void); static void display_force(void); static void display_control(void); static void update_displays(void); /* all */ static void myinit(void); static void mouse(int btn, int state, int x, int y); static void mouse_control(int btn, int state, int x, int y); static int in_rect(int x, int y, int w, int h); static void keys(unsigned char key, int x, int y); static void reshape(int w, int h); static void controlReshape(int w, int h); /* int main(int argc, char * argv[]); */ static void finish(void); static void draw_box(float x1, float x2, float y1, float y2, float z1, float z2) { /* six faces: x1,y1,z1 x1,y1,z2 x2,y1,z2 x2,y1,z1 */ /* x1,y1,z1 x1,y2,z1 x2,y2,z1 x2,y1,z1 */ /* x1,y1,z1 x1,y2,z1 x1,y2,z2 x1,y1,z2 */ /* x2,y2,z2 x2,y2,z1 x1,y2,z1 x1,y2,z2 */ /* x2,y2,z2 x2,y1,z2 x1,y1,z2 x1,y2,z2 */ /* x2,y2,z2 x2,y1,z2 x2,y1,z1 x2,y2,z1 */ glBegin(GL_POLYGON); /* set color before call */ glVertex3f(x1,y1,z1); glVertex3f(x1,y1,z2); glVertex3f(x2,y1,z2); glVertex3f(x2,y1,z1); glEnd(); glBegin(GL_POLYGON); glVertex3f(x1,y1,z1); glVertex3f(x1,y2,z1); glVertex3f(x2,y2,z1); glVertex3f(x2,y1,z1); glEnd(); glBegin(GL_POLYGON); glVertex3f(x1,y1,z1); glVertex3f(x1,y2,z1); glVertex3f(x1,y2,z2); glVertex3f(x1,y1,z2); glEnd(); glBegin(GL_POLYGON); glVertex3f(x2,y2,z2); glVertex3f(x2,y2,z1); glVertex3f(x1,y2,z1); glVertex3f(x1,y2,z2); glEnd(); glBegin(GL_POLYGON); glVertex3f(x2,y2,z2); glVertex3f(x2,y1,z2); glVertex3f(x1,y1,z2); glVertex3f(x1,y2,z2); glEnd(); glBegin(GL_POLYGON); glVertex3f(x2,y2,z2); glVertex3f(x2,y1,z2); glVertex3f(x2,y1,z1); glVertex3f(x2,y2,z1); glEnd(); } /* end draw_box */ static writeText(GLfloat x, GLfloat y, GLfloat z, GLfloat size, char * msg) { char * p; glPushMatrix(); glLoadIdentity (); glEnable(GL_LINE_SMOOTH); glEnable(GL_BLEND); glTranslatef(x, y, z); glScalef(size/1000.0, size/1000.0, 0.0); for(p=msg; *p; p++) glutStrokeCharacter(GLUT_STROKE_ROMAN, *p); glPopMatrix(); } /* end writeText, may have to reset glEnable's after call */ static void draw_grid(void) { int i, j, k; float x, y, z, stepx, stepy, stepz; glColor3f (0.0, 0.0, 1.0); glPointSize(2.0); stepx = 1.0/(float)nx; stepy = 1.0/(float)ny; stepz = 1.0/(float)nz; for(i=1; ix && xmy && ym