Skip to content

Commit 8fae164

Browse files
committed
CHG: overlay compass is a box
1 parent 4907cf2 commit 8fae164

File tree

1 file changed

+67
-6
lines changed

1 file changed

+67
-6
lines changed

src/main/java/sc/iview/commands/edit/AddOrientationCompass.java

Lines changed: 67 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,17 @@
2929
package sc.iview.commands.edit;
3030

3131
import graphics.scenery.*;
32-
import org.joml.Quaternionf;
33-
import org.joml.Vector2f;
3432
import org.joml.Vector3f;
33+
import org.joml.Matrix4f;
34+
import org.joml.Quaternionf;
3535
import org.scijava.command.Command;
3636
import org.scijava.plugin.Menu;
3737
import org.scijava.plugin.Parameter;
3838
import org.scijava.plugin.Plugin;
3939
import sc.iview.SciView;
4040

41+
import java.lang.Math;
42+
4143
import static sc.iview.commands.MenuWeights.EDIT;
4244
import static sc.iview.commands.MenuWeights.EDIT_ADD_COMPASS;
4345

@@ -118,17 +120,76 @@ private Node createCompass() {
118120
return root;
119121
}
120122

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+
121173
@Override
122174
public void run() {
123175
if (showInTheScene) sciView.addNode( createCompass() );
124176
if (attachToCam) {
125-
final Node compass = createCompass();
177+
final Node compass = createBox();
126178
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);
127189

128190
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 );
132193
return null;
133194
});
134195
}

0 commit comments

Comments
 (0)