📄 table.c
字号:
} glEnd(); glBegin(GL_TRIANGLES); autonormalize_triangle(p[1],p[10],p[0],order); autonormalize_triangle(p[2],p[3],p[11],order); autonormalize_triangle(p[0],p[10],p[8],order); autonormalize_triangle(p[0],p[5],p[1],order); autonormalize_triangle(p[0],p[4],p[5],order); autonormalize_triangle(p[3],p[9],p[11],order); autonormalize_triangle(p[3],p[2],p[6],order); autonormalize_triangle(p[3],p[6],p[7],order); glEnd();}#define TABLETEXCOORD_X(x,y) (-0.7+(y+TABLE_L/2.0)/TABLE_L*2.4-0.2+(x+TABLE_W/2.0)/TABLE_W*0.4)#define TABLETEXCOORD_Y(x,y) (-0.2+(x+TABLE_W/2.0)/TABLE_W*1.4) /* holes-tuch */void my_HoleTuch( int xfact, int yfact ){ int i; double x,y; double edge_xyoffs; edge_xyoffs = HOLE1_R*SQR2-BANDE_D;// edge_xyoffs = HOLE1_R*SQR2-BANDE_D;HOLE1_XYOFFS; glBegin(GL_TRIANGLES); x=-TABLE_W/2.0-HOLE1_XYOFFS+HOLE1_R/SQR2; y=-TABLE_L/2.0-HOLE1_XYOFFS+HOLE1_R/SQR2; x*=xfact; y*=yfact; glTexCoord2f( TABLETEXCOORD_X(x,y), TABLETEXCOORD_Y(x,y) ); glNormal3f( 0.0, 0.0, 1.0 ); glVertex3f(x,y,-BALL_D/2.0); x=-TABLE_W/2.0-BANDE_D; y=-TABLE_L/2.0+edge_xyoffs; x*=xfact; y*=yfact; glTexCoord2f( TABLETEXCOORD_X(x,y), TABLETEXCOORD_Y(x,y) ); glNormal3f( 0.0, 0.0, 1.0 ); glVertex3f(x,y,-BALL_D/2.0); x=-TABLE_W/2.0-BANDE_D*BANDE_D2RATIO; y=-TABLE_L/2.0+edge_xyoffs+BANDE_D*HOLE1_TAN; x*=xfact; y*=yfact; glTexCoord2f( TABLETEXCOORD_X(x,y), TABLETEXCOORD_Y(x,y) ); glNormal3f( 0.0, 0.0, 1.0 ); glVertex3f(x,y,-BALL_D/2.0); x=-TABLE_W/2.0-HOLE1_XYOFFS+HOLE1_R/SQR2; y=-TABLE_L/2.0-HOLE1_XYOFFS+HOLE1_R/SQR2; x*=xfact; y*=yfact; glTexCoord2f( TABLETEXCOORD_X(x,y), TABLETEXCOORD_Y(x,y) ); glNormal3f( 0.0, 0.0, 1.0 ); glVertex3f(x,y,-BALL_D/2.0); x=-TABLE_W/2.0+edge_xyoffs+BANDE_D*HOLE1_TAN; y=-TABLE_L/2.0-BANDE_D*BANDE_D2RATIO; x*=xfact; y*=yfact; glTexCoord2f( TABLETEXCOORD_X(x,y), TABLETEXCOORD_Y(x,y) ); glNormal3f( 0.0, 0.0, 1.0 ); glVertex3f(x,y,-BALL_D/2.0); x=-TABLE_W/2.0+edge_xyoffs; y=-TABLE_L/2.0-BANDE_D; x*=xfact; y*=yfact; glTexCoord2f( TABLETEXCOORD_X(x,y), TABLETEXCOORD_Y(x,y) ); glNormal3f( 0.0, 0.0, 1.0 ); glVertex3f(x,y,-BALL_D/2.0); glEnd();#define HOLE1_SEGNR_4 8 glBegin(GL_TRIANGLE_FAN); x=-TABLE_W/2.0-BANDE_D; y=-TABLE_L/2.0+edge_xyoffs; x*=xfact; y*=yfact; glTexCoord2f( TABLETEXCOORD_X(x,y), TABLETEXCOORD_Y(x,y) ); glNormal3f( 0.0, 0.0, 1.0 ); glVertex3f(x,y,-BALL_D/2.0); for(i=0;i<HOLE1_SEGNR_4+1;i++){ double phi; phi=M_PI/4.0+(double)i*M_PI/HOLE1_SEGNR_4/2.0; x=-TABLE_W/2.0-HOLE1_XYOFFS+HOLE1_R*cos(phi); y=-TABLE_L/2.0-HOLE1_XYOFFS+HOLE1_R*sin(phi); x*=xfact; y*=yfact; glTexCoord2f( TABLETEXCOORD_X(x,y), TABLETEXCOORD_Y(x,y) ); glNormal3f( 0.0, 0.0, 1.0 ); glVertex3f(x,y,-BALL_D/2.0); } glEnd(); glBegin(GL_TRIANGLE_FAN); x=-TABLE_W/2.0+edge_xyoffs; y=-TABLE_L/2.0-BANDE_D; x*=xfact; y*=yfact; glTexCoord2f( TABLETEXCOORD_X(x,y), TABLETEXCOORD_Y(x,y) ); glNormal3f( 0.0, 0.0, 1.0 ); glVertex3f(x,y,-BALL_D/2.0); for(i=HOLE1_SEGNR_4;i>=0;i--){ double phi; phi=M_PI/4.0+(double)i*M_PI/HOLE1_SEGNR_4/2.0; x=-TABLE_W/2.0-HOLE1_XYOFFS+HOLE1_R*sin(phi); y=-TABLE_L/2.0-HOLE1_XYOFFS+HOLE1_R*cos(phi); x*=xfact; y*=yfact; glTexCoord2f( TABLETEXCOORD_X(x,y), TABLETEXCOORD_Y(x,y) ); glNormal3f( 0.0, 0.0, 1.0 ); glVertex3f(x,y,-BALL_D/2.0); } glEnd(); glBegin(GL_QUAD_STRIP); for(i=-HOLE1_SEGNR_4;i<HOLE1_SEGNR_4+1;i++){ double phi; phi=M_PI/4.0+(double)i*M_PI/HOLE1_SEGNR_4/2.0; x=-TABLE_W/2.0-HOLE1_XYOFFS+HOLE1_R*cos(phi); y=-TABLE_L/2.0-HOLE1_XYOFFS+HOLE1_R*sin(phi); x*=xfact; y*=yfact; glTexCoord2f( TABLETEXCOORD_X(x,y), TABLETEXCOORD_Y(x,y) ); glNormal3f( 0.0, 0.0, 1.0 ); glVertex3f(x,y,-BALL_D/2.0); x=-TABLE_W/2.0-HOLE1_XYOFFS+(HOLE1_R-0.005)*cos(phi); y=-TABLE_L/2.0-HOLE1_XYOFFS+(HOLE1_R-0.005)*sin(phi); x*=xfact; y*=yfact; glTexCoord2f( TABLETEXCOORD_X(x,y), TABLETEXCOORD_Y(x,y) ); glNormal3f( -cos(phi)*xfact, -sin(phi)*yfact, 0.0 ); glVertex3f(x,y,-BALL_D/2.0-0.005); } glEnd();}void grayen_color( GLfloat * col ){ GLfloat c; c=(col[0]+col[1]+col[2])/3.0; col[0]=c; col[1]=c; col[2]=c;}int create_table( int reflect_bind, BordersType *borders, int carambol ){ static int init = 0; static int bumpref_init = 0; static int bump_init = 0; static int bump_cloth_init = 0; static BumpRefType bumpref; static BumpRefType bumponly; static BumpRefType bumpcloth; static int table_obj=-1; static int frametexbind=-1; static int tabletexbind=-1; static int clothtexbind=-1; int frametexw,frametexh; int tabletexw,tabletexh; int clothtexw,clothtexh; int depth; char * frametexdata; char * tabletexdata; char * clothtexdata; float balld = BALL_D; float tablew = TABLE_W; float tablel = TABLE_L; float tableh = TABLE_H; float bande_d = BANDE_D; float cm = 0.01; // cm double hole_r1,hole_r2, edge_xyoffs; GLfloat tab_col_spec[4] = {0.0, 0.0, 0.0, 0.0}; GLfloat tab_col_diff[4] = {0.05, 0.4, 0.13, 1.0}; GLfloat tab_col_amb [4]; GLfloat wood_col_spec[4] = {0.7, 0.7, 0.7, 1.0}; GLfloat wood_col_spec_null[4] = {0.0, 0.0, 0.0, 1.0}; GLfloat wood_col_diff[4] = {0.25, 0.08, 0.02, 1.0}; GLfloat wood_col_diff2[4] = {0.7, 0.7, 0.7, 1.0}; GLfloat wood_col_diff3[4] = {0.07, 0.07, 0.07, 1.0}; GLfloat wood_col_amb [4]; GLfloat wood_col_amb2 [4]; GLfloat wood_col_amb3 [4]; GLfloat wood_col_shin = 100.0;// GLfloat dia_col_spec[4] = {1.0, 0.9, 0.4, 1.0}; GLfloat dia_col_spec[4] = {0.5, 0.5, 0.5, 1.0}; GLfloat dia_col_diff[4] = {0.8, 0.7, 0.1, 1.0}; GLfloat dia_col_amb [4]; GLfloat dia_col_shin = 100.0; GLfloat bumpers_col_spec[4] = {1.0, 1.0, 1.0, 1.0}; GLfloat bumpers_col_diff[4] = {0.3, 0.3, 0.3, 1.0}; GLfloat bumpers_col_amb [4]; GLfloat bumpers_col_shin = 100.0; GLfloat hole_col_spec[4] = {0.6, 0.6, 0.6, 0.6}; GLfloat hole_col_diff[4] = {0.2, 0.2, 0.2, 1.0}; GLfloat hole_col_amb [4]; GLfloat hole_col_shin = 1000.0; GLfloat t_gen_params[] = {8.0,0.0,0.0,0.0}; GLfloat s_gen_params[] = {0.0,1.0,0.0,0.0};// GLfloat s_gen_params2[] = {1.0,0.0,0.0,0.0};// GLfloat t_gen_params2[] = {0.0,8.0,0.0,0.0}; int imax,jmax,i,j,k,l; float area_w,area_l; /* the main area */ edge_xyoffs = HOLE1_R*SQR2-BANDE_D;#define TABLE_COLOR options_table_color#define DIAMOND_COLOR options_diamond_color#define FRAME_COLOR options_frame_color tab_col_diff[0]=(double)((TABLE_COLOR>>16) & 0xFF)/255.0; tab_col_diff[1]=(double)((TABLE_COLOR>> 8) & 0xFF)/255.0; tab_col_diff[2]=(double)((TABLE_COLOR>> 0) & 0xFF)/255.0; tab_col_diff[3]=1.0-(double)((TABLE_COLOR>>24) & 0xFF)/255.0; dia_col_diff[0]=(double)((DIAMOND_COLOR>>16) & 0xFF)/255.0; dia_col_diff[1]=(double)((DIAMOND_COLOR>> 8) & 0xFF)/255.0; dia_col_diff[2]=(double)((DIAMOND_COLOR>> 0) & 0xFF)/255.0; dia_col_diff[3]=1.0-(double)((DIAMOND_COLOR>>24) & 0xFF)/255.0; wood_col_diff[0]=(double)((FRAME_COLOR>>16) & 0xFF)/255.0; wood_col_diff[1]=(double)((FRAME_COLOR>> 8) & 0xFF)/255.0; wood_col_diff[2]=(double)((FRAME_COLOR>> 0) & 0xFF)/255.0; wood_col_diff[3]=1.0-(double)((FRAME_COLOR>>24) & 0xFF)/255.0; if(options_rgstereo_on){ tab_col_diff[0]=0.533; tab_col_diff[1]=0.533; tab_col_diff[2]=0.533; grayen_color(dia_col_diff); } if( frametexbind > 0 ) glDeleteTextures( 1, &frametexbind ); if( options_frame_tex ) { glGenTextures(1,&frametexbind); load_png("table-frame.png",&frametexw,&frametexh,&depth,&frametexdata); glBindTexture(GL_TEXTURE_2D,frametexbind); gluBuild2DMipmaps(GL_TEXTURE_2D, 3, frametexw, frametexh, GL_RGB, GL_UNSIGNED_BYTE, frametexdata); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, options_tex_min_filter); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, options_tex_mag_filter); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); free( frametexdata ); } else { frametexbind=0; } if( tabletexbind > 0 ) glDeleteTextures( 1, &tabletexbind ); if( options_table_tex ) { glGenTextures(1,&tabletexbind); load_png("tabletex_fB_256x256.png",&tabletexw,&tabletexh,&depth,&tabletexdata);// load_png("cloth.png",&tabletexw,&tabletexh,&depth,&tabletexdata);// load_png("table-frame.png",&tabletexw,&tabletexh,&depth,&tabletexdata); glBindTexture(GL_TEXTURE_2D,tabletexbind); gluBuild2DMipmaps(GL_TEXTURE_2D, 1, tabletexw, tabletexh, GL_LUMINANCE, GL_UNSIGNED_BYTE, tabletexdata); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, options_tex_min_filter); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, options_tex_mag_filter); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); free( tabletexdata ); } else { tabletexbind=0; } if( clothtexbind > 0 ) glDeleteTextures( 1, &clothtexbind ); if( options_cloth_tex ) { glGenTextures(1,&clothtexbind); load_png("cloth.png",&clothtexw,&clothtexh,&depth,&clothtexdata);// load_png("cloth.png",&tabletexw,&tabletexh,&depth,&tabletexdata);// load_png("table-frame.png",&tabletexw,&tabletexh,&depth,&tabletexdata); glBindTexture(GL_TEXTURE_2D,clothtexbind); gluBuild2DMipmaps(GL_TEXTURE_2D, 1, clothtexw, clothtexh, GL_LUMINANCE, GL_UNSIGNED_BYTE, clothtexdata); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, options_tex_min_filter); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, options_tex_mag_filter); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); free( clothtexdata ); } else { clothtexbind=0; } for(i=0;i<3;i++) tab_col_amb[i]=tab_col_diff[i]*0.5; for(i=0;i<3;i++) dia_col_amb[i]=dia_col_diff[i]*0.5; for(i=0;i<3;i++) bumpers_col_amb[i]=bumpers_col_diff[i]*0.5; for(i=0;i<3;i++) hole_col_amb[i]=hole_col_diff[i]*0.5; for(i=0;i<3;i++) wood_col_amb[i]=wood_col_diff[i]*0.5; for(i=0;i<3;i++) wood_col_amb2[i]=wood_col_diff2[i]*0.43; for(i=0;i<3;i++) wood_col_amb3[i]=0.0;// for(i=0;i<3;i++) dia_col_spec[i]=dia_col_diff[i]*1.0; /* initialize bumpref setup */ if(!carambol){ if( options_bumpref && extension_multitexture && extension_cubemap && extension_rc_NV && extension_ts_NV && extension_vp_NV && !bumpref_init ) { bumpref = bumpref_setup_vp_ts_rc( "bumpref.png", 0.008, /* bump map */ "posx.png", "posy.png", "posz.png", "negx.png", "negy.png", "negz.png", /* cube map */ 0.00001f, /* z-shift */ 1, /* use HILO normals */ 1 /* gen tex coords in vertex program */ ); bumpref_init = 1; } } if(options_bumpwood && extension_multitexture && extension_rc_NV && extension_vp_NV && !bump_init ){ DPRINTF("setting up wood frame bumpmaps\n"); //bumponly = bump_setup_vp_rc("cloth-col.png",0.02,0); bumponly = bump_setup_vp_rc("table-frame.png",0.007,0); bump_init = 1; }/* if(options_bumpwood && extension_multitexture && extension_rc_NV && extension_vp_NV && !bump_cloth_init ){ DPRINTF("setting up wood frame bumpmaps\n");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -