DMS8013: Playing around with the Solar System

Screen Shot 2016-04-25 at 18.17.26

It has been awhile since I played around the exercise we saw the other day in class, “The Solar System”, in which we learnt “ matrix translations “. I simply forgot to upload the outcome on the blog. When I started working on this exercise, I had at least two goals:

– creating a moon  orbiting the planet Earth.

– adding textures to the 3D spheres in order to make them look what they are representing.

It took me many hours to figure out how to achieve those goals. I didn’t achieve them in the way I was thinking all the time, so I ended up changing the code I was using from the beginning (the one we created in class).

solar_system_textures

YouTube Preview Image

See the code I used:

import shapes3d.*;
import shapes3d.animation.*;
import shapes3d.utils.*;

import processing.opengl.*;
Ellipsoid sun, earth, moon, stars;
Box orbiter;

boolean attached = true;

//this is angle, which is equal to 0
float sunRot = 0;
float ang = 0.0;
float angleDirection = 1;
PImage sunmap;
int y;
PImage starfield;

void setup (){
size(1200, 600, OPENGL);
smooth();
hint(ENABLE_DEPTH_SORT);
background(255);
starfield = loadImage(“starfield.jpg”);

// create the sun
sun = new Ellipsoid(this, 16, 16);
sun.setTexture(“sun.jpg”);
sun.setRadius(90);
sun.moveTo(new PVector(0, 0, 0));
sun.strokeWeight(1.0f);
sun.stroke(color(255, 255, 0));

sun.tag = “Sun”;
sun.drawMode(Shape3D.TEXTURE);

// create the earth

earth = new Ellipsoid(this, 15, 15);
earth.setTexture(“earth.jpg”);
earth.drawMode(Shape3D.TEXTURE);
earth.setRadius(30);
earth.moveTo(0, 0, 220);
earth.tag = “Earth”;

// create the moon

moon = new Ellipsoid (this, 20,20);
moon.setTexture(“moon.jpg”);
moon.drawMode(Shape3D.TEXTURE);
moon.setRadius(8);
moon.moveTo(0, -10, -50);
moon.tag = “Moon”;

// Create the star background
stars = new Ellipsoid(this, 10, 10);
stars.setTexture(“starfield.jpg”, 5, 5);
stars.drawMode(Shape3D.TEXTURE);
stars.setRadius(500);
stars.moveTo(0, 0, 0);

// Add the earth to the sun this makes
// its position relative to the sun’s
sun.addShape(earth);
// and the moon to the earth
earth.addShape(moon);
}
void draw () {

//without the ambient light we get very harsh shadows
ambientLight(452, 452, 452);

//SUN
//shift matrix to centre
translate(width/2.0, height/2.0);
pushStyle();

background(0);
pushMatrix();
// Change the rotations before drawing
sun.rotateBy(0, radians(0.6f), 0);
earth.rotateBy(0, radians(0.6f), 0);
stars.rotateBy(0, 0, radians(0.02f));

sun.draw();
stars.draw();
popMatrix();
popStyle();

}