protected void applyDelta(Vector3f deltaTranslation, Quaternion deltaRotation) {
    LOGGER.warning("Applying delta: " + deltaTranslation + " " + deltaRotation);

    boolean startedDrag = false;
    if (!dragging) {
      // no drag in progress. Start one now and end it after the drag
      // operation
      startDrag();
      startedDrag = true;
    }

    for (Cell cell : selected.getSelectedCells()) {
      CellTransform transform = cell.getLocalTransform();
      Vector3f translate = transform.getTranslation(null);
      Quaternion rotation = transform.getRotation(null);

      // if the cell has a parent, make sure to take the parent's
      // rotation and scale into account when applying the delta
      Vector3f localDeltaTranslation = deltaTranslation.clone();
      Cell parent = cell.getParent();
      if (parent != null) {
        CellTransform parentWorld = parent.getWorldTransform();
        Quaternion parentRotation = parentWorld.getRotation(null);
        float parentScale = parentWorld.getScaling();

        LOGGER.warning("Parent transform: " + parentWorld);

        // invert the rotation to get the child rotation
        parentRotation.inverseLocal();
        localDeltaTranslation = parentRotation.mult(deltaTranslation);
        localDeltaTranslation.multLocal(parentScale);

        LOGGER.warning("Local delta translation: " + localDeltaTranslation);
      }

      translate.addLocal(localDeltaTranslation);
      rotation.multLocal(deltaRotation);
      transform.setTranslation(translate);
      transform.setRotation(rotation);

      MovableComponent mc = getMovable(cell);
      if (mc != null) {
        mc.localMoveRequest(transform);
      }
    }
    lastTranslation.addLocal(deltaTranslation);
    lastRotation.multLocal(deltaRotation);
    // if we started a drag, remember to end it
    if (startedDrag) {
      endDrag();
    }
  }
  public void triggerGoto(final Vector3f position, final Quaternion look) {

    if (avatarCharacter != null) {
      SceneWorker.addWorker(
          new WorkCommit() {
            public void commit() {
              PTransform xform = new PTransform(look, position, new Vector3f(1, 1, 1));
              avatarCharacter.getModelInst().setTransform(xform);
            }
          });
    } else {
      CellTransform transform = new CellTransform();
      transform.setRotation(look);
      transform.setTranslation(position);

      cell.getComponent(MovableComponent.class).localMoveRequest(transform);
    }
  }
Beispiel #3
0
  private void syncWindowStateNext() throws EOFException {
    AppXrw.logger.info("Enter syncWindowStateNext");

    CreateWindowMsgArgs crtMsgArgs = new CreateWindowMsgArgs();
    WindowXrw win;
    int controllingUserLen;
    int desiredZOrder;
    float rotY; // Currently ignored
    Vector3f userTranslation = new Vector3f();

    crtMsgArgs.wid = bufQueue.nextInt();
    crtMsgArgs.x = (short) bufQueue.nextInt();
    crtMsgArgs.y = (short) bufQueue.nextInt();
    crtMsgArgs.wAndBorder = bufQueue.nextInt();
    crtMsgArgs.hAndBorder = bufQueue.nextInt();
    crtMsgArgs.borderWidth = bufQueue.nextInt();
    controllingUserLen = bufQueue.nextInt();
    desiredZOrder = bufQueue.nextInt();
    rotY = bufQueue.nextFloat(); // Just skipped
    userTranslation.x = bufQueue.nextFloat();
    userTranslation.y = bufQueue.nextFloat();
    userTranslation.z = bufQueue.nextFloat();
    AppXrw.logger.info("userTranslation = " + userTranslation);
    /* TODO: 0.4 protocol:
    int transientFor = bufQueue.nextInt();
    AppXrw.logger.info("transientFor = " + transientFor);
     */
    // TODO: 0.4 protocol: skip isTransient
    int transientFor = bufQueue.nextInt();
    int typeOrdinal = bufQueue.nextInt();
    Window2D.Type type = Window2D.Type.values()[typeOrdinal];
    AppXrw.logger.info("type = " + type);
    int parentWid = bufQueue.nextInt();
    AppXrw.logger.info("parentWid = " + parentWid);

    crtMsgArgs.decorated = (bufQueue.nextByte() == 1) ? true : false;
    AppXrw.logger.info("client = " + client);
    AppXrw.logger.info("crtMsgArgs = " + crtMsgArgs);
    AppXrw.logger.info("desiredZOrder= " + desiredZOrder);

    // Make sure window is ready to receive data on creation
    win = client.createWindow(crtMsgArgs);
    if (win == null) {
      AppXrw.logger.warning("Cannot create slave window for " + crtMsgArgs.wid);
      return;
    }

    if (win.getType() != type) {
      win.setType(type);
    }

    // Defer parent assignment until all windows are created
    if (parentWid != WindowXrw.INVALID_WID) {
      windowParents.put(win, parentWid);
    }

    win.setDesiredZOrder(desiredZOrder);

    CellTransform userTransformCell = new CellTransform(null, null);
    userTransformCell.setTranslation(userTranslation);
    win.setUserTransformCellLocal(userTransformCell);

    boolean show = (bufQueue.nextByte() == 1) ? true : false;
    AppXrw.logger.info("show = " + show);

    if (controllingUserLen > 0) {
      byte[] controllingUserBuf = bufQueue.nextBuffer();
      String controllingUser = new String(controllingUserBuf);
      AppXrw.logger.info("controlling user = " + controllingUser);
      win.setControllingUser(controllingUser);
    }

    int srcWidth = crtMsgArgs.wAndBorder;
    int srcHeight = crtMsgArgs.hAndBorder;
    int[] pixels = new int[srcWidth * srcHeight];

    for (int y = 0; y < srcHeight; y++) {
      int srcLineOffset = y * srcWidth;
      for (int x = 0; x < srcWidth; x++) {
        pixels[srcLineOffset + x] = bufQueue.nextInt();
      }
    }
    win.displayPixels(0, 0, srcWidth, srcHeight, pixels);

    /* TODO: 0.4 protocol:
    WindowXrw winTransientFor = client.lookupWindow(transientFor);
    win.setVisibleApp(show, winTransientFor);
     */
    win.setVisibleApp(show);
  }