1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
package sample3d; import javafx.application.Application; import javafx.scene.paint.Color; import my3d._math3d; import my3d._math3d.*; import my3d._shape3d; import my3d._shape3d.*; import my3d._slider_dialog; import my3d._slider_dialog.*; import my3d._viewer3d3; import my3d._viewport3d; public class _sample09 extends _viewer3d3 { public static void main(String... args) { Application.launch(args); } private _shape3d box = _shape3d.create_box(0.6, 0.4, 1.5); private _slider_dialog[] pose_dlgs = new _slider_dialog[2]; private _quaternion[] qa = {new _quaternion(), new _quaternion()}; private int curr_index; private _slider_data[] POSE_DATA = { new _slider_data("水平", 180, -180, 0), new _slider_data("垂直", -90, 90, 0), new _slider_data("傾き", 180, -180, 0), }; @Override public void init_scene(_viewport3d vp) { set_animation_enable(true); int c = 1; for (_face face : box.faces) { face.set_color(new Color(c / 4, c % 4 / 2, c % 2, 1)); c++; } for (int i = 0; i < 2; i++) { pose_dlgs[i] = new _slider_dialog(stage, "ポーズ" + (i + 1), (values) -> { double tx, ty, tz; ty = values[0] * Math.PI / 180; tx = values[1] * Math.PI / 180; tz = values[2] * Math.PI / 180; _quaternion.euler(tx, ty ,tz, qa[curr_index]); repaint(); }, POSE_DATA ); } add_app_menu((index) -> { curr_index = index; set_anim_pos(index); _slider_dialog dlg = pose_dlgs[index]; if (!dlg.isShowing()) dlg.showAndWait(); else dlg.requestFocus(); }, "rポーズ1", "rポーズ2" ); } private _transform tf = new _transform(); private _quaternion q_buf = new _quaternion(); @Override public void render(_viewport3d vp) { double pos = get_anim_pos(); _math3d.slerp(qa[0], qa[1], pos, q_buf).to_matrix(tf.orientation); vp.push_transform(tf); vp.render_shape(box); } }