2007-03-13 18:37:22 +00:00
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
package ei.engine.scene;
|
|
|
|
|
|
2007-03-17 16:29:39 +00:00
|
|
|
import org.lwjgl.opengl.GL11;
|
|
|
|
|
|
2007-03-15 19:52:28 +00:00
|
|
|
import ei.engine.math.Vector2f;
|
2007-03-17 16:29:39 +00:00
|
|
|
import ei.engine.math.Vector3f;
|
2007-03-13 18:37:22 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This class is the root class of all the objects that
|
|
|
|
|
* will show on the scrren. This class handles the position
|
|
|
|
|
* and rotation and the colitions of the objects.
|
|
|
|
|
* @author Ziver
|
|
|
|
|
*/
|
|
|
|
|
public abstract class Entity {
|
|
|
|
|
/** The name of this sprite */
|
|
|
|
|
private String name;
|
|
|
|
|
|
|
|
|
|
/** The location of this entity in pixels*/
|
2007-03-27 17:51:02 +00:00
|
|
|
private Vector3f location;
|
2007-03-13 18:37:22 +00:00
|
|
|
|
|
|
|
|
/** The rotation of this entity in pixels*/
|
2007-03-17 16:29:39 +00:00
|
|
|
private Vector3f rotation;
|
2007-03-13 18:37:22 +00:00
|
|
|
|
|
|
|
|
/** The size of this entity in pixels*/
|
2007-03-27 17:51:02 +00:00
|
|
|
private Vector3f size;
|
2007-03-21 21:55:03 +00:00
|
|
|
|
2007-03-13 18:37:22 +00:00
|
|
|
/**
|
|
|
|
|
* creates a new entity
|
|
|
|
|
*
|
|
|
|
|
* @param name The name of the entity
|
|
|
|
|
*/
|
|
|
|
|
public Entity(String name){
|
|
|
|
|
this.name = name;
|
2007-03-27 17:51:02 +00:00
|
|
|
location = new Vector3f();
|
2007-03-17 16:29:39 +00:00
|
|
|
rotation = new Vector3f();
|
2007-03-27 17:51:02 +00:00
|
|
|
size = new Vector3f(1,1,1);
|
2007-03-13 18:37:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return The name of the entity
|
|
|
|
|
*/
|
|
|
|
|
public String getName() {
|
|
|
|
|
return name;
|
|
|
|
|
}
|
2007-03-21 21:55:03 +00:00
|
|
|
|
|
|
|
|
/**
|
2007-03-27 17:51:02 +00:00
|
|
|
* Get the Location of the entity
|
2007-03-21 21:55:03 +00:00
|
|
|
*
|
2007-03-27 17:51:02 +00:00
|
|
|
* @return The Location of the entity
|
2007-03-21 21:55:03 +00:00
|
|
|
*/
|
2007-03-27 17:51:02 +00:00
|
|
|
public Vector3f getLocation() {
|
|
|
|
|
return location;
|
|
|
|
|
}
|
2007-03-21 21:55:03 +00:00
|
|
|
|
2007-03-13 18:37:22 +00:00
|
|
|
/**
|
2007-03-27 17:51:02 +00:00
|
|
|
* set the location of this entity in pixels
|
2007-03-13 18:37:22 +00:00
|
|
|
*
|
2007-03-27 17:51:02 +00:00
|
|
|
* @param l The location of the entity
|
2007-03-13 18:37:22 +00:00
|
|
|
*/
|
2007-03-27 17:51:02 +00:00
|
|
|
public void setLocation(Vector3f l) {
|
|
|
|
|
location = l;
|
2007-03-13 18:37:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* set the location of this entity in pixels
|
|
|
|
|
*
|
|
|
|
|
* @param l The location of the entity
|
|
|
|
|
*/
|
2007-03-15 19:52:28 +00:00
|
|
|
public void setLocation(Vector2f l) {
|
2007-03-27 17:51:02 +00:00
|
|
|
location = new Vector3f(l.getX(),l.getY(),getLocation().getZ());
|
2007-03-13 18:37:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the rotation of the entity
|
|
|
|
|
*
|
|
|
|
|
* @return The Location of the entity
|
|
|
|
|
*/
|
2007-03-17 16:29:39 +00:00
|
|
|
public Vector3f getRotation() {
|
2007-03-13 18:37:22 +00:00
|
|
|
return rotation;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* set the rotation of this entity in pixels
|
|
|
|
|
*
|
|
|
|
|
* @param r The rotation of the entity
|
|
|
|
|
*/
|
2007-03-17 16:29:39 +00:00
|
|
|
public void setRotation(Vector3f r) {
|
2007-03-13 18:37:22 +00:00
|
|
|
rotation = r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2007-03-18 17:38:58 +00:00
|
|
|
* Get the scale of the entity
|
2007-03-13 18:37:22 +00:00
|
|
|
*
|
|
|
|
|
* @return The Location of the entity
|
|
|
|
|
*/
|
2007-03-27 17:51:02 +00:00
|
|
|
public Vector3f getScale() {
|
2007-03-13 18:37:22 +00:00
|
|
|
return size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2007-03-18 17:38:58 +00:00
|
|
|
* set the scale of this entity in pixels
|
2007-03-13 18:37:22 +00:00
|
|
|
*
|
|
|
|
|
* @param s The size of the entity
|
|
|
|
|
*/
|
2007-03-27 17:51:02 +00:00
|
|
|
public void setScale(Vector3f s) {
|
2007-03-13 18:37:22 +00:00
|
|
|
size = s;
|
|
|
|
|
}
|
2007-03-17 16:29:39 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the location of the entity in opengl
|
|
|
|
|
* before rendering.
|
|
|
|
|
*/
|
|
|
|
|
protected void setTranslationGL(){
|
|
|
|
|
// translate to the right location and prepare to draw
|
2007-03-27 22:51:23 +00:00
|
|
|
GL11.glTranslatef(location.getX(), location.getY(), location.getZ());
|
2007-03-17 16:29:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2007-03-18 17:38:58 +00:00
|
|
|
* Sets the location of the entity in opengl
|
2007-03-17 16:29:39 +00:00
|
|
|
*
|
|
|
|
|
* @param x The value to add x
|
|
|
|
|
* @param y The value to add y
|
2007-03-27 17:51:02 +00:00
|
|
|
* @param z The value to add z
|
2007-03-17 16:29:39 +00:00
|
|
|
*/
|
2007-03-27 17:51:02 +00:00
|
|
|
protected void setTranslationGL(float x, float y, float z){
|
2007-03-17 16:29:39 +00:00
|
|
|
// translate to the right location and prepare to draw
|
2007-03-27 17:51:02 +00:00
|
|
|
GL11.glTranslatef(x,y, z);
|
2007-03-18 17:38:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void setScaleGL(){
|
|
|
|
|
// translate to the right location and prepare to draw
|
2007-03-27 17:51:02 +00:00
|
|
|
GL11.glScalef(size.getX(), size.getY(), size.getZ());
|
2007-03-17 16:29:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the rotation of the entity in opengl
|
|
|
|
|
* before rendering.
|
|
|
|
|
*/
|
|
|
|
|
protected void setRotationGL(){
|
|
|
|
|
// rotating the entity
|
|
|
|
|
GL11.glRotatef(rotation.getX(), 1.0f, 0.0f, 0.0f); // Rotate On The X Axis
|
|
|
|
|
GL11.glRotatef(rotation.getY(), 0.0f, 1.0f, 0.0f); // Rotate On The Y Axis
|
|
|
|
|
GL11.glRotatef(rotation.getZ(), 0.0f, 0.0f, 1.0f); // Rotate On The Z Axis
|
|
|
|
|
}
|
2007-03-13 18:37:22 +00:00
|
|
|
|
|
|
|
|
/**
|
2007-03-15 19:52:28 +00:00
|
|
|
* the render method should be implemented for every entity
|
2007-03-13 18:37:22 +00:00
|
|
|
*/
|
|
|
|
|
public abstract void render();
|
2007-03-15 19:52:28 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* the update method can be implemented for every entity
|
|
|
|
|
*/
|
|
|
|
|
public void update(){}
|
2007-03-13 18:37:22 +00:00
|
|
|
}
|