We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Pages: 1 2 
World Map (Read 7858 times)
Re: World Map
Reply #15 - Jan 23rd, 2010, 6:31am
 
Thanks Quark... I'm using your Earth example from your Shapes library to do this.  I only changed the picture to a higher quality one (similar to this one).  Removed moon/stars, constant rotation, and added the peasycam library for control.

I tried this... but it didn't work...
Code:

import javax.media.opengl.GL;
import processing.opengl.*;
import shapes3d.utils.*;
import shapes3d.*;
import peasy.*;
Ellipsoid earth;
PeasyCam cam;
float r = 0;
PGraphicsOpenGL pgl;
GL gl;

void setup(){
 size(screen.width,screen.height, OPENGL);
 hint(DISABLE_OPENGL_2X_SMOOTH);
 hint(ENABLE_OPENGL_4X_SMOOTH); //after disabling the 2x this works fine

 smooth();
 float fov = PI/3.0;
 float cameraZ = (height/2.0) / tan(fov/2.0);
 perspective(fov, float(width)/float(height), cameraZ/50.0, cameraZ*32.0);

 pgl = (PGraphicsOpenGL) g;
 gl = pgl.gl;

 hint(DISABLE_OPENGL_ERROR_REPORT);

 gl.glEnable( gl.GL_BLEND );
 gl.glHint (gl.GL_LINE_SMOOTH_HINT, gl.GL_NICEST);

 cam = new PeasyCam(this, width);
 cam.setResetOnDoubleClick(false);
 cam.setMinimumDistance(150);
 cam.setMaximumDistance(1000);
 // Create the earth

 earth = new Ellipsoid(this, 50 ,50);
 earth.setTexture("Earth4096.jpg");
 earth.setRadius(90);
 earth.moveTo(new PVector(0,0,0));

 noStroke();
 gl.glBlendFunc(GL.GL_SRC_ALPHA,GL.GL_ONE);

 earth.rotateBy(0, radians(90), 0);
 ambientLight(255, 255, 255, 0,0,0);
}

void draw(){

 background(0);

 earth.draw();

 float lng;
 float lat;
 lng = 48.45; //Paris
 lat = 2.35;
 
  float x = map(lat, 180, -180, -90, 90);
  float y = map(lng, 90, -90, -90, 90);
  float z = 90;
 
 //Quarks example - if I exclude this, the position is close to where it should be but too low on the sphere
  x = radians(x) * sin(x-PI) * cos(y-2*PI);
  y = -(radians(y)) * cos(x-PI);
  z = radians(z) * sin(x-PI) * sin(y-2*PI);

   noStroke();
   fill(255, 0, 0);
   pushMatrix();
   translate(x, y, z);
   sphere(2);
   popMatrix();
 
}
Re: World Map
Reply #16 - Jan 23rd, 2010, 8:00am
 
You have
Code:
   x = radians(x) * sin(x-PI) * cos(y-2*PI);
  y = -(radians(y)) * cos(x-PI);
  z = radians(z) * sin(x-PI) * sin(y-2*PI);

where I had
Code:
x = radX * sin(angNS)  * cos(angEW);
y = - radY * cos(angNS);
z = radZ * sin(angNS) * sin(angEW);

radX is the radius not radians(x)

also beware you have this which is confusing
Code:
  float lng;
 float lat;
 lng = 48.45;  //Paris
 lat = 2.35;
 
  float x = map(lat, 180, -180, -90, 90);
  float y = map(lng, 90, -90, -90, 90);
  float z = 90;

Use x,y and z for the coordinates and something else for the 2 angles for latitude and longitude.

The Shapes 3D library has a nice feature where you can add one shape to another which means the relative position between them is constant provided we just move/rotate the primary shape.
In the sketch below I have created a simplified version of your program to demonstrate the techniques.
Code:
import peasy.org.apache.commons.math.*;
import peasy.*;
import peasy.org.apache.commons.math.geometry.*;

import shapes3d.utils.*;
import shapes3d.org.apache.commons.math.util.*;
import shapes3d.org.apache.commons.math.*;
import shapes3d.org.apache.commons.math.geometry.*;
import shapes3d.*;

Ellipsoid earth, somewhere;
PeasyCam pcam;

float angNS, angEW;
float x,y,z;

void setup(){
 size(400,400,P3D);
 pcam = new PeasyCam(this,0,0,0,500);

 earth = new Ellipsoid(this,20,20);
 earth.setRadius(90);
 earth.fill(color(0,128,0));
 somewhere =  new Ellipsoid(this, 6,10);
 somewhere.fill(color(128,0,0));
 somewhere.setSize(4);
 angNS = radians(60);
 angEW = radians(20);
 x = 90 * sin(angNS)  * cos(angEW);
 y = - 90 * cos(angNS);
 z = 90 * sin(angNS) * sin(angEW);
 somewhere.moveTo(x,y,z);
 earth.addShape(somewhere);
}

void draw(){
 background(32);
 ambientLight(200,200,200);
 earth.draw();
}


Good luck
Smiley
Re: World Map
Reply #17 - Jan 25th, 2010, 10:37am
 
Awesome! That helped a lot. Grin  I think I have it all figured out now.  I had to make a small change, perhaps because I'm using OpenGL and it flips the xy.  Had to change it to this:
Code:
placemarker(48.45,2.35,color(255,0,0)); //Paris
placemarker(27.966667,-15.6,color(255,128,0)); //Gran Canaria
placemarker(40.716667,-74,color(255,0,255)); //New York City


void placemarker(float lat, float lng, color c) {
float angNS, angEW;
float x,y,z;

angNS = radians(lat);
angEW = radians(lng);
y = - r * sin(angNS);
x = - r * cos(angNS) * cos(angEW);
z = r * sin(angEW) * cos(angNS);

noStroke();
fill(c);
pushMatrix();
translate(x, y, z);
sphere(1);
popMatrix();
}

Thanks for the tip on the subobject.. I noticed that was possible with the moon, but I have a separate class I'll be pulling from and I didn't want to duplicate the vertex, since I might have quite a few of them.  I'll keep it in mind though... it's a nice feature.

I've now made the ellipsoid much larger to make use of the higher res image.  Smiley
Re: World Map
Reply #18 - Jan 25th, 2010, 12:25pm
 
There is no limit to the number of sub-objects that you can add to the ellipsoid (Earth).
Smiley
Re: World Map
Reply #19 - Jan 25th, 2010, 12:32pm
 
I have added at least one for the moment... a cloud texture ellipsoid that's a few pixels larger than the earth, which I rotate very slowly around the earth.  Very cool. Smiley
Code:
clouds.rotateBy(0, radians(.015),0); 

Pages: 1 2