1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
| //MultiTexRectangle(GL gl, float x, float y, float z, float width, float height, int nb_div, int TexEchelle)
//nb_div, est le nombre de division en carré de la surface, avec de garantir un nombre important de sommet, s'il faut éclairer la surface
private void MultiTexRectangle(GL gl, float x, float y, float z, float width, float height, int nb_div, int TexEchelle){
vector normale;
//On déssine le rectangle
gl.glColor3f( 1.0f, 1.0f, 1.0f );
gl.glBegin(GL.GL_QUAD_STRIP);
float nb_div_width = nb_div;
float nb_div_height = nb_div;
float sizew = (width / nb_div_width); //Rect_Division_Size
float sizeh = (height / nb_div_height); //Rect_Division_Size
float TexX = 1/nb_div_width;
float TexY = 1/nb_div_height;
TexX *= TexEchelle;
TexY *= TexEchelle;
//System.out.println("x:"+normale[0]+" y:"+normale[1]+" z:"+normale[2]);
//gl.glNormal3f(normale[0], normale[1], normale[2]);
//gl.glNormal3f(normale[0], normale[1], normale[2]);
gl.glColor3f( 1.0f, 1.0f, 1.0f );
for(int i=0;i<nb_div_width;i++){
//VERTEX 1
normale = CalculateSurfaceNormal(new float[] {
x, y + i * sizeh + sizeh, z,
x, y + i * sizeh, z,
x + sizew, y + i * sizeh, z
}, true);
gl.glNormal3f(normale.x, normale.y, normale.z);
gl.glTexCoord2f(0.0f, 1-(i*TexY)); gl.glVertex3f(x, y + i * sizeh, z); //1 ... Y
//VERTEX 2
normale = CalculateSurfaceNormal(new float[] {
x + sizew, y + i * sizeh + sizeh, z,
x, y + i * sizeh + sizeh, z,
x, y + i * sizeh, z
}, true);
gl.glNormal3f(normale.x, normale.y, normale.z);
gl.glTexCoord2f(0.0f, 1-((i+1)*TexY)); gl.glVertex3f(x, y + i * sizeh + sizeh, z); //2 ... Y
//VERTEX 3
normale = CalculateSurfaceNormal(new float[] {
x, y + i * sizeh, z,
x + sizew, y + i * sizeh, z,
x + sizew, y + i * sizeh + sizeh, z
}, true);
gl.glNormal3f(normale.x, normale.y, normale.z);
gl.glTexCoord2f(TexX, 1-(i*TexY)); gl.glVertex3f(x + sizew, y + i * sizeh, z); //3 .. Y
//VERTEX 4
normale = CalculateSurfaceNormal(new float[] {
x + sizew, y + i * sizeh, z,
x + sizew, y + i * sizeh + sizeh, z,
x, y + i * sizeh + sizeh, z
}, true);
gl.glNormal3f(normale.x, normale.y, normale.z);
gl.glTexCoord2f(TexX, 1-((i+1)*TexY)); gl.glVertex3f(x + sizew, y + i * sizeh + sizeh, z);//4 ... Y
for(int j=1;j<nb_div_height;j++){
//VERTEX 5
normale = CalculateSurfaceNormal(new float[] {
x + sizew*j, y + i * sizeh, z,
x + sizew + j * sizew, y + i * sizeh, z,
x + sizew + j * sizew, y + i * sizeh + sizeh, z
}, true);
gl.glNormal3f(normale.x, normale.y, normale.z);
gl.glTexCoord2f((j+1)*TexX, 1-(i*TexY)); gl.glVertex3f(x + sizew + j * sizew, y + i * sizeh, z);//5 ... X
//VERTEX 6
normale = CalculateSurfaceNormal(new float[] {
x + sizew + j * sizew, y + i * sizeh, z,
x + sizew + j * sizew, y + i * sizeh + sizeh, z,
x + sizew*j, y + i * sizeh + sizeh, z
}, true);
gl.glNormal3f(normale.x, normale.y, normale.z);
gl.glTexCoord2f((j+1)*TexX, 1-((i+1)*TexY)); gl.glVertex3f(x + sizew + j * sizew, y + i * sizeh + sizeh, z);//6 ... X
}
}
gl.glEnd();
} |
Partager