We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have a problem with a code to create and texturing a sphere. Can you help me please? Obs.: My texture has 259 width by 194 height
var theta = 2 * Math.PI;
var phi = Math.PI;
var u = 0;
var v = 0;
var deltaUV = 1 / 20;
gl.beginShape(gl.TRIANGLE_STRIP);
for (var i = 0.0; i < phi; i += phi / 20) {
for (var j = 0.0; j < theta; j += theta / 20) {
x = radius * Math.cos(j) * Math.sin(i);
y = radius * Math.sin(j) * Math.sin(i);
z = radius * Math.cos(i);
u = Math.atan2(x, z) / (2.0 * Math.PI) + 0.5;
v = Math.asin(y) / Math.PI + 0.5;
gl.vertex(x, y, z, u * 259, v * 194);
x = radius * Math.cos(j) * Math.sin(i + Math.PI / 20);
y = radius * Math.sin(j) * Math.sin(i + Math.PI / 20);
z = radius * Math.cos(i + Math.PI / 20);
gl.vertex(x, y, z, u * 259, v * 194);
}
}
gl.endShape();
Answers
Edit post, highlight code, press ctrl-o to format.
How can you define an entire sphere using one triangle strip?
And is this Processing code? It seems to be missing bits, looks like plain JavaScript. This is a forum for processing.org.
@koogs this discussion is in the Java script programming category ;)
(yeah, i saw that. but i'd still expect it to look more like 'real' processing. ie no Math prefix for sin(), PI etc plus, y'know, setup() and draw())
(plus i'm always suspicious of someone with 1 post on the forum, like they have registered to ask this specific question after a google search turned up similar looking things here)
This Processing.js, that is the same framework...
I have removed the question, thanks...
https://forum.processing.org/two/discussion/21148/do-not-delete-your-posts