How to add a world map image to a sphere?

Here is the code, all im trying to do is add a world map to the sphere so its like a rotating globe, yet im not sure how to do this. Thanks

int n; float[][] points; float lat, lon, r, t; PVector coord;

void setup() { size(640, 480, P3D); coord = new PVector();

n = 100; // number of points r = 200; // sphere's radius t = 0; // rotation accumulator

// populate globe w/ random GPS coordinates points = new float[n][2]; for (int i=0; i<points.length; i++) { points[i][0] = random(-90, 90); // latitude points[i][1] = random(-180, 180); // longitude } }

void draw() { background(0); translate(width/2, height/2); //this centers the sphere rotateY(12 * radians(t += (TWO_PI / 365))); //change this to change the speed of rotation

// earth fill(0,125,0); stroke(0,127,255); strokeWeight(1); sphere(r);

// points fill(255,0,0); stroke(255,0,0); strokeWeight(10);

for (int i=1; i<points.length; i++) { // wgs84 -> cartesian coordinate conversion lat = radians(points[i][0]); lon = radians(points[i][1]); coord.x = r * cos(lat) * cos(lon); coord.y = r * cos(lat) * sin(lon); coord.z = r * sin(lat); point(coord.x, coord.y, coord.z); } }


  • I also found this, so im trying to add the two together:

    PImage earth; PShape globe;

    void setup() { size(600, 600, P3D); background(0); earth = loadImage( ""); globe = createShape(SPHERE, 200); globe.setTexture(earth); noStroke(); }

    void draw() { translate(width/2, height/2); shape(globe); }

  • Edit posts, highlight code, press Ctrl-o to format.

  • What does the first piece of code do that the second piece doesn't?

  • Well the first piece of code is a rotating sphere with some random co-ordinates shown, the second piece is just a static sphere with a earth texture applied, i just want to apply the earth texture to the sphere in the first code, but when i try, the sphere just turns black and the sphere doesnt have the earth texture

  • Answer ✓

    Format the code first, then we can refer to line numbers. As it is it's an unreadable mess.

  • Dont worry i sorted it. Thanks

Sign In or Register to comment.