Entity.java 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package eu.tankernn.gameEngine.entities;
  2. import org.lwjgl.util.vector.Vector3f;
  3. import eu.tankernn.gameEngine.loader.models.AABB;
  4. import eu.tankernn.gameEngine.loader.models.TexturedModel;
  5. import eu.tankernn.gameEngine.util.IPositionable;
  6. public class Entity implements IPositionable {
  7. private static final Vector3f SIZE = new Vector3f(2, 4, 2);
  8. private TexturedModel model;
  9. private Vector3f position;
  10. private Vector3f rotation;
  11. private float scale;
  12. private AABB boundingBox;
  13. private int textureIndex = 0;
  14. public Entity(TexturedModel model, Vector3f position, Vector3f rotation, float scale) {
  15. this.model = model;
  16. this.position = position;
  17. this.rotation = rotation;
  18. this.scale = scale;
  19. this.boundingBox = new AABB(position, SIZE);
  20. }
  21. public Entity(TexturedModel model, int index, Vector3f position, Vector3f rotation, float scale) {
  22. this.model = model;
  23. this.textureIndex = index;
  24. this.position = position;
  25. this.rotation = rotation;
  26. this.scale = scale;
  27. this.boundingBox = new AABB(position, SIZE);
  28. }
  29. public float getTextureXOffset() {
  30. int column = textureIndex % model.getModelTexture().getNumberOfRows();
  31. return (float) column / (float) model.getModelTexture().getNumberOfRows();
  32. }
  33. public float getTextureYOffset() {
  34. int row = textureIndex / model.getModelTexture().getNumberOfRows();
  35. return (float) row / (float) model.getModelTexture().getNumberOfRows();
  36. }
  37. public void increasePosition(float dx, float dy, float dz) {
  38. this.position.x += dx;
  39. this.position.y += dy;
  40. this.position.z += dz;
  41. updateBoundingBox();
  42. }
  43. public void increaseRotation(Vector3f deltaRotation) {
  44. Vector3f.add(this.rotation, deltaRotation, this.rotation);
  45. }
  46. private void updateBoundingBox() {
  47. this.boundingBox = new AABB(this.position, SIZE); //TODO Fix model size
  48. }
  49. public TexturedModel getModel() {
  50. return model;
  51. }
  52. public void setModel(TexturedModel model) {
  53. this.model = model;
  54. }
  55. public Vector3f getPosition() {
  56. return position;
  57. }
  58. public void setPosition(Vector3f position) {
  59. this.position = position;
  60. }
  61. public Vector3f getRotation() {
  62. return rotation;
  63. }
  64. public float getScale() {
  65. return scale;
  66. }
  67. public void setScale(float scale) {
  68. this.scale = scale;
  69. }
  70. public AABB getBoundingBox() {
  71. return boundingBox;
  72. }
  73. }