/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import com.sun.opengl.util.texture.Texture;
import com.sun.opengl.util.texture.TextureData;
import com.sun.opengl.util.texture.TextureIO;
import java.io.File;
import javax.media.opengl.GL;
import javax.media.opengl.glu.GLU;
import javax.media.opengl.glu.GLUquadric;
import javax.vecmath.Vector3f;
/**
*
* @author philippXXX
*/
public class Planet {
private Vector3f position;
private Vector3f normalAxsis;
private float radius;
private float speed;
private String texture;
private String name;
protected GL gl;
private TextureData textureData;
private Texture tex;
private float innerRoation;
private float orbit;
private float orbitRotation;
private float innerRationSpeed;
public float getInnerRationSpeed() {
return innerRationSpeed;
}
public void setInnerRationSpeed(float innerRationSpeed) {
this.innerRationSpeed = innerRationSpeed;
}
public Planet(String name, String texture, GL gl, float speed, Vector3f normal,float orbit,float radius,float innerRotationSpeed) {
this.gl = gl;
this.setName(name);
this.setRadius(radius);
this.setTexture(texture);
this.setNormalAxsis(normal);
this.setSpeed(speed);
this.setOrbit(orbit);
this.setPosition(new Vector3f(0f,0f,0f));
this.setInnerRationSpeed(innerRotationSpeed);
this.setInnerRoation(90);
gl.glEnable(GL.GL_TEXTURE_2D);
textureData = null;
tex = null;
try {
tex = TextureIO.newTexture(new File(texture), true);
} catch (Exception e) {
e.printStackTrace();
}
}
public float getOrbit() {
return orbit;
}
public void setOrbit(float orbit) {
this.orbit = orbit;
}
private int counter = 0;
public void update() {
gl.glPushMatrix();
GLU glu = new GLU();
float x = (float) (Math.sin(Math.toRadians(this.getOrbitRotation())) * this.getOrbit());
float z = (float) (Math.cos(Math.toRadians(this.getOrbitRotation())) * this.getOrbit());
this.getPosition().x = x;
this.getPosition().z = z;
this.getPosition().y = 0;
// gl.glPushMatrix();
//gl.glPopMatrix();
gl.glTranslatef(this.getPosition().x, this.getPosition().y, this.getPosition().z);
gl.glRotatef(this.getInnerRoation(),this.getNormalAxsis().x, this.getNormalAxsis().y, this.getNormalAxsis().z);
tex.bind();
GLUquadric sphere_quadric = glu.gluNewQuadric();
glu.gluQuadricTexture(sphere_quadric, true);
glu.gluQuadricDrawStyle(sphere_quadric, GLU.GLU_FILL);
glu.gluQuadricNormals(sphere_quadric, GLU.GLU_SMOOTH);
glu.gluSphere(sphere_quadric, this.getRadius(), 25, 25);
counter++;
this.innerRoation = counter * innerRationSpeed;
this.orbitRotation = counter * speed;
gl.glPopMatrix();
}
public float getInnerRoation() {
return innerRoation;
}
public void setInnerRoation(float innerRoation) {
this.innerRoation = innerRoation;
}
public Texture getTex() {
return tex;
}
public void setTex(Texture tex) {
this.tex = tex;
}
public TextureData getTextureData() {
return textureData;
}
public void setTextureData(TextureData textureData) {
this.textureData = textureData;
}
public GL getGl() {
return gl;
}
public void setGl(GL gl) {
this.gl = gl;
}
public Vector3f getNormalAxsis() {
return normalAxsis;
}
public void setNormalAxsis(Vector3f normalAxsis) {
this.normalAxsis = normalAxsis;
}
public float getSpeed() {
return speed;
}
public void setSpeed(float speed) {
this.speed = speed;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Vector3f getPosition() {
return position;
}
public void setPosition(Vector3f position) {
this.position = position;
}
public float getRadius() {
return radius;
}
public void setRadius(float radius) {
this.radius = radius;
}
public String getTexture() {
return texture;
}
public void setTexture(String texture) {
this.texture = texture;
}
public float getOrbitRotation() {
return orbitRotation;
}
public void setOrbitRotation(float orbitRotation) {
this.orbitRotation = orbitRotation;
}
}