00001
00002
00003
00004
00005
00006 #include <stdio.h>
00007 #include <string.h>
00008 #if defined(_WIN32)
00009 #include <windows.h>
00010 #else
00011 #include <strings.h>
00012 #endif
00013 #ifndef __APPLE__
00014 #include <GL/gl.h>
00015 #include <GL/glut.h>
00016 #else
00017 #include <OpenGL/gl.h>
00018 #include <GLUT/glut.h>
00019 #endif
00020 #include <AR/gsub.h>
00021 #include "draw_object.h"
00022 #include "object.h"
00023
00024
00025 GLfloat mat_specular1[] = {0.2, 0.0, 0.0, 1.0};
00026 GLfloat mat_shininess1[] = {50.0};
00027 GLfloat mat_specular2[] = {0.0, 0.0, 0.2, 1.0};
00028 GLfloat mat_shininess2[] = {25.0};
00029
00030 GLfloat mat_ambient1[] = {1.0, 0.0, 0.0, 1.0};
00031 GLfloat mat_ambient2[] = {0.0, 0.0, 1.0, 1.0};
00032 GLfloat mat_flash_ambient1[] = {0.0, 1.0, 0.0, 1.0};
00033
00034 GLfloat mat_flash1[] = {1.0, 0.0, 0.0, 1.0};
00035 GLfloat mat_flash_shiny1[] = {25.0};
00036 GLfloat mat_flash2[] = {0.0, 0.0, 1.0, 1.0};
00037 GLfloat mat_flash_shiny2[] = {50.0};
00038
00039 static int draw_object( char *name, double gl_para[16] );
00040 static void init_lights( void );
00041
00042
00043 int draw( ObjectData_T *object, int objectnum )
00044 {
00045 int i;
00046 double gl_para[16];
00047
00048
00049 for( i = 0; i < objectnum; i++ ) {
00050 if( object[i].visible == 0 ) continue;
00051
00052 argConvGlpara(object[i].trans, gl_para);
00053
00054
00055 draw_object( object[i].name, gl_para );
00056 }
00057
00058 return(0);
00059 }
00060
00061
00062 static int draw_object( char *name, double gl_para[16] )
00063 {
00064 argDrawMode3D();
00065 argDraw3dCamera( 0, 0 );
00066 glDepthFunc(GL_LEQUAL);
00067 glEnable(GL_DEPTH_TEST);
00068
00069
00070 glMatrixMode(GL_MODELVIEW);
00071 glLoadMatrixd( gl_para );
00072 init_lights();
00073
00074
00075
00076
00077 if( strcmp(name, "torus") == 0 ) {
00078
00079 glEnable(GL_LIGHTING);
00080 glEnable(GL_LIGHT0);
00081 glMaterialfv(GL_FRONT, GL_SPECULAR, mat_flash1);
00082 glMaterialfv(GL_FRONT, GL_SHININESS, mat_flash_shiny1);
00083 glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient1);
00084
00085
00086 glMatrixMode(GL_MODELVIEW);
00087 glTranslatef( 0.0, 0.0, 10.0 );
00088 glutSolidTorus(10.0, 40.0, 24, 24);
00089 glDisable( GL_LIGHTING );
00090 }
00091 else if( strcmp(name, "sphere") == 0 ) {
00092 glEnable(GL_LIGHTING);
00093 glEnable(GL_LIGHT0);
00094 glMaterialfv(GL_FRONT, GL_SPECULAR, mat_flash1);
00095 glMaterialfv(GL_FRONT, GL_SHININESS, mat_flash_shiny1);
00096 glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient1);
00097
00098
00099 glMatrixMode(GL_MODELVIEW);
00100 glTranslatef( 0.0, 0.0, 40.0 );
00101 glutSolidSphere(40.0, 24, 24);
00102 glDisable( GL_LIGHTING );
00103 }
00104 else if( strcmp(name, "cube") == 0 ) {
00105 glEnable(GL_LIGHTING);
00106 glEnable(GL_LIGHT0);
00107 glMaterialfv(GL_FRONT, GL_SPECULAR, mat_flash2);
00108 glMaterialfv(GL_FRONT, GL_SHININESS, mat_flash_shiny2);
00109 glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient2);
00110
00111 glMatrixMode(GL_MODELVIEW);
00112 glTranslatef( 0.0, 0.0, 25.0 );
00113 glutSolidCube(50.0);
00114 glDisable( GL_LIGHTING );
00115 }
00116 else if( strcmp(name, "cone") == 0 ) {
00117 glEnable(GL_LIGHTING);
00118 glEnable(GL_LIGHT0);
00119 glMaterialfv(GL_FRONT, GL_SPECULAR, mat_flash1);
00120 glMaterialfv(GL_FRONT, GL_SHININESS, mat_flash_shiny1);
00121 glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient1);
00122
00123 glMatrixMode(GL_MODELVIEW);
00124 glutSolidCone(25.0, 50.0, 20, 24);
00125 glDisable( GL_LIGHTING );
00126 }
00127 else {
00128 printf("unknown object type!!\n");
00129 }
00130
00131 glDisable( GL_DEPTH_TEST );
00132
00133 return 0;
00134 }
00135
00136
00137 static void init_lights( void )
00138 {
00139 GLfloat light_position[] = {0.0,-200.0,0.0,0.0};
00140 GLfloat ambi[] = {0.1, 0.1, 0.1, 0.1};
00141 GLfloat lightZeroColor[] = {0.9, 0.9, 0.9, 0.1};
00142
00143 glLightfv(GL_LIGHT0, GL_POSITION, light_position);
00144 glLightfv(GL_LIGHT0, GL_AMBIENT, ambi);
00145 glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor);
00146 }