예제 #1
0
파일: LJ3MDApp.java 프로젝트: eskilj/mvp
 /**
  * Set the view matrix `s' is the scaling factor of translating real coordinates to the screen
  * coordinates (x0, y0) the screen coordinates of the center
  */
 void setMatrix(Matrix3D viewMat, double s, double x0, double y0) {
   mat.unit();
   mat.mult(viewMat);
   mat.scale(s, s, s);
   real2Screen = s;
   mat.translate(x0, y0, 0);
   transformed = false;
 }
예제 #2
0
파일: LJ3MDApp.java 프로젝트: eskilj/mvp
 public void mouseDragged(MouseEvent e) {
   int x = e.getX();
   int y = e.getY();
   tmpMatrix.unit();
   tmpMatrix.xrot(360.0 * (mouseY - y) / getSize().height);
   tmpMatrix.yrot(360.0 * (x - mouseX) / getSize().width);
   viewMatrix.mult(tmpMatrix);
   repaint();
   mouseX = x;
   mouseY = y;
   e.consume();
 }
예제 #3
0
파일: LJ3MDApp.java 프로젝트: eskilj/mvp
  /** Compute the Z-order */
  void getZOrder() {
    // transform the coordinates
    if (!transformed) {
      mat.transform(realXYZ, screenXYZ, np);
      transformed = true;
    }

    // bubble sort z-order
    // zOrder[0] is the fartherest from the viewer
    // zOrder[np - 1] is the nearest to the viewer
    for (int i = 0; i < np; i++) zOrder[i] = i;
    for (int i = 0; i < np; i++) {
      // find the particle with the smallest z
      int jm = i, k;
      for (int j = i + 1; j < np; j++)
        if (screenXYZ[zOrder[j]][2] < screenXYZ[zOrder[jm]][2]) jm = j;
      if (jm != i) {
        k = zOrder[i];
        zOrder[i] = zOrder[jm];
        zOrder[jm] = k;
      }
    }
  }