/* table.c ** ** create the billard-table display lists ** Copyright (C) 2001 Florian Berger ** Email: harpin_floh@yahoo.de, florian.berger@jk.uni-linz.ac.at ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License Version 2 as ** published by the Free Software Foundation; ** ** This program is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with this program; if not, write to the Free Software ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ** */ #include #include #include #include #include #include "billard.h" #include "table.h" #include "options.h" #include "png_loader.h" #include "bumpref.h" void my_glBox( float x1, float y1, float z1, float x2, float y2, float z2 ) { float dummy; if( x1 > x2 ){ dummy=x1; x1=x2; x2=dummy; } if( y1 > y2 ){ dummy=y1; y1=y2; y2=dummy; } if( z1 > z2 ){ dummy=z1; z1=z2; z2=dummy; } glBegin(GL_QUADS); glNormal3f( 0.0, -1.0, 0.0 ); glVertex3f(x1,y1,z1); glVertex3f(x1,y1,z2); glVertex3f(x2,y1,z2); glVertex3f(x2,y1,z1); glNormal3f( 1.0, 0.0, 0.0 ); glVertex3f(x2,y1,z1); glVertex3f(x2,y1,z2); glVertex3f(x2,y2,z2); glVertex3f(x2,y2,z1); glNormal3f( 0.0, 1.0, 0.0 ); glVertex3f(x2,y2,z1); glVertex3f(x2,y2,z2); glVertex3f(x1,y2,z2); glVertex3f(x1,y2,z1); glNormal3f( -1.0, 0.0, 0.0 ); glVertex3f(x1,y2,z1); glVertex3f(x1,y2,z2); glVertex3f(x1,y1,z2); glVertex3f(x1,y1,z1); glNormal3f( 0.0, 0.0, -1.0 ); glVertex3f(x1,y1,z1); glVertex3f(x2,y1,z1); glVertex3f(x2,y2,z1); glVertex3f(x1,y2,z1); glNormal3f( 0.0, 0.0, 1.0 ); glVertex3f(x1,y1,z2); glVertex3f(x1,y2,z2); glVertex3f(x2,y2,z2); glVertex3f(x2,y1,z2); glEnd(); } void autonormalize_quad( VMvect v1, VMvect v2, VMvect v3, VMvect v4, int order ) { VMvect n; n=vec_unit(vec_cross(vec_diff(v2,v1),vec_diff(v3,v1))); glNormal3f( n.x, n.y, n.z ); if( !order ) { glVertex3f(v4.x,v4.y,v4.z); glVertex3f(v3.x,v3.y,v3.z); glVertex3f(v2.x,v2.y,v2.z); glVertex3f(v1.x,v1.y,v1.z); } else { glVertex3f(v1.x,v1.y,v1.z); glVertex3f(v2.x,v2.y,v2.z); glVertex3f(v3.x,v3.y,v3.z); glVertex3f(v4.x,v4.y,v4.z); } } void autonormalize_triangle( VMvect v1, VMvect v2, VMvect v3, int order ) { VMvect n; n=vec_unit(vec_cross(vec_diff(v2,v1),vec_diff(v3,v1))); if( !order ) { glNormal3f( n.x, n.y, n.z ); glVertex3f(v3.x,v3.y,v3.z); glNormal3f( n.x, n.y, n.z ); glVertex3f(v2.x,v2.y,v2.z); glNormal3f( n.x, n.y, n.z ); glVertex3f(v1.x,v1.y,v1.z); } else { glNormal3f( n.x, n.y, n.z ); glVertex3f(v1.x,v1.y,v1.z); glNormal3f( n.x, n.y, n.z ); glVertex3f(v2.x,v2.y,v2.z); glNormal3f( n.x, n.y, n.z ); glVertex3f(v3.x,v3.y,v3.z); } } void autonormalize_triangle_round( VMvect v1, VMvect v2, VMvect v3, int order, double round ) { VMvect n0,c,n; n0=vec_cross(vec_diff(v2,v1),vec_diff(v3,v1)); c=tri_center(v1,v2,v3); if( !order ) { n=vec_unit(vec_add(n0,vec_scale(vec_diff(v3,c),round))); glNormal3f( n.x, n.y, n.z ); glVertex3f(v3.x,v3.y,v3.z); n=vec_unit(vec_add(n0,vec_scale(vec_diff(v2,c),round))); glNormal3f( n.x, n.y, n.z ); glVertex3f(v2.x,v2.y,v2.z); n=vec_unit(vec_add(n0,vec_scale(vec_diff(v1,c),round))); glNormal3f( n.x, n.y, n.z ); glVertex3f(v1.x,v1.y,v1.z); } else { n=vec_unit(vec_add(n0,vec_scale(vec_diff(v1,c),round))); glNormal3f( n.x, n.y, n.z ); glVertex3f(v1.x,v1.y,v1.z); n=vec_unit(vec_add(n0,vec_scale(vec_diff(v2,c),round))); glNormal3f( n.x, n.y, n.z ); glVertex3f(v2.x,v2.y,v2.z); n=vec_unit(vec_add(n0,vec_scale(vec_diff(v3,c),round))); glNormal3f( n.x, n.y, n.z ); glVertex3f(v3.x,v3.y,v3.z); } } void my_Diamondxy( float wx, float wy, float h, int order ) { VMvect p[10]; p[3] = vec_xyz( -wx, 0.0, 0.0 ); p[2] = vec_xyz( 0.0, wy, 0.0 ); p[1] = vec_xyz( wx, 0.0, 0.0 ); p[0] = vec_xyz( 0.0, -wy, 0.0 ); p[4] = vec_xyz( 0.0, 0.0, h ); glBegin(GL_TRIANGLES); autonormalize_triangle_round(p[0],p[1],p[4],order,-0.002); autonormalize_triangle_round(p[1],p[2],p[4],order,-0.002); autonormalize_triangle_round(p[2],p[3],p[4],order,-0.002); autonormalize_triangle_round(p[3],p[0],p[4],order,-0.002); glEnd(); } void my_Rectxy( float x1, float y1, float z1, /* inside up */ float x2, float y2, float z2, int fall_x, int order ) /* outside down */ { VMvect p[10]; if(fall_x){ p[0]=vec_xyz(x1,y1,z1); p[1]=vec_xyz(x1,y2,z1); p[2]=vec_xyz(x2,y2,z2); p[3]=vec_xyz(x2,y1,z2); glBegin(GL_QUADS); autonormalize_quad(p[0],p[1],p[2],p[3],order); glEnd(); } else { p[0]=vec_xyz(x1,y1,z1); p[1]=vec_xyz(x1,y2,z2); p[2]=vec_xyz(x2,y2,z2); p[3]=vec_xyz(x2,y1,z1); glBegin(GL_QUADS); autonormalize_quad(p[3],p[2],p[1],p[0],!order); glEnd(); } } double r1func( double phi ) { double phi1, rval; // return(HOLE1_W/SQR2); // return(HOLE1_W/SQR2+(1.0-pow((phi-M_PI/4.0)/M_PI*4.0,2))*0.02); // return(HOLE1_R*SQR2+(1.0-pow((phi-M_PI/4.0)/M_PI*4.0,2))*0.03); phi1=atan(HOLE1_XYOFFS/(HOLE1_R*SQR2+HOLE1_XYOFFS)); if(phiM_PI/2.0-phi1){ rval=HOLE1_R/cos(M_PI/2.0-phi+M_PI/4.0); } else { rval=HOLE1_R/cos(phi1+M_PI/4.0)+0.7*HOLE1_R*sin((phi-phi1)/(M_PI/2-phi1-phi1)*M_PI); } return(rval); } double r2func( double phi ) { double phi1, rval; // return(HOLE1_W/SQR2+FRAME_D-BANDE_D); // return(HOLE1_R*SQR2-BANDE_D+FRAME_D); phi1=M_PI/8.0; if(phiM_PI/2.0-phi1){ rval=(HOLE1_R*SQR2-BANDE_D+FRAME_D)/cos(M_PI/2.0-phi); } else { rval=(HOLE1_R*SQR2-BANDE_D+FRAME_D)/cos(phi1); } return(rval); } void my_Edge( int segnr, double (*r1)(double), double (*r2)(double), int order ) /* edge shows to positive x,y direction*/ { int i; double phi1,phi2,dphi1,dphi2; VMvect n00,n10,n20,n30,n40,n0,n1,n2,n3,n4,n5,n6,n7,n8,n9,v0,v1,v2,v3,v4,v5,v6,v7,v8,v9, v8_2,v8_3, v4_2,v4_3; n00 = vec_xyz(-1,0,0); n10 = vec_xyz(0,0,1); n20 = vec_unit(vec_xyz(FRAME_DH,0,FRAME_D-BANDE_D-FRAME_PHASE)); n30 = vec_unit(vec_xyz(FRAME_H-FRAME_PHASE,0,-FRAME_PHASE)); n40 = vec_unit(vec_xyz(FRAME_H-FRAME_PHASE,0,-FRAME_PHASE)); for(i=0;i=1.0 ){ return 0.0; // return HOLE2_XYOFFS-BANDE_D; } else { return( HOLE2_XYOFFS-BANDE_D+sqrt(1.0-y*y)*HOLE2_R ); } } #define nonconst_step 1 void my_Cover( int segnr, double (*r1)(double), double l, int order, double endtan, double tex_x, double tex_y ) /* edge shows to pos x,y direction*/ { int i; double y1,y2; double tan1, tan2; VMvect n1,n2,n3,n4,v1,v2,v3,v4,v5,v6,v7,v8, v4_2,v4_3, v8_2,v8_3; double r2; r2 = FRAME_D-BANDE_D; n1 = vec_unit(vec_xyz(0,0,1)); n2 = vec_unit(vec_xyz(FRAME_DH/(FRAME_D-BANDE_D-FRAME_PHASE),0,1)); n3 = vec_unit(vec_xyz(FRAME_H-FRAME_PHASE,0,-FRAME_PHASE)); n4 = vec_unit(vec_xyz(FRAME_H-FRAME_PHASE,0,-FRAME_PHASE)); for(i=0;i=0.15 && y<0.5){ return( ampl*(0.5+0.5*cos(4.0*M_PI*(y-0.15)/0.35*0.25)) ); }else if(y>=0.5 && y<0.75){ return( 0.7*ampl-0.7*ampl*cos(2.0*M_PI*(y-0.5)) ); }else if(y>=0.75 && y<=1.0){ return( 0.7*ampl-0.7*ampl*sin(3.7*M_PI*(y-0.75)) ); } return( 0.0 ); /* if(y>0) return( +0.02*sin(10.0*M_PI/4.0*y) ); else return( -0.02*sin(10.0*M_PI/4.0*y) );*/ } void my_Cover2func( int segnr, double (*r1)(double), double (*r2)(double), double l, int order, double endtan ) /* edge shows to pos x,y direction*/ { int i; double y1,y2; double tan1, tan2; VMvect n1,n2,n3,n4,v1,v2,v3,v4,v5,v6,v7,v8, v4_2,v4_3, v8_2,v8_3; double r2_1,r2_2; double txfact=0.75; double tyfact=6.0; n1 = vec_unit(vec_xyz(0,0,1)); n2 = vec_unit(vec_xyz(FRAME_DH/(FRAME_D-BANDE_D-FRAME_PHASE),0,1)); n3 = vec_unit(vec_xyz(FRAME_H-FRAME_PHASE,0,-FRAME_PHASE)); n4 = vec_unit(vec_xyz(FRAME_H-FRAME_PHASE,0,-FRAME_PHASE)); for(i=0;i x * * * * 4 8 9 7 * * 0 \ / 3 * * \5_______________6/ * * 1 2 */ float dummy; VMvect p[10]; p[0]=vec_xyz(x1-(y2-y1)*tan1,y2,z1+FRAME_DH); // p[1]=vec_xyz(x1,y1,z1-(z1-z2)*0.1); // p[2]=vec_xyz(x2,y1,z1-(z1-z2)*0.1); p[1]=vec_xyz(x1,y1,z1); p[2]=vec_xyz(x2,y1,z1); p[3]=vec_xyz(x2+(y2-y1)*tan2,y2,z1+FRAME_DH); p[4]=vec_xyz(x1-(y2-y1)*tan1,y2,z2); p[5]=vec_xyz(x1-(y2-y1)*BANDE_D2RATIO*tan1,y1+(y2-y1)*BANDE_D2RATIO,z2); p[6]=vec_xyz(x2+(y2-y1)*BANDE_D2RATIO*tan2,y1+(y2-y1)*BANDE_D2RATIO,z2); p[7]=vec_xyz(x2+(y2-y1)*tan2,y2,z2); p[8]=vec_xyz(x1,y2,z1+FRAME_DH); p[9]=vec_xyz(x2,y2,z1+FRAME_DH); if( x1 > x2 ){ dummy=x1; x1=x2; x2=dummy; } if( y1 > y2 ){ dummy=y1; y1=y2; y2=dummy; } if( z1 > z2 ){ dummy=z1; z1=z2; z2=dummy; } glBegin(GL_QUADS); autonormalize_quad(p[1],p[2],p[9],p[8],order); autonormalize_quad(p[5],p[6],p[2],p[1],order); glEnd(); glBegin(GL_TRIANGLES); autonormalize_triangle(p[0],p[1],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[2],order); autonormalize_triangle(p[3],p[2],p[6],order); autonormalize_triangle(p[3],p[6],p[7],order); glEnd(); } void my_Bande( float x1, float y1, float z1, /* inside up */ float x2, float y2, float z2, /* outside down */ float tan1, float tan2, int order ) {/* ^ y * * | * * .z -> x * * * * 4 8 9 7 * * 0 \ / 3 * * \5_______________6/ * * 1 2 */ float dummy,sin1,sin2,cos1,cos2,r1,r2; VMvect p[12]; #define BANDE_WULST 0.006 p[0]=vec_xyz(x1-(y2-y1)*tan1,y2,z1+FRAME_DH); // p[1]=vec_xyz(x1,y1,z1-(z1-z2)*0.1); // p[2]=vec_xyz(x2,y1,z1-(z1-z2)*0.1); p[1]=vec_xyz(x1,y1,z1-BANDE_WULST/2.0); p[2]=vec_xyz(x2,y1,z1-BANDE_WULST/2.0); p[3]=vec_xyz(x2+(y2-y1)*tan2,y2,z1+FRAME_DH); p[4]=vec_xyz(x1-(y2-y1)*tan1,y2,z2); p[5]=vec_xyz(x1-(y2-y1)*BANDE_D2RATIO*tan1,y1+(y2-y1)*BANDE_D2RATIO,z2); p[6]=vec_xyz(x2+(y2-y1)*BANDE_D2RATIO*tan2,y1+(y2-y1)*BANDE_D2RATIO,z2); p[7]=vec_xyz(x2+(y2-y1)*tan2,y2,z2); p[8]=vec_xyz(x1,y2,z1+FRAME_DH); p[9]=vec_xyz(x2,y2,z1+FRAME_DH); p[10]=vec_xyz(x1,y1,z1+BANDE_WULST/2.0); p[11]=vec_xyz(x2,y1,z1+BANDE_WULST/2.0); if( x1 > x2 ){ dummy=x1; x1=x2; x2=dummy; } if( y1 > y2 ){ dummy=y1; y1=y2; y2=dummy; } if( z1 > z2 ){ dummy=z1; z1=z2; z2=dummy; } r1=sqrt((FRAME_DH-BANDE_WULST)*(FRAME_DH-BANDE_WULST)+(y2-y1)*(y2-y1)); sin1=fabs((FRAME_DH-BANDE_WULST)/r1); cos1=fabs((y2-y1)/r1); r2=sqrt((y2-y1)*BANDE_D2RATIO*(y2-y1)*BANDE_D2RATIO+(z1-z2)*(z1-z2)); sin2=fabs((y2-y1)*BANDE_D2RATIO/r2); cos2=fabs((z1-z2)/r2); glBegin(GL_QUADS); autonormalize_quad(p[10],p[11],p[9],p[8],order); autonormalize_quad(p[5],p[6],p[2],p[1],order); if(!order){ glNormal3f(0,-sin1,cos1); glVertex3f(p[10].x,p[10].y,p[10].z); glNormal3f(0,-sin1,cos1); glVertex3f(p[11].x,p[11].y,p[11].z); glNormal3f(0,-cos2,-sin2); glVertex3f(p[2].x,p[2].y,p[2].z); glNormal3f(0,-cos2,-sin2); glVertex3f(p[1].x,p[1].y,p[1].z); }else{ glNormal3f(0,-cos2,-sin2); glVertex3f(p[1].x,p[1].y,p[1].z); glNormal3f(0,-cos2,-sin2); glVertex3f(p[2].x,p[2].y,p[2].z); glNormal3f(0,-sin1,cos1); glVertex3f(p[11].x,p[11].y,p[11].z); glNormal3f(0,-sin1,cos1); glVertex3f(p[10].x,p[10].y,p[10].z); } 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=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>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"); bumpcloth = bump_setup_vp_rc("cloth-col.png",0.02,0); bump_cloth_init = 1; }*/ if( table_obj != -1 ) glDeleteLists( table_obj, 1 ); table_obj = glGenLists(1); glNewList(table_obj, GL_COMPILE); // glScalef( 1.0, 1.0, 1.0 ); glMaterialfv(GL_FRONT, GL_DIFFUSE, tab_col_diff); glMaterialfv(GL_FRONT, GL_AMBIENT, tab_col_amb); glMaterialfv(GL_FRONT, GL_SPECULAR, tab_col_spec); glMaterialf (GL_FRONT, GL_SHININESS, 0.0 ); //glTranslatef( 0, 0, 0 ); //gluQuadricDrawStyle(q, GLU_LINE); /* cylinder */ // gluQuadricNormals(q, GL_SMOOTH); // gluQuadricTexture(q, GL_TRUE); //gluCylinder(q, 0.5, 0.5, 2.0, 24, 1); //glTranslatef(1.0, 0.0, 0.5); //gluCylinder(q, 0.0, 0.4, 1.0, 24, 1); //glTranslatef(-1.0, 0.0, -0.5); /*glTranslatef( 0, 0, balld/2.0 ); glRectd( -tablew/2.0, -tablel/2.0, tablew/2.0, tablel/2.0 ); glTranslatef( 0, 0, tableh ); glRectd( tablew/2.0, -tablel/2.0, -tablew/2.0, tablel/2.0 ); glTranslatef( 0, 0, -tableh-balld/2.0 );*/ if( options_table_tex ){ float vx[]={0,50,60,0}; float vy[]={50,0,60,0}; glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,tabletexbind); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); if( options_cloth_tex ){ glActiveTextureARB(GL_TEXTURE1_ARB); glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); glTexGenfv(GL_S, GL_OBJECT_PLANE, vx); glTexGenfv(GL_T, GL_OBJECT_PLANE, vy); glBindTexture(GL_TEXTURE_2D,clothtexbind); glActiveTextureARB(GL_TEXTURE0_ARB); } } else { glDisable(GL_TEXTURE_2D); } /* { GLfloat t_gen_params[] = {300.0,100.0,0.0,0.0}; GLfloat s_gen_params[] = {-100.0,300.0,0.0,0.0}; glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); glTexGenfv(GL_S, GL_OBJECT_PLANE, s_gen_params); glTexGenfv(GL_T, GL_OBJECT_PLANE, t_gen_params); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); }*/ glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); /* if(options_bumpwood && extension_multitexture && extension_rc_NV && extension_vp_NV && bump_cloth_init ){ DPRINTF("applying wood frame bumpmaps\n"); bump_set_light(&bumpcloth,0.0,0.0,0.7); bump_set_diff(&bumpcloth,tab_col_diff[0]+tab_col_amb[0],tab_col_diff[1]+tab_col_amb[1],tab_col_diff[2]+tab_col_amb[2]); bump_set_spec(&bumpcloth,0.5,0.5,0.5); bump_use(&bumpcloth); glActiveTextureARB(GL_TEXTURE1_ARB); GLfloat t_gen_params[] = {1.0,0.0,0.0,0.0}; GLfloat s_gen_params[] = {0.0,1.0,0.0,0.0}; glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); glTexGenfv(GL_S, GL_OBJECT_PLANE, s_gen_params); glTexGenfv(GL_T, GL_OBJECT_PLANE, t_gen_params); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glActiveTextureARB(GL_TEXTURE0_ARB); }*/ // glShadeModel(GL_FLAT); /* glBegin(GL_QUADS); glTexCoord2f( -0.7-0.2, -0.2 ); glNormal3f( 0.0, 0.0, 1.0 ); glVertex3f(-tablew/2.0, -tablel/2.0, -balld/2.0); glTexCoord2f( 1.7-0.2, -0.2 ); glNormal3f( 0.0, 0.0, 1.0 ); glVertex3f(-tablew/2.0, +tablel/2.0, -balld/2.0); glTexCoord2f( 1.7+0.2, 1.2 ); glNormal3f( 0.0, 0.0, 1.0 ); glVertex3f(+tablew/2.0, +tablel/2.0, -balld/2.0); glTexCoord2f( -0.7+0.2, 1.2 ); glNormal3f( 0.0, 0.0, 1.0 ); glVertex3f(+tablew/2.0, -tablel/2.0, -balld/2.0); glEnd();*/ if(carambol){ tablew=TABLE_W+2.0*BANDE_D; tablel=TABLE_L+2.0*BANDE_D; area_w = TABLE_W+2.0*BANDE_D; area_l = TABLE_L+2.0*BANDE_D; } else { area_w = TABLE_W-0.07; area_l = TABLE_L-0.07; } /*#define TABLEBUMPCOORD_X(x,y) (x*3.0) #define TABLEBUMPCOORD_Y(x,y) (y*3.0)*/ /* AREA_SUBDIV_Y and AREA_SUBDIV_X have to be even */ #define AREA_SUBDIV_Y 6 #define AREA_SUBDIV_X 4 jmax=AREA_SUBDIV_Y; imax=AREA_SUBDIV_X; for(j=0;j0.0)?GL_CW:GL_CCW); /*lower, upper*/ for(i=0;i<2;i++){ glFrontFace(i==0?GL_CW:GL_CCW); glBegin(GL_QUAD_STRIP); TABLEVERTEX( area_w/2.0, -area_l/2.0, -BALL_D/2.0, 1.0, i==0?1.0:-1.0 ); TABLEVERTEX( TABLE_W/2.0-edge_xyoffs-BANDE_D*HOLE1_TAN, -TABLE_L/2.0-BANDE_D*BANDE_D2RATIO, -BALL_D/2.0, 1.0, i==0?1.0:-1.0 ); for(j=0;jholenr;i++){ GLUquadric * qd; qd=gluNewQuadric(); glPushMatrix(); glTranslatef( borders->hole[i].pos.x, borders->hole[i].pos.y, borders->hole[i].pos.z ); gluSphere( qd, borders->hole[i].r, 8, 8 ); glPopMatrix(); }*/ // glShadeModel(GL_SMOOTH); glEndList(); if(!init) init = 1; return table_obj; }