我遇到了正確的球體映射問題。我用世界地圖來顯示它出錯的地方。北美從上到下出現在前方,而南美則倒在另一邊,像亞洲這樣的大陸甚至沒有在地圖上出現。在球體上映射紋理的正確方法是什麼?
Screenshot http://i.troll.ws/3aedbe4b.png
下面的代碼是近似球形物體
class Shape {
public void drawSphere(double radius, int slices, int stacks) {
gl.glEnable(GL_TEXTURE_2D);
head.bind(gl); //Method that binds the world-map (for testing) texture.
gl.glBegin(GL_QUADS);
double stack = (2 * PI)/stacks;
double slice = (2 * PI)/slices;
for (double theta = 0; theta < 2 * PI; theta += stack) {
for (double phi = 0; phi < 2 * PI; phi += slice) {
Vector p1 = getPoints(phi, theta, radius);
Vector p2 = getPoints(phi + slice, theta, radius);
Vector p3 = getPoints(phi + slice, theta + stack, radius);
Vector p4 = getPoints(phi, theta + stack, radius);
double s0 = theta/(2 * PI);
double s1 = (theta + stack)/(2 * PI);
double t0 = phi/(2 * PI);
double t1 = (phi + slice)/(2 * PI);
vectorToNormal(norm(p1));
gl.glTexCoord2d(s0, t0);
vectorToVertex(p1);
vectorToNormal(norm(p2));
gl.glTexCoord2d(s0, t1);
vectorToVertex(p2);
vectorToNormal(norm(p3));
gl.glTexCoord2d(s1, t1);
vectorToVertex(p3);
vectorToNormal(norm(p4));
gl.glTexCoord2d(s1, t0);
vectorToVertex(p4);
}
}
gl.glEnd();
gl.glDisable(GL_TEXTURE_2D);
}
Vector getPoints(double phi, double theta, double radius) {
double x = radius * cos(theta) * sin(phi);
double y = radius * sin(theta) * sin(phi);
double z = radius * cos(phi);
return new Vector(x, y, z);
}
我怎樣才能解決呢?我嘗試交換一些座標和其他東西,但這使我更加混亂。
此外,當我將紋理綁定到紋理上時,似乎還有一些工件。這是可以修復的嗎?
你的屏幕截圖在哪裏? – genpfault
託管映像的託管服務不再運行。 – Yatoom