Solution - create two axis vectors, xaxis and yaxis, for your surface. The texture coordinates are simply the dot product of each vertex to these vectors.
Using java Syntax Highlighting
- Vector3 xaxis = new Vector3();
- Vector3 yaxis = new Vector3();
- Vector3 down = new Vector3();
- // The xaxis is the real x-axis if the plane is parallel to the xy plane, (normal is 0,0,+-1)
- // Otherwise, the xaxis is the cross product of 'down' and the plane normal
- if ((Math.abs(plane.normal.z) == 1) && (plane.normal.x == 0) and (plane.normal.y == 0))
- {
- Vector3.set(xaxis,1,0,0);
- }
- else
- {
- Vector3.set(down,0,0,-1);
- Vector3.cross_product(xaxis, down, plane.normal);
- Vector3.normalize(xaxis,xaxis);
- }
- // The yaxis is the cross of the xaxis and the plane normal
- Vector3.cross_product(yaxis,plane.normal,xaxis);
- Vector3.normalize(yaxis,yaxis);
- // For each of your vertices, the x and y texture coordinates are the dot products respective to
- // these newly created x and y axis vectors.
- for (int i=0; i<number_of_vertices; i++)
- {
- texture_vertex[i].x = Vector3.dot_product(vertex[i],xaxis) * texture_scale;
- texture_vertex[i].y = Vector3.dot_product(vertex[i],yaxis) * texture_scale;
- }
Parsed in 0.033 seconds, using GeSHi 1.0.8.4

