|
29 | 29 | package sc.iview.commands.edit; |
30 | 30 |
|
31 | 31 | import graphics.scenery.*; |
32 | | -import org.joml.Quaternionf; |
33 | | -import org.joml.Vector2f; |
34 | 32 | import org.joml.Vector3f; |
| 33 | +import org.joml.Matrix4f; |
| 34 | +import org.joml.Quaternionf; |
35 | 35 | import org.scijava.command.Command; |
36 | 36 | import org.scijava.plugin.Menu; |
37 | 37 | import org.scijava.plugin.Parameter; |
38 | 38 | import org.scijava.plugin.Plugin; |
39 | 39 | import sc.iview.SciView; |
40 | 40 |
|
| 41 | +import java.lang.Math; |
| 42 | + |
41 | 43 | import static sc.iview.commands.MenuWeights.EDIT; |
42 | 44 | import static sc.iview.commands.MenuWeights.EDIT_ADD_COMPASS; |
43 | 45 |
|
@@ -118,17 +120,76 @@ private Node createCompass() { |
118 | 120 | return root; |
119 | 121 | } |
120 | 122 |
|
| 123 | + private Node createBox() { |
| 124 | + final Node root = new Node("Scene representing box"); |
| 125 | + |
| 126 | + // X - red edges |
| 127 | + final float halfPI = (float)(0.5*Math.PI); |
| 128 | + final float edgeLen = 0.05f; |
| 129 | + final float edgeRadius = 0.0008f; |
| 130 | + for (int i = 0; i < 4; ++i) |
| 131 | + { |
| 132 | + final Node n = new Cylinder(edgeRadius,edgeLen,4); |
| 133 | + n.getPosition().set( -0.5f * edgeLen ); |
| 134 | + n.getPosition().add( new Vector3f(0, i%2 *edgeLen, i < 2 ? 0 : edgeLen) ); |
| 135 | + n.setRotation( new Quaternionf().rotateXYZ(0,0,-halfPI).normalize() ); |
| 136 | + n.setName("box edge: X"); |
| 137 | + n.getMaterial().getDiffuse().set( new Vector3f(1,0,0) ); |
| 138 | + n.getMaterial().setDepthTest(Material.DepthTest.Always); |
| 139 | + //n.getMaterial().getBlending().setTransparent(true); |
| 140 | + root.addChild( n ); |
| 141 | + } |
| 142 | + |
| 143 | + // Y - green edges |
| 144 | + for (int i = 0; i < 4; ++i) |
| 145 | + { |
| 146 | + final Node n = new Cylinder(edgeRadius,edgeLen,4); |
| 147 | + n.getPosition().set( -0.5f * edgeLen ); |
| 148 | + n.getPosition().add( new Vector3f(i%2 *edgeLen, 0, i < 2 ? 0 : edgeLen) ); |
| 149 | + n.setName("box edge: Y"); |
| 150 | + n.getMaterial().getDiffuse().set( new Vector3f(0,1,0) ); |
| 151 | + n.getMaterial().setDepthTest(Material.DepthTest.Always); |
| 152 | + //n.getMaterial().getBlending().setTransparent(true); |
| 153 | + root.addChild( n ); |
| 154 | + } |
| 155 | + |
| 156 | + // Z - blue edges |
| 157 | + for (int i = 0; i < 4; ++i) |
| 158 | + { |
| 159 | + final Node n = new Cylinder(edgeRadius,edgeLen,4); |
| 160 | + n.getPosition().set( -0.5f * edgeLen ); |
| 161 | + n.getPosition().add( new Vector3f(i%2 *edgeLen, i < 2 ? 0 : edgeLen, 0) ); |
| 162 | + n.setRotation( new Quaternionf().rotateXYZ(halfPI,0,0).normalize() ); |
| 163 | + n.setName("box edge: Z"); |
| 164 | + n.getMaterial().getDiffuse().set( new Vector3f(0,0,1) ); |
| 165 | + n.getMaterial().setDepthTest(Material.DepthTest.Always); |
| 166 | + //n.getMaterial().getBlending().setTransparent(true); |
| 167 | + root.addChild( n ); |
| 168 | + } |
| 169 | + |
| 170 | + return root; |
| 171 | + } |
| 172 | + |
121 | 173 | @Override |
122 | 174 | public void run() { |
123 | 175 | if (showInTheScene) sciView.addNode( createCompass() ); |
124 | 176 | if (attachToCam) { |
125 | | - final Node compass = createCompass(); |
| 177 | + final Node compass = createBox(); |
126 | 178 | sciView.getCamera().addChild( compass ); |
| 179 | + compass.setWantsComposeModel(false); |
| 180 | + |
| 181 | + final float xStretch = sciView.getCamera().getProjection().m00(); |
| 182 | + final float yStretch = sciView.getCamera().getProjection().m11(); |
| 183 | + // |
| 184 | + final Matrix4f positionDaBox = new Matrix4f(); |
| 185 | + positionDaBox.set(1,0,0,0, //1st col |
| 186 | + 0,1,0,0, //2nd col |
| 187 | + 0,0,1,0, |
| 188 | + -0.9f/xStretch,+0.85f/yStretch,-1.0f,1); |
127 | 189 |
|
128 | 190 | compass.getUpdate().add(() -> { |
129 | | - final Camera cam = sciView.getCamera(); |
130 | | - compass.setPosition(cam.viewportToView(new Vector2f(-0.9f, 0.7f))); |
131 | | - compass.setRotation(new Quaternionf(sciView.getCamera().getRotation()).conjugate()); |
| 191 | + sciView.getCamera().getRotation().get( compass.getModel() ); |
| 192 | + compass.getModel().mulLocal( positionDaBox ); |
132 | 193 | return null; |
133 | 194 | }); |
134 | 195 | } |
|
0 commit comments