java - JavaFX 3D - How to set different cameras for Group with 3D object and SubScene with UI Controls? -
due new features in javafx 8, became possible combine 3d objects 2d ui controls.
i used documents manuals: javafx tutorial, exploring javafx 3d.
so, made code:
public class castanalytics extends application { final group root = new group(); final group axisgroup = new group(); final xform world = new xform(); final perspectivecamera camera = new perspectivecamera(true); final perspectivecamera subscenecamera = new perspectivecamera(false); final xform cameraxform = new xform(); final xform cameraxform2 = new xform(); final xform cameraxform3 = new xform(); final double cameradistance = 450; final xform moleculegroup = new xform(); private timeline timeline; boolean timelineplaying = false; double control_multiplier = 0.1; double shift_multiplier = 0.1; double alt_multiplier = 0.5; double mouseposx; double mouseposy; double mouseoldx; double mouseoldy; double mousedeltax; double mousedeltay; @override public void start(stage primarystage) throws exception{ buildscene(); buildcamera(); buildaxes(); scene scene = new scene(root, 1024, 768, true); scene.setfill(color.grey); handlekeyboard(scene, world); handlemouse(scene, world); primarystage.settitle("sample application"); primarystage.setscene(scene); primarystage.show(); scene.setcamera(subscenecamera); scene.setcamera(camera); } private void buildscene() { root.getchildren().add(world); label label = new label("123"); hbox hbox = new hbox(); hbox.getchildren().add(label); subscene subscene = new subscene(hbox, 200, 200); subscene.setlayoutx(100); subscene.setlayouty(100); root.getchildren().addall(subscene); } private void buildcamera() { root.getchildren().addall(cameraxform); cameraxform.getchildren().add(cameraxform2); cameraxform2.getchildren().add(cameraxform3); cameraxform3.getchildren().add(camera); cameraxform3.setrotatez(180.0); camera.setnearclip(0.1); camera.setfarclip(10000.0); camera.settranslatez(-cameradistance); cameraxform.ry.setangle(320.0); cameraxform.rx.setangle(40); } private void buildaxes() { box box = new box(200,200,200); axisgroup.getchildren().addall(box); world.getchildren().addall(axisgroup); } private void handlemouse(scene scene, final node root) { scene.setonmousepressed(new eventhandler<mouseevent>() { @override public void handle(mouseevent me) { mouseposx = me.getscenex(); mouseposy = me.getsceney(); mouseoldx = me.getscenex(); mouseoldy = me.getsceney(); } }); scene.setonmousedragged(new eventhandler<mouseevent>() { @override public void handle(mouseevent me) { mouseoldx = mouseposx; mouseoldy = mouseposy; mouseposx = me.getscenex(); mouseposy = me.getsceney(); mousedeltax = (mouseposx - mouseoldx); mousedeltay = (mouseposy - mouseoldy); double modifier = 1.0; double modifierfactor = 0.1; if (me.iscontroldown()) { modifier = 0.1; } if (me.isshiftdown()) { modifier = 10.0; } if (me.isprimarybuttondown()) { cameraxform.ry.setangle(cameraxform.ry.getangle() - mousedeltax * modifierfactor * modifier * 2.0); // + cameraxform.rx.setangle(cameraxform.rx.getangle() + mousedeltay * modifierfactor * modifier * 2.0); // - } else if (me.issecondarybuttondown()) { double z = camera.gettranslatez(); double newz = z + mousedeltax * modifierfactor * modifier; camera.settranslatez(newz); } else if (me.ismiddlebuttondown()) { cameraxform2.t.setx(cameraxform2.t.getx() + mousedeltax * modifierfactor * modifier * 0.3); // - cameraxform2.t.sety(cameraxform2.t.gety() + mousedeltay * modifierfactor * modifier * 0.3); // - } } }); } private void handlekeyboard(scene scene, final node root) { final boolean movecamera = true; scene.setonkeypressed(new eventhandler<keyevent>() { @override public void handle(keyevent event) { duration currenttime; switch (event.getcode()) { case z: if (event.isshiftdown()) { cameraxform.ry.setangle(0.0); cameraxform.rx.setangle(0.0); camera.settranslatez(-300.0); } cameraxform2.t.setx(0.0); cameraxform2.t.sety(0.0); break; case x: if (event.iscontroldown()) { if (axisgroup.isvisible()) { axisgroup.setvisible(false); } else { axisgroup.setvisible(true); } } break; case s: if (event.iscontroldown()) { if (moleculegroup.isvisible()) { moleculegroup.setvisible(false); } else { moleculegroup.setvisible(true); } } break; case space: if (timelineplaying) { timeline.pause(); timelineplaying = false; } else { timeline.play(); timelineplaying = true; } break; case up: if (event.iscontroldown() && event.isshiftdown()) { cameraxform2.t.sety(cameraxform2.t.gety() - 10.0 * control_multiplier); } else if (event.isaltdown() && event.isshiftdown()) { cameraxform.rx.setangle(cameraxform.rx.getangle() - 10.0 * alt_multiplier); } else if (event.iscontroldown()) { cameraxform2.t.sety(cameraxform2.t.gety() - 1.0 * control_multiplier); } else if (event.isaltdown()) { cameraxform.rx.setangle(cameraxform.rx.getangle() - 2.0 * alt_multiplier); } else if (event.isshiftdown()) { double z = camera.gettranslatez(); double newz = z + 5.0 * shift_multiplier; camera.settranslatez(newz); } break; case down: if (event.iscontroldown() && event.isshiftdown()) { cameraxform2.t.sety(cameraxform2.t.gety() + 10.0 * control_multiplier); } else if (event.isaltdown() && event.isshiftdown()) { cameraxform.rx.setangle(cameraxform.rx.getangle() + 10.0 * alt_multiplier); } else if (event.iscontroldown()) { cameraxform2.t.sety(cameraxform2.t.gety() + 1.0 * control_multiplier); } else if (event.isaltdown()) { cameraxform.rx.setangle(cameraxform.rx.getangle() + 2.0 * alt_multiplier); } else if (event.isshiftdown()) { double z = camera.gettranslatez(); double newz = z - 5.0 * shift_multiplier; camera.settranslatez(newz); } break; case right: if (event.iscontroldown() && event.isshiftdown()) { cameraxform2.t.setx(cameraxform2.t.getx() + 10.0 * control_multiplier); } else if (event.isaltdown() && event.isshiftdown()) { cameraxform.ry.setangle(cameraxform.ry.getangle() - 10.0 * alt_multiplier); } else if (event.iscontroldown()) { cameraxform2.t.setx(cameraxform2.t.getx() + 1.0 * control_multiplier); } else if (event.isaltdown()) { cameraxform.ry.setangle(cameraxform.ry.getangle() - 2.0 * alt_multiplier); } break; case left: if (event.iscontroldown() && event.isshiftdown()) { cameraxform2.t.setx(cameraxform2.t.getx() - 10.0 * control_multiplier); } else if (event.isaltdown() && event.isshiftdown()) { cameraxform.ry.setangle(cameraxform.ry.getangle() + 10.0 * alt_multiplier); // - } else if (event.iscontroldown()) { cameraxform2.t.setx(cameraxform2.t.getx() - 1.0 * control_multiplier); } else if (event.isaltdown()) { cameraxform.ry.setangle(cameraxform.ry.getangle() + 2.0 * alt_multiplier); // - } break; } } }); } public static void main(string[] args) { launch(args); } }
but te result isn't expected. wanted have pane
ui controls above 3d object, this:
what doing wrong?
from understand (limited) tests have done, there 2 options:
set camera sub-scene , add sub-scene root. using 1 camera. world have separate group , flying/pivoting camera view have accomplished transforming world group.
file bug report javafx jira.
i not successful using separate camera sub-scene camera. no transforms applied camera or sub-scene ever rotated sub-scene default position similar 1 in screenshot. @ point oracle not releasing sub-scene documentation, can wait till come clean , fill gaps. until can consider subscene support in javafx 3d broken.
Comments
Post a Comment