mardi 2 juin 2015

JavaFX Image View Würfel berechnen

Hallo

ich habe ein problem ich habe diese zwei Klassen hier gemacht

Java Code:

  1.  
  2. import javafx.scene.Group;
  3.  
  4.  
  5. public class Cube extends Group{
  6.  
  7. private static Wall w1;
  8. private static Wall w2;
  9. private static Wall w3;
  10. private static Wall w4;
  11. private static Wall w5;
  12. private static Wall w6;
  13.  
  14.  
  15. public Cube(String name,String Input,double x,double y,double z){
  16.  
  17. w1 = new Wall(Input,name);
  18. w1.addToGroup(QuickSpiel.wo, name);
  19. w1.setPos(name, x + w1.getWidth(name)/2, y, z);
  20. w1.setRotation(name, 0, 90, 0);
  21.  
  22. String name2 = name + "1";
  23. w2 = new Wall(Input, name2);
  24. w1.addToGroup(QuickSpiel.wo, name2);
  25. w2.setPos(name2, x, y, z + w2.getDepth(name2)/2);
  26.  
  27. String name3 = name + "2";
  28. w3 = new Wall(Input,name3);
  29. w1.addToGroup(QuickSpiel.wo, name3);
  30. w3.setPos(name3, x, y + w3.getHeight(name3)/2, z);
  31. w3.setRotation(name3, 90, 0, 0);
  32.  
  33. String name4 = name + "3";
  34. w4 = new Wall(Input,name4);
  35. w1.addToGroup(QuickSpiel.wo, name4);
  36. w4.setPos(name4, x, y - w4.getHeight(name4)/2, z);
  37. w4.setRotation(name4, 90, 0, 0);
  38.  
  39. String name5 = name + "4";
  40. w5 = new Wall(Input,name5);
  41. w1.addToGroup(QuickSpiel.wo, name5);
  42. w5.setPos(name5, x - w5.getWidth(name5)/2, y, z);
  43. w5.setRotation(name5, 0, 90, 0);
  44.  
  45. String name6 = name + "5";
  46. w6 = new Wall(Input, name6);
  47. w1.addToGroup(QuickSpiel.wo, name6);
  48. w6.setPos(name6, x, y, z - w2.getDepth(name6)/2);
  49.  
  50.  
  51.  
  52. }
  53. }


und

