Entity.java 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 float rotX, rotY, rotZ;
  11. private float scale;
  12. private AABB boundingBox;
  13. private int textureIndex = 0;
  14. public Entity(TexturedModel model, Vector3f position, float rotX, float rotY, float rotZ, float scale) {
  15. this.model = model;
  16. this.position = position;
  17. this.rotX = rotX;
  18. this.rotY = rotY;
  19. this.rotZ = rotZ;
  20. this.scale = scale;
  21. this.boundingBox = new AABB(position, SIZE);
  22. }
  23. public Entity(TexturedModel model, int index, Vector3f position, float rotX, float rotY, float rotZ, float scale) {
  24. this.model = model;
  25. this.textureIndex = index;
  26. this.position = position;
  27. this.rotX = rotX;
  28. this.rotY = rotY;
  29. this.rotZ = rotZ;
  30. this.scale = scale;
  31. this.boundingBox = new AABB(position, SIZE);
  32. }
  33. public float getTextureXOffset() {
  34. int column = textureIndex % model.getModelTexture().getNumberOfRows();
  35. return (float) column / (float) model.getModelTexture().getNumberOfRows();
  36. }
  37. public float getTextureYOffset() {
  38. int row = textureIndex / model.getModelTexture().getNumberOfRows();
  39. return (float) row / (float) model.getModelTexture().getNumberOfRows();
  40. }
  41. public void increasePosition(float dx, float dy, float dz) {
  42. this.position.x += dx;
  43. this.position.y += dy;
  44. this.position.z += dz;
  45. updateBoundingBox();
  46. }
  47. public void increaseRotation(float dx, float dy, float dz) {
  48. this.rotX += dx;
  49. this.rotY += dy;
  50. this.rotZ += dz;
  51. }
  52. private void updateBoundingBox() {
  53. this.boundingBox = new AABB(this.position, SIZE); //TODO Fix model size
  54. }
  55. public TexturedModel getModel() {
  56. return model;
  57. }
  58. public void setModel(TexturedModel model) {
  59. this.model = model;
  60. }
  61. public Vector3f getPosition() {
  62. return position;
  63. }
  64. public void setPosition(Vector3f position) {
  65. this.position = position;
  66. }
  67. public float getRotX() {
  68. return rotX;
  69. }
  70. public void setRotX(float rotX) {
  71. this.rotX = rotX;
  72. }
  73. public float getRotY() {
  74. return rotY;
  75. }
  76. public void setRotY(float rotY) {
  77. this.rotY = rotY;
  78. }
  79. public float getRotZ() {
  80. return rotZ;
  81. }
  82. public void setRotZ(float rotZ) {
  83. this.rotZ = rotZ;
  84. }
  85. public float getScale() {
  86. return scale;
  87. }
  88. public void setScale(float scale) {
  89. this.scale = scale;
  90. }
  91. public AABB getBoundingBox() {
  92. return boundingBox;
  93. }
  94. }