Revisão | 7dd7e71c0c9d32ae1c68f784a97eda4ac53c2f0b (tree) |
---|---|
Hora | 2021-06-07 20:09:07 |
Autor | sebastian_bugiu |
Commiter | sebastian_bugiu |
Now objects from scene get saved as asteroids with position and orientation.
@@ -81,6 +81,9 @@ | ||
81 | 81 | private double currentIntersectedNodeDistance; |
82 | 82 | private Point3D currentIntersectedNodeInitialPos; |
83 | 83 | private HashMap<Node, Group> meshToParentGroupMap = new HashMap<>(); |
84 | + private ArrayList<Asteroid> asteroidList = new ArrayList<>(); | |
85 | + private HashMap<Node, Asteroid> nodeToAsteroidMap = new HashMap<>(); | |
86 | + private HashMap<Node, NodeData> nodeMap = new HashMap<>(); | |
84 | 87 | |
85 | 88 | private AmbientLight ambientLight = new AmbientLight(Color.DARKGREY); |
86 | 89 | private SimpleBooleanProperty ambientLightEnabled = new SimpleBooleanProperty(false) { |
@@ -279,10 +282,6 @@ | ||
279 | 282 | } |
280 | 283 | }; |
281 | 284 | |
282 | - | |
283 | - | |
284 | - private HashMap<Node, NodeData> nodeMap = new HashMap<>(); | |
285 | - | |
286 | 285 | { |
287 | 286 | contentProperty().addListener((ov, oldContent, newContent) -> { |
288 | 287 | // autoScalingGroup.getChildren() |
@@ -297,6 +296,9 @@ | ||
297 | 296 | // Beyond retarded. |
298 | 297 | Group group = (Group) newContent; |
299 | 298 | meshToParentGroupMap.put(group.getChildren().get(0), group); |
299 | + Asteroid asteroid = new Asteroid(); | |
300 | + asteroidList.add(asteroid); | |
301 | + nodeToAsteroidMap.put(group.getChildren().get(0), asteroid); | |
300 | 302 | setWireFrame(newContent, wireframe); |
301 | 303 | // TODO mesh is updated each time these are called even if no rendering needs to happen |
302 | 304 | setSubdivisionLevel(newContent, subdivisionLevel); |
@@ -473,10 +475,20 @@ | ||
473 | 475 | Group group = meshToParentGroupMap.get(currentIntersectedNode); |
474 | 476 | if (group != null) { |
475 | 477 | meshToParentGroupMap.remove(currentIntersectedNode); |
478 | + Asteroid asteroid = nodeToAsteroidMap.remove(currentIntersectedNode); | |
479 | + if (asteroid == null) { | |
480 | + System.out.println("Could not find asteroid to remove"); | |
481 | + } else { | |
482 | + asteroidList.remove(asteroid); | |
483 | + } | |
476 | 484 | boolean remove = autoScalingGroup.getChildren().remove(group); |
477 | 485 | if (!remove) { |
478 | 486 | System.out.println("currentIntersectedNode: " + currentIntersectedNode.getId() + " could not be removed"); |
479 | 487 | } |
488 | + NodeData remove1 = nodeMap.remove(currentIntersectedNode); | |
489 | + if (remove1 == null) { | |
490 | + System.out.println("Could not find nodeData to remove"); | |
491 | + } | |
480 | 492 | resetCurrentIntersectedNode(); |
481 | 493 | } |
482 | 494 | } |
@@ -487,6 +499,10 @@ | ||
487 | 499 | //System.out.println(cameraXform.getTranslateX() + ", " + cameraXform.getTranslateY() + ", " + cameraXform.getTranslateZ()); |
488 | 500 | |
489 | 501 | }; |
502 | + | |
503 | + } | |
504 | + | |
505 | + { | |
490 | 506 | mouseEventHandler = event -> { |
491 | 507 | // System.out.println("MouseEvent ..."); |
492 | 508 |
@@ -557,6 +573,8 @@ | ||
557 | 573 | Point3D p = vecPos.subtract(currentIntersectedNodeInitialPos).multiply(currentIntersectedNodeDistance); |
558 | 574 | nodeData.getNodePos().addInPlace(new ENG_Vector4D(p.getX(), -1 * p.getY(), p.getZ(), 1.0)); |
559 | 575 | // getCurrentIntersectedNodeTransform().appendTranslation(p.getX(), -1 * p.getY(), p.getZ()); |
576 | + Asteroid asteroid = nodeToAsteroidMap.get(currentIntersectedNode); | |
577 | + asteroid.getPosition().set(nodeData.getNodePos()); | |
560 | 578 | currentIntersectedNodeInitialPos = vecPos; |
561 | 579 | currentIntersectedNodeDistance = event.getPickResult().getIntersectedDistance(); |
562 | 580 | } else if (currentModifier == Modifier.ROTATION) { |
@@ -573,6 +591,8 @@ | ||
573 | 591 | nodeRotation.mulInPlace(inverse); |
574 | 592 | nodeRotation.mulInPlace(currentRot); |
575 | 593 | nodeRotation.mulInPlace(currentOrientationCopy); |
594 | + Asteroid asteroid = nodeToAsteroidMap.get(currentIntersectedNode); | |
595 | + asteroid.getOrientation().set(nodeRotation); | |
576 | 596 | // Point3D pivot = new Point3D(getCurrentIntersectedNodeTransform().getTx(), getCurrentIntersectedNodeTransform().getTy(), getCurrentIntersectedNodeTransform().getTz()); |
577 | 597 | // System.out.println("rot pivot: " + pivot); |
578 | 598 | // getCurrentIntersectedNodeTransform().appendRotation(1, new Point3D(0, 0, 0), rotAxis); |
@@ -1029,9 +1049,8 @@ | ||
1029 | 1049 | } |
1030 | 1050 | |
1031 | 1051 | public void export(VelocityContext templateContext) { |
1032 | - ArrayList<Asteroid> asteroids = new ArrayList<>(); | |
1033 | - asteroids.add(new Asteroid("Asteroid0", new ENG_Vector3D(0.0f, 200.0f, -250.0f), new ENG_Quaternion(true), 50)); | |
1034 | - asteroids.add(new Asteroid("Asteroid1", new ENG_Vector3D(1500.0f -200.0f -250.0f), new ENG_Quaternion(true), 50)); | |
1035 | - templateContext.put("asteroids", asteroids); | |
1052 | +// asteroidList.add(new Asteroid("Asteroid0", new ENG_Vector3D(0.0f, 200.0f, -250.0f), new ENG_Quaternion(true), 50)); | |
1053 | +// asteroidList.add(new Asteroid("Asteroid1", new ENG_Vector3D(1500.0f -200.0f -250.0f), new ENG_Quaternion(true), 50)); | |
1054 | + templateContext.put("asteroids", asteroidList); | |
1036 | 1055 | } |
1037 | 1056 | } |
@@ -1135,7 +1135,7 @@ | ||
1135 | 1135 | } |
1136 | 1136 | |
1137 | 1137 | public String toString() { |
1138 | - return (String.valueOf(x) + ", " + String.valueOf(y) + ", " + | |
1139 | - String.valueOf(z) + ", " + String.valueOf(w)); | |
1138 | + return (String.valueOf(x) + " " + String.valueOf(y) + " " + | |
1139 | + String.valueOf(z) + " " + String.valueOf(w)); | |
1140 | 1140 | } |
1141 | 1141 | } |
@@ -514,7 +514,7 @@ | ||
514 | 514 | } |
515 | 515 | |
516 | 516 | public String toString(boolean format, NumberFormat formatter) { |
517 | - return (formatter.format(x) + ", " + formatter.format(y)); | |
517 | + return (x + " " + y); | |
518 | 518 | } |
519 | 519 | |
520 | 520 | public String toString() { |
@@ -673,8 +673,7 @@ | ||
673 | 673 | } |
674 | 674 | |
675 | 675 | public String toString(boolean format, NumberFormat formatter) { |
676 | - return (formatter.format(x) + ", " + formatter.format(y) + ", " + | |
677 | - formatter.format(z)); | |
676 | + return (x + " " + y + " " + z); | |
678 | 677 | } |
679 | 678 | |
680 | 679 | public String toString() { |
@@ -1649,8 +1649,7 @@ | ||
1649 | 1649 | } |
1650 | 1650 | |
1651 | 1651 | public String toString(boolean format, NumberFormat formatter) { |
1652 | - return (/*"Vector3("*/formatter.format(x) + " " + formatter.format(y) + " " + | |
1653 | - formatter.format(z) + " " + formatter.format(w)/* + ")"*/); | |
1652 | + return (x + " " + y + " " + z + " " + w); | |
1654 | 1653 | } |
1655 | 1654 | |
1656 | 1655 | public String toString() { |