Java Code:

  1.  
  2. package Spiele.MrTroble;
  3.  
  4.  
  5. import java.util.ArrayList;
  6.  
  7.  
  8. import javafx.geometry.Point3D;
  9. import javafx.scene.Group;
  10. import javafx.scene.Node;
  11. import javafx.scene.image.Image;
  12. import javafx.scene.image.ImageView;
  13. import javafx.scene.transform.Rotate;
  14.  
  15.  
  16. public class Wall extends Group{
  17.  
  18. private static final ArrayList<ImageView[]> list = new ArrayList<ImageView[]>();
  19. private static final ArrayList<String[]> Source = new ArrayList<String[]>();
  20. private static final ArrayList<double[]> koord = new ArrayList<double[]>();
  21.  
  22.  
  23. public Wall(String ip,String src){
  24. this(ip, src, true);
  25. }
  26.  
  27. public Wall(String ip,String sourc,boolean vis){
  28. this(ip,sourc,0,0,0,vis);
  29. }
  30.  
  31. public Wall(String ip,String sourc,double x,double y,double z,boolean vis){
  32. this(ip,sourc,x,y,z,0,0,0,vis);
  33. }
  34.  
  35. public Wall(String ip,String sourc,double x,double y,double z,double rotX,double rotY,double rotZ,boolean vis){
  36. ImageView vw = new ImageView(new Image(Cube.class.getResourceAsStream(ip)));
  37. vw.setTranslateX(x);
  38. vw.setTranslateY(y);
  39. vw.setTranslateZ(z);
  40.  
  41. Rotate xr = new Rotate(rotX, Rotate.X_AXIS);
  42. Rotate yr = new Rotate(rotY, Rotate.Y_AXIS);
  43. Rotate zr = new Rotate(rotZ, Rotate.Z_AXIS);
  44.  
  45. vw.getTransforms().addAll(xr,yr,zr);
  46. vw.setVisible(vis);
  47.  
  48. ImageView[] im = {vw};
  49. String[] src = {sourc};
  50. double[] ifo = {x,y,z,vw.layoutBoundsProperty().get().getWidth(),vw.layoutBoundsProperty().get().getHeight(),vw.layoutBoundsProperty().get().getDepth(),rotX,rotY,rotZ};
  51. koord.add(ifo);
  52. Source.add(src);
  53. list.add(im);
  54.  
  55. }
  56.  
  57. public ImageView getImageView(int place){
  58. return list.get(place)[0];
  59. }
  60.  
  61. public static ImageView getImageView(String src){
  62. return list.get(getPlace(src))[0];
  63. }
  64.  
  65. public static int getPlace(String source){
  66. int i = 0;
  67. while(!(source == Source.get(i)[0])){
  68. if(i == getSize()){
  69. Logger.Error("Array Limite has reatched");
  70. return (Integer) null;
  71. }
  72. i += 1;
  73. }
  74. return i;
  75. }
  76.  
  77. public String getName(int place){
  78. return Source.get(place)[0];
  79. }
  80.  
  81. public void addToGroup(Group g,String n){
  82. g.getChildren().add(getImageView(n));
  83. }
  84.  
  85. public static int getSize(){
  86. return Source.size();
  87. }
  88.  
  89. public void setPos(String src,double x,double y,double z){
  90. ImageView v = getImageView(src);
  91. v.setTranslateX(x);
  92. v.setTranslateY(y);
  93. v.setTranslateZ(z);
  94. add(v,src);
  95. }
  96.  
  97. public void setRotation(String src,double rx,double ry,double rz){
  98. Rotate xr = new Rotate(rx, Rotate.X_AXIS);
  99. Rotate yr = new Rotate(ry, Rotate.Y_AXIS);
  100. Rotate zr = new Rotate(rz, Rotate.Z_AXIS);
  101.  
  102. getImageView(src).getTransforms().addAll(xr,yr,zr);
  103. add(getImageView(src), src);
  104. }
  105.  
  106. private static void add(Node vw,String sourc){
  107. double[] ifo = {vw.getTranslateX(),vw.getTranslateY(),vw.getTranslateZ(),vw.layoutBoundsProperty().get().getWidth(),vw.layoutBoundsProperty().get().getHeight(),vw.layoutBoundsProperty().get().getDepth(),vw.getTransforms().get(0).getTx(),vw.getTransforms().get(0).getTy(),vw.getTransforms().get(0).getTz()};
  108. koord.set(getPlace(sourc), ifo);
  109. }
  110.  
  111. public double getHeight(String src){
  112. return koord.get(getPlace(src))[3];
  113. }
  114.  
  115. public double getWidth(String src){
  116. return koord.get(getPlace(src))[4];
  117. }
  118.  
  119. public double getDepth(String src){
  120. return koord.get(getPlace(src))[5];
  121. }
  122.  
  123. public Point3D getPos(String src){
  124. Point3D p = new Point3D(getImageView(src).getTranslateX(), getImageView(src).getTranslateY(), getImageView(src).getTranslateX());
  125. return p;
  126. }
  127.  
  128. public String toString(){
  129. String st = "";
  130. int i = 0;
  131. while(!(i == getSize())){
  132. st += getName(i);
  133. }
  134.  
  135. return "Size from List:" + getSize() + String.format("%n") + "Names:" + st;
  136. }
  137. public void setVisible(String src,boolean vis){
  138. getImageView(src).setVisible(vis);
  139.  
  140.  
  141. }
  142. public boolean isVisible(String src){
  143. return getImageView(src).isVisible();
  144. }
  145. }


so ausgeführt

Java Code:

  1.  
  2. Cube w = new Cube("Hollo","WallNormal.png", 5, 5, 5);


dabei Rausgekommen ist:
Miniaturansichten angehängter Grafiken
Klicken Sie auf die Grafik für eine größere Ansicht  Name: Das hier.jpg  Hits: -  Größe: 19,9 KB  ID: 7841  


JavaFX Image View Würfel berechnen

0 commentaires:

Enregistrer un commentaire