Java based Simulated Solar system




Sationary Object- Sun
Small Orange - Mercury
Blue ones - Venus and Earth


Source Code



package applets;
import shout3d.*;
import shout3d.core.*;
import shout3d.math.*;
//*********************************************
//@ Author: Chitra .R
// Location: Home
// File: TemplatePanel.java
// Uses the elipse equation aCosX + bSinX for revolving
// Uses SolSys2.wrl for getting the nodes
//*********************************************
public class TemplatePanel extends Shout3DPanel implements DeviceObserver, RenderObserver {
//construnctor


//defining all transform nodes
Transform mercuryTrans;
Transform venusTrans;
Transform earthTrans;
Transform marsTrans;
Transform jupitorTrans;
Transform saturnTrans;
Transform saturnRingsTrans;
// getting the co-ords
float[] mercuryPos = new float[3];
float[] venusPos = new float[3];
float[] earthPos = new float[3];
float[] marsPos = new float[3];
float[] jupitorPos = new float[3];
float[] saturnPos = new float[3];
float[] saturnRingsPos = new float[3];
//defining angles
float cycleAngle = 0;
float venusCycleAngle = 0;
float earthCycleAngle = 0;
float marsCycleAngle = 0;
float jupitorCycleAngle = 0;
float saturnCycleAngle = 0;

//cycletimes
float MercycleTime = 4.0f; //seconds per cycle
float venusCycleTime = 5.0f; //seconds per cycle
float earthCycleTime = 6.5f;
float marsCycleTime = 7.3f;
float jupitorCycleTime = 9.3f;
float saturnCycleTime = 10.5f;



public TemplatePanel ( Shout3DApplet applet)
{
super(applet);
}

//called immediately after scene is loaded

public void customInitialize()
{

//Get all planets Node from the wrl file
mercuryTrans = (Transform) getNodeByName("Mercury");
venusTrans = (Transform) getNodeByName("Venus");
earthTrans = (Transform) getNodeByName("Earth");
jupitorTrans = (Transform) getNodeByName("Jupitor");
marsTrans = (Transform) getNodeByName("Mars");
saturnTrans = (Transform) getNodeByName("Saturn");
saturnRingsTrans = (Transform) getNodeByName("rings");


//get value returns in a float array of 3 for 3 coords
mercuryPos = mercuryTrans.translation.getValue();
venusPos = venusTrans.translation.getValue();
earthPos = earthTrans.translation.getValue();
jupitorPos = jupitorTrans.translation.getValue();
marsPos = marsTrans.translation.getValue();
saturnPos = saturnTrans.translation.getValue();
saturnRingsPos = saturnRingsTrans.translation.getValue();

addDeviceObserver(this, "MouseInput", null);
getRenderer().addRenderObserver(this, null);

}
public void finalize ()
{
removeDeviceObserver(this, "MouseInput");
getRenderer().removeRenderObserver(this);
}

//method of from DeviceObserver interface

// to handle user input
// will only recieve mouse as registered
public boolean onDeviceInput(DeviceInput di, Object userData)
{ return false;
}
public void onPreRender(Renderer r, Object o)
{
//****************************************Mercury Rotar
double rad1 = 14.0;
double rad2 = 13.22;
float deltaAngle = (6.28f/MercycleTime)/getFramesPerSecond();
//update angle
cycleAngle = cycleAngle + deltaAngle;
//convert to elipse equation aCosX + bSinX, where a is x-axis and b is z-axiz
mercuryPos[0] = (float) (rad1 * Math.cos( cycleAngle));
mercuryPos[1] = (float) 0.0;
mercuryPos[2] = (float) (rad2 * Math.sin( cycleAngle ));
mercuryTrans.translation.setValue(mercuryPos); //set them back
//************************************************************ following isfor venus
double venusrad1 = 22.0;
double venusrad2 = 21.22;
float delvenusAngle = (6.28f/venusCycleTime)/getFramesPerSecond();
venusCycleAngle = venusCycleAngle + delvenusAngle;
// System.out.println(venusPos[0] + " = " + venusPos[1] + " = " + venusPos[2]);
venusPos[0] = (float) (venusrad1 * Math.cos( venusCycleAngle)); //find the cos & sine angles for the elipse
venusPos[1] = (float) 0.0;
venusPos[2] = (float) (venusrad2 * Math.sin( venusCycleAngle ));
venusTrans.translation.setValue(venusPos); //set them again
// ******************************************** this is for earth
double earthrad1 = 35.0;
double earthrad2 = 33.22;
float delearthAngle = (6.28f/earthCycleTime)/getFramesPerSecond();
earthCycleAngle = earthCycleAngle + delearthAngle;
// System.out.println("earth=" + earthPos[0] + " = " + earthPos[1] + " = " + earthPos[2]);
earthPos[0] = (float) (earthrad1 * Math.cos( earthCycleAngle));
earthPos[1] = (float) 0.0;
earthPos[2] = (float) (earthrad2 * Math.sin( earthCycleAngle ));
earthTrans.translation.setValue(earthPos);
//********************************************* this if for mars
double marsrad1 = 47.0;
double marsrad2 = 44.22;
float delmarsAngle = (6.28f/marsCycleTime)/getFramesPerSecond();
marsCycleAngle = marsCycleAngle + delmarsAngle;
// System.out.println("mars=" + marsPos[0] + " = " + marsPos[1] + " = " + marsPos[2]);
marsPos[0] = (float) (marsrad1 * Math.cos( marsCycleAngle));
marsPos[1] = (float) 0.0;
marsPos[2] = (float) (marsrad2 * Math.sin( marsCycleAngle ));
marsTrans.translation.setValue(marsPos);
//*****************************************************the following is for Venus
double jupitorrad1 = 64.0;
double jupitorrad2 = 56.22;
float deljupitorAngle = (6.28f/jupitorCycleTime)/getFramesPerSecond();
jupitorCycleAngle = jupitorCycleAngle + deljupitorAngle;
// System.out.println("jupitor=" + jupitorPos[0] + " = " + jupitorPos[1] + " = " + jupitorPos[2]);
jupitorPos[0] = (float) (jupitorrad1 * Math.cos( jupitorCycleAngle));
jupitorPos[1] = (float) 0.0;
jupitorPos[2] = (float) (jupitorrad2 * Math.sin( jupitorCycleAngle ));
jupitorTrans.translation.setValue(jupitorPos);

//***************************************************88for saturn and rings
double saturnrad1 = 83.0;
double saturnrad2 = 74.22;
float delsaturnAngle = (6.28f/saturnCycleTime)/getFramesPerSecond();
saturnCycleAngle = saturnCycleAngle + delsaturnAngle;
// System.out.println("Saturn=" + saturnPos[0] + " = " + saturnPos[1] + " = " + saturnPos[2]);
saturnPos[0] = (float) (saturnrad1 * Math.cos( saturnCycleAngle));
saturnPos[1] = (float) 0.0;
saturnPos[2] = (float) (saturnrad2 * Math.sin( saturnCycleAngle ));
saturnTrans.translation.setValue(saturnPos);
//rings
saturnRingsPos[0] = (float) (saturnrad1 * Math.cos( saturnCycleAngle));
saturnRingsPos[1] = (float) 0.0;
saturnRingsPos[2] = (float) (saturnrad2 * Math.sin( saturnCycleAngle ));
saturnRingsTrans.translation.setValue(saturnRingsPos);
}
public void onPostRender (Renderer r, Object o)
{

}

} //end of class

package applets;
import shout3d.*;
//*********************************************
//@ Author: Chitra .R
// Location: Home 
// File: TemplateApplet.java
// parent applet
//*********************************************
public class TemplateApplet extends Shout3DApplet  {
	public void initShout3DPanel()  {
		panel = new TemplatePanel(this);
		}
	}	//end of class