use of javax.media.j3d.Transform3D in project ffx by mjschnie.
the class GraphicsAxis method createAxisLabel.
@SuppressWarnings("unchecked")
private TransformGroup createAxisLabel(String letter, Font3D font3d, Appearance ap, double x, double y, double z) {
Text3D text = new Text3D(font3d, letter);
text.setUserData(this);
Transform3D t3D = new Transform3D();
t3D.setTranslation(new Vector3d(x, y, z));
TransformGroup tg = new TransformGroup(t3D);
Shape3D text3d = new Shape3D(text, ap);
text3d.setUserData(this);
for (Enumeration<Geometry> e = text3d.getAllGeometries(); e.hasMoreElements(); ) {
Geometry g = e.nextElement();
g.setCapability(Geometry.ALLOW_INTERSECT);
}
text3d.setCapability(Shape3D.ENABLE_PICK_REPORTING);
text3d.setCapability(Shape3D.ALLOW_GEOMETRY_READ);
tg.addChild(text3d);
return tg;
}
use of javax.media.j3d.Transform3D in project ffx by mjschnie.
the class MolecularAssembly method createScene.
/**
* The MolecularAssembly BranchGroup has two TransformGroups between it and
* the "base" node where geometry is attached. If the point between the two
* transformations is where user rotation occurs. For example, if rotating
* about the center of mass of the system, the RotToCOM transformation will
* be an identity transformation (ie. none). If rotation is about some atom
* or group of atoms within the system, then the RotToCOM transformation
* will be a translation from that point to the COM.
*
* @param zero boolean
* @return BranchGroup
*/
public BranchGroup createScene(boolean zero) {
originToRotT3D = new Transform3D();
originToRotV3D = new Vector3d();
originToRot = new TransformGroup(originToRotT3D);
branchGroup = new BranchGroup();
rotToCOM = new TransformGroup();
rotToCOMT3D = new Transform3D();
rotToCOMV3D = new Vector3d();
// Set capabilities needed for picking and moving the MolecularAssembly
branchGroup.setCapability(BranchGroup.ALLOW_DETACH);
originToRot.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
originToRot.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
originToRot.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
rotToCOM.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
rotToCOM.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
// Put the MolecularAssembly in the middle of the scene
if (zero) {
originToRotV3D.set(0.0, 0.0, 0.0);
originToRotT3D.set(originToRotV3D);
originToRot.setTransform(originToRotT3D);
}
wire = renderWire();
switchGroup = new Switch(Switch.CHILD_NONE);
switchGroup.setCapability(Switch.ALLOW_SWITCH_WRITE);
base = new BranchGroup();
base.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
base.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
childNodes = new BranchGroup();
childNodes.setCapability(BranchGroup.ALLOW_DETACH);
childNodes.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
childNodes.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
switchGroup.addChild(base);
if (wire != null) {
base.addChild(wire);
}
vrml = loadVRML();
if (vrml != null) {
vrmlTG = new TransformGroup();
vrmlTd = new Transform3D();
vrmlTG.setTransform(vrmlTd);
vrmlTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
vrmlTG.addChild(vrml);
switchGroup.addChild(vrmlTG);
setView(RendererCache.ViewModel.INVISIBLE, null);
}
switchGroup.setWhichChild(Switch.CHILD_ALL);
rotToCOM.addChild(switchGroup);
originToRot.addChild(rotToCOM);
branchGroup.addChild(originToRot);
branchGroup.compile();
return branchGroup;
}
use of javax.media.j3d.Transform3D in project ffx by mjschnie.
the class RendererCache method transform3DFactory.
/**
* <p>
* transform3DFactory</p>
*
* @param position a {@link javax.vecmath.Vector3d} object.
* @param scale a double.
* @return a {@link javax.media.j3d.Transform3D} object.
*/
public static final Transform3D transform3DFactory(Vector3d position, double scale) {
Transform3D transform3D;
if (transform3DPool.size() > 0) {
transform3D = transform3DPool.get(0);
if (transform3D != null) {
transform3D.setTranslation(position);
transform3D.setScale(scale);
return transform3D;
}
}
transform3D = new Transform3D();
transform3D.setTranslation(position);
transform3D.setScale(scale);
return transform3D;
}
use of javax.media.j3d.Transform3D in project ffx by mjschnie.
the class MouseOrbit method processStimulus.
/**
* {@inheritDoc}
*/
public void processStimulus(Enumeration criteria) {
WakeupCriterion wakeup;
AWTEvent[] event;
int id;
int dx, dy;
while (criteria.hasMoreElements()) {
wakeup = (WakeupCriterion) criteria.nextElement();
if (wakeup instanceof WakeupOnAWTEvent) {
event = ((WakeupOnAWTEvent) wakeup).getAWTEvent();
for (int i = 0; i < event.length; i++) {
processMouseEvent((MouseEvent) event[i]);
if (((buttonPress) && ((flags & MANUAL_WAKEUP) == 0)) || ((wakeUp) && ((flags & MANUAL_WAKEUP) != 0))) {
id = event[i].getID();
if ((id == MouseEvent.MOUSE_DRAGGED)) {
x = ((MouseEvent) event[i]).getX();
y = ((MouseEvent) event[i]).getY();
dx = x - x_last;
dy = y - y_last;
if (!reset) {
Transform3D tempT3D = new Transform3D();
Transform3D orbitT3D = new Transform3D();
tempT3D.rotX(-dy * y_factor);
orbitT3D.mul(tempT3D);
tempT3D.rotY(-dx * x_factor);
orbitT3D.mul(tempT3D);
Transform3D tg_ghost_T3D = new Transform3D();
tg_ghost.getTransform(tg_ghost_T3D);
Vector3f tg_ghost_vec3f = new Vector3f();
tg_ghost_T3D.get(tg_ghost_vec3f);
Matrix4d tg_ghost_mat4d = new Matrix4d();
tg_ghost_T3D.get(tg_ghost_mat4d);
Transform3D VPTG_ghost_T3D_inverted = new Transform3D();
Transform3D VPTG_ghost_T3D_noninverted = new Transform3D();
// (super.ViewerTG).getTransform(VPTG_ghost_T3D_inverted);
ViewerTG.getTransform(VPTG_ghost_T3D_inverted);
// (super.ViewerTG).getTransform(VPTG_ghost_T3D_noninverted);
ViewerTG.getTransform(VPTG_ghost_T3D_noninverted);
VPTG_ghost_T3D_inverted.setTranslation(new Vector3d(0.0, 0.0, 0.0));
VPTG_ghost_T3D_noninverted.setTranslation(new Vector3d(0.0, 0.0, 0.0));
VPTG_ghost_T3D_inverted.invert();
tg_ghost_T3D.mul(VPTG_ghost_T3D_inverted, tg_ghost_T3D);
tg_ghost_T3D.setTranslation(new Vector3d(0.0, 0.0, 0.0));
if (invert) {
tg_ghost_T3D.mul(tg_ghost_T3D, orbitT3D);
} else {
tg_ghost_T3D.mul(orbitT3D, tg_ghost_T3D);
}
tg_ghost_T3D.mul(VPTG_ghost_T3D_noninverted, tg_ghost_T3D);
tg_ghost_T3D.setTranslation(tg_ghost_vec3f);
tg_ghost.setTransform(tg_ghost_T3D);
VPTG_ghost_T3D = new Transform3D();
// (super.ViewerTG).getTransform(VPTG_ghost_T3D);
ViewerTG.getTransform(VPTG_ghost_T3D);
Vector3f VPTG_ghost_vec3f = new Vector3f();
VPTG_ghost_T3D.get(VPTG_ghost_vec3f);
Vector3f temp_vec3f = new Vector3f();
temp_vec3f.x = VPTG_ghost_vec3f.x - tg_ghost_vec3f.x;
temp_vec3f.y = VPTG_ghost_vec3f.y - tg_ghost_vec3f.y;
temp_vec3f.z = VPTG_ghost_vec3f.z - tg_ghost_vec3f.z;
VPTG_ghost_T3D.setTranslation(temp_vec3f);
VPTG_ghost_T3D.mul(VPTG_ghost_T3D_inverted, VPTG_ghost_T3D);
if (invert) {
VPTG_ghost_T3D.mul(VPTG_ghost_T3D, orbitT3D);
} else {
VPTG_ghost_T3D.mul(orbitT3D, VPTG_ghost_T3D);
}
VPTG_ghost_T3D.mul(VPTG_ghost_T3D_noninverted, VPTG_ghost_T3D);
VPTG_ghost_T3D.get(temp_vec3f);
temp_vec3f.x = temp_vec3f.x + tg_ghost_vec3f.x;
temp_vec3f.y = temp_vec3f.y + tg_ghost_vec3f.y;
temp_vec3f.z = temp_vec3f.z + tg_ghost_vec3f.z;
VPTG_ghost_T3D.setTranslation(temp_vec3f);
// (super.ViewerTG).setTransform(VPTG_ghost_T3D);
ViewerTG.setTransform(VPTG_ghost_T3D);
transformChanged(currXform);
if (callback != null) {
callback.transformChanged(MouseBehaviorCallback.ORBIT, currXform);
}
} else {
reset = false;
}
x_last = x;
y_last = y;
} else if (id == MouseEvent.MOUSE_PRESSED) {
x_last = ((MouseEvent) event[i]).getX();
y_last = ((MouseEvent) event[i]).getY();
}
}
}
}
}
wakeupOn(mouseCriterion);
}
use of javax.media.j3d.Transform3D in project ffx by mjschnie.
the class MouseTranslate method processStimulus.
/**
* {@inheritDoc}
*/
public void processStimulus(Enumeration criteria) {
while (criteria.hasMoreElements()) {
WakeupCriterion wakeup = (WakeupCriterion) criteria.nextElement();
if (wakeup instanceof WakeupOnAWTEvent) {
AWTEvent[] event = ((WakeupOnAWTEvent) wakeup).getAWTEvent();
for (int i = 0; i < event.length; i++) {
MouseEvent mevent = (MouseEvent) event[i];
processMouseEvent(mevent);
int id = event[i].getID();
int mod = mevent.getModifiersEx();
boolean rightButton = ((mod & mouseButton) == mouseButton);
if (!rightButton) {
rightButton = ((mod & MouseEvent.SHIFT_DOWN_MASK) == MouseEvent.SHIFT_DOWN_MASK);
}
if ((id == MouseEvent.MOUSE_DRAGGED) && rightButton && transformGroup != null) {
x = ((MouseEvent) event[i]).getX();
y = ((MouseEvent) event[i]).getY();
int dx = x - x_last;
int dy = y - y_last;
if ((!reset) && ((Math.abs(dy) < 50) && (Math.abs(dx) < 50))) {
transformGroup.getTransform(currXform);
Transform3D VPTG_T3D = new Transform3D();
ViewerTG.getTransform(VPTG_T3D);
VPTG_T3D.setTranslation(zero3d);
VPTG_T3D.invert();
currXform.mul(VPTG_T3D, currXform);
translation.x = dx * x_factor;
translation.y = -dy * y_factor;
transformX.set(translation);
if (invert) {
currXform.mul(currXform, transformX);
} else {
currXform.mul(transformX, currXform);
}
VPTG_T3D.invert();
currXform.mul(VPTG_T3D, currXform);
transformGroup.setTransform(currXform);
transformChanged(currXform);
if (callback != null) {
callback.transformChanged(MouseBehaviorCallback.TRANSLATE, currXform);
}
} else {
reset = false;
}
x_last = x;
y_last = y;
}
if (id == MouseEvent.MOUSE_PRESSED) {
x_last = ((MouseEvent) event[i]).getX();
y_last = ((MouseEvent) event[i]).getY();
} else if (id == MouseEvent.MOUSE_RELEASED) {
setTransformGroup(null);
}
}
}
}
if (transformGroup != null) {
wakeupOn(mouseCriterion);
} else {
mouseButton = MouseEvent.BUTTON3_DOWN_MASK;
postId(doneID);
wakeupOn(postCriterion);
}
}
Aggregations