Bone.java 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package eu.tankernn.gameEngine.animation;
  2. import java.io.BufferedReader;
  3. import java.io.FileNotFoundException;
  4. import java.io.FileReader;
  5. import java.io.IOException;
  6. import java.util.ArrayList;
  7. import java.util.List;
  8. import org.lwjgl.util.vector.Vector3f;
  9. import org.lwjgl.util.vector.Vector4f;
  10. public class Bone {
  11. private String name;
  12. private List<Bone> children;
  13. private Bone parent;
  14. private float length;
  15. private Vector3f position;
  16. private Vector4f rotation;
  17. public Bone(String name, float length, Vector3f position, Vector4f rotation) {
  18. this.name = name;
  19. this.children = new ArrayList<Bone>();
  20. this.length = length;
  21. this.position = position;
  22. this.rotation = rotation;
  23. }
  24. public Bone(String[] args) {
  25. this.children = new ArrayList<Bone>();
  26. this.position = new Vector3f(Float.parseFloat(args[1]), Float.parseFloat(args[2]), Float.parseFloat(args[3]));
  27. this.rotation = new Vector4f(Float.parseFloat(args[4]), Float.parseFloat(args[5]), Float.parseFloat(args[6]), Float.parseFloat(args[7]));
  28. this.length = Float.parseFloat(args[8]);
  29. this.name = args[9];
  30. }
  31. public static Bone fromFile(String filename) throws IOException {
  32. BufferedReader reader;
  33. try {
  34. reader = new BufferedReader(new FileReader(filename));
  35. } catch (FileNotFoundException e) {
  36. e.printStackTrace();
  37. return null;
  38. }
  39. Bone root = new Bone(reader.readLine().split(" "));
  40. while (reader.ready()) {
  41. String[] line = reader.readLine().split(" ");
  42. String depthBuffer = line[0];
  43. int depth = depthBuffer.length() - 1;
  44. if (depth < 0) {
  45. System.err.println("Wrong bone depth.");
  46. }
  47. }
  48. reader.close();
  49. return root;
  50. }
  51. public void addChild(Bone child) {
  52. child.setParent(this);
  53. this.children.add(child);
  54. }
  55. public Bone getParent() {
  56. return parent;
  57. }
  58. protected void setParent(Bone parent) {
  59. this.parent = parent;
  60. }
  61. public String getName() {
  62. return name;
  63. }
  64. public List<Bone> getChildren() {
  65. return children;
  66. }
  67. public float getLength() {
  68. return length;
  69. }
  70. public Vector3f getPosition() {
  71. return position;
  72. }
  73. public Vector4f getRotation() {
  74. return rotation;
  75. }
  76. }