Rotating images in 3D
in
Programming Questions
•
2 years ago
Hi,
I am a beginner in Processing (and 3D visualization) and I am trying to learn it by doing a small project in it.
I want a rotating map of the world with a few ellipses marking some cities on it.
Here is gist of how I am going about it:
- PImage world_map_img;
- float angle = 0;
- void setup(){
- size(width, height, P3D);
- world_map_img = loadImage("world_map_wikipedia.png");
- }
- void draw(){
- increase_angle();
- smooth();
- image(world_map_img, 0, 0, width, height);
- for(int ii; ii=0; ii<=N; ii++) {
- pos_x = city_positions[ii].x;
- pos_y = city_positions[ii].y;
- pushMatrix();
- translate(pos_x, pos_y, 0.0);
- set_right_colors(ii);
- ellipse(0, 0, 10, 10);
- popMatrix();
- }
- camera( radius * cos(angle), radius * sin(angle), fixed_z_height,
- width/2, height/2, 0.0,
- 0.0, 1.0, 0.0); // Will throw more trigonometry at it soon.
- }
There are some
problems I am running into:
- If I do not call 'smooth()', the image drawn is distorted (https://github.com/musically-ut/World-prices/raw/master/screen_shots/16_58_46.png)
- After calling 'smooth()', the drawing and movement is extremely slow.
- There is a diagonal line across the map and the ellipses are very flaky ( https://github.com/musically-ut/World-prices/raw/master/screen_shots/20_58_47.png)
I am guessing (after reading the preliminary 3D tutorials, which do not seem to promote the use of
camera function) that this is not the recommended way of doing things. Hence, before I blame everything from my Laptop hardware to the Java software, I would like a second opinion of how this
should be done.
One option is loading the image pixel by pixel and doing the transformations by hand; I am
hoping there is a better way?
The end result I would like is the background map of the world rotating as here:
http://vimeo.com/4587178
Also, the source code (with the data files) is posted here:
https://github.com/musically-ut/World-prices
Any code review/feedback/pointer-to-guidelines is welcome!
Thanks!
~
musically_ut
1