protected void setUniformValues(GL gl, GlslProgram prog) {
   super.setUniformValues(gl, prog);
   // some matrix in gl(3)
   double a = 3, b = 2, c = -.1;
   Matrix m = new Matrix(0, -a, -b, 0, a, 0, -c, 0, b, c, 0, 0, 0, 0, 0, 0);
   // Matrix m = MatrixBuilder.euclidean().rotate(Math.PI/2, 0,0,1).getMatrix();
   prog.setUniformMatrix("matrix", m.getArray());
   prog.setUniform("h", 0.005);
   prog.setUniform("r3", true);
 }
Ejemplo n.º 2
0
/** @author weissman */
public class VirtualRotation implements VirtualDevice {

  InputSlot pointerNDC;
  InputSlot cameraToWorld;

  InputSlot out;

  private double gain = 4;
  //  private double aspectRatio = 1;

  private Matrix result = new Matrix();
  private DoubleArray da = new DoubleArray(result.getArray());

  private double oldX = Integer.MAX_VALUE, oldY;
  private double[] mouseCoords = new double[3], mouseCoordsOld = new double[3];

  public ToolEvent process(VirtualDeviceContext context) throws MissingSlotException {
    if (context.getEvent().getInputSlot() == cameraToWorld) return null;
    DoubleArray pointer = context.getTransformationMatrix(pointerNDC);
    if (pointer == null) throw new MissingSlotException(pointerNDC);
    if (oldX == Integer.MAX_VALUE) {
      oldX = pointer.getValueAt(3);
      oldY = pointer.getValueAt(7);
      return null;
    }
    double x = pointer.getValueAt(3);
    double y = pointer.getValueAt(7);
    double dist = x * x + y * y;
    double z = 2 > dist ? Math.sqrt(2 - dist) : 0;
    Rn.setToValue(mouseCoords, x, y, z);

    mouseCoords = Rn.normalize(mouseCoords, mouseCoords);
    double[] cross = Rn.crossProduct(null, mouseCoordsOld, mouseCoords);
    double angle = gain * Math.asin(Rn.euclideanNorm(cross));
    double[] cross4 = {cross[0], cross[1], cross[2], 0};
    cross = new Matrix(context.getTransformationMatrix(cameraToWorld)).multiplyVector(cross4);
    result.assignFrom(P3.makeRotationMatrix(null, cross, angle));
    Rn.setToValue(mouseCoordsOld, x, y, z);
    return new ToolEvent(this, context.getEvent().getTimeStamp(), out, da);
  }

  public void initialize(List inputSlots, InputSlot result, Map configuration) {
    pointerNDC = (InputSlot) inputSlots.get(0);
    cameraToWorld = (InputSlot) inputSlots.get(1);
    out = result;
    if (configuration != null)
      try {
        gain = ((Double) configuration.get("gain")).doubleValue();
      } catch (Exception e) {
      }
  }

  public void dispose() {}

  public String getName() {
    return "Virtual: Rotation";
  }
}
  public void alignContent() {
    try {
      bounds = calculateBoundingBox(wrap(content));
    } catch (Exception e) {
      return;
    }
    removeZeroExtends(bounds);
    double scale = 1;
    double[] e = bounds.getExtent();
    double[] center = bounds.getCenter();
    double objectSize = Math.max(Math.max(e[0], e[1]), e[2]);
    scale = contentSize / objectSize;
    Matrix matrix = MatrixBuilder.euclidean().scale(scale).getMatrix();

    matrix.assignTo(scalingComponent);

    bounds = bounds.transformByMatrix(bounds, matrix.getArray());
    center = bounds.getCenter();

    FactoredMatrix factoredMatrix = new FactoredMatrix(transformationComponent.getTransformation());
    double angle = factoredMatrix.getRotationAngle();
    double[] axis = factoredMatrix.getRotationAxis();

    Matrix m =
        MatrixBuilder.euclidean()
            .translate(0, verticalOffset, 0)
            .rotate(angle, axis)
            .translate(-center[0], -bounds.getMinY(), -center[2])
            .getMatrix();
    m.assignTo(transformationComponent);
    bounds = bounds.transformByMatrix(bounds, m.getArray());
  }
Ejemplo n.º 4
0
  public ToolEvent process(VirtualDeviceContext context) throws MissingSlotException {
    if (context.getEvent().getInputSlot() == cameraToWorld) return null;
    DoubleArray pointer = context.getTransformationMatrix(pointerNDC);
    if (pointer == null) throw new MissingSlotException(pointerNDC);
    if (oldX == Integer.MAX_VALUE) {
      oldX = pointer.getValueAt(3);
      oldY = pointer.getValueAt(7);
      return null;
    }
    double x = pointer.getValueAt(3);
    double y = pointer.getValueAt(7);
    double dist = x * x + y * y;
    double z = 2 > dist ? Math.sqrt(2 - dist) : 0;
    Rn.setToValue(mouseCoords, x, y, z);

    mouseCoords = Rn.normalize(mouseCoords, mouseCoords);
    double[] cross = Rn.crossProduct(null, mouseCoordsOld, mouseCoords);
    double angle = gain * Math.asin(Rn.euclideanNorm(cross));
    double[] cross4 = {cross[0], cross[1], cross[2], 0};
    cross = new Matrix(context.getTransformationMatrix(cameraToWorld)).multiplyVector(cross4);
    result.assignFrom(P3.makeRotationMatrix(null, cross, angle));
    Rn.setToValue(mouseCoordsOld, x, y, z);
    return new ToolEvent(this, context.getEvent().getTimeStamp(), out, da);
  }