コード例 #1
0
ファイル: FastMath.java プロジェクト: TofuWatagashi/NextText
 /**
  * Converts a point from Cartesian coordinates (using positive Z as up) to Spherical and stores
  * the results in the store var. (Radius, Azimuth, Polar)
  */
 public static PVector cartesianZToSpherical(PVector cartCoords, PVector store) {
   if (cartCoords.x == 0) cartCoords.x = FastMath.FLT_EPSILON;
   store.x =
       FastMath.sqrt(
           (cartCoords.x * cartCoords.x)
               + (cartCoords.y * cartCoords.y)
               + (cartCoords.z * cartCoords.z));
   store.z = FastMath.atan(cartCoords.z / cartCoords.x);
   if (cartCoords.x < 0) store.z += FastMath.PI;
   store.y = FastMath.asin(cartCoords.y / store.x);
   return store;
 }
コード例 #2
0
 // A function to rotate a vector
 public void rotateVector(PVector v, float theta) {
   float m = v.mag();
   float a = v.heading2D();
   a += theta;
   v.x = m * PApplet.cos(a);
   v.y = m * PApplet.sin(a);
 }
コード例 #3
0
ファイル: plante2.java プロジェクト: radeise/Collection2
    // --------------------------------------------------------
    private void calculPositionAndAngle() {

      PVector prev = new PVector(0, 0);
      PVector next;

      for (int i = 0; i < n; i++) {

        next = new PVector();

        // Position
        if (i == 0) {
          next = new PVector(0, 0);
        } else {
          next.x = prev.x + cos(random(angleMini - HALF_PI, angleMax - HALF_PI)) * distance;
          next.y = prev.y + sin(random(angleMini - HALF_PI, angleMax - HALF_PI)) * distance;

          // Angle
          float a = atan2(prev.y - next.y, prev.x - next.x) - HALF_PI;
          angle.append(a);
          if (i == n - 1) lastAngle = a;
        }

        // Add position
        position.add(next);

        distance *= 1.01f;
        prev.set(next);
      }
    }
コード例 #4
0
    public void checkCollision(Paddle[] pads) {

      // check against walls
      if (y >= height || y < 0) {
        speed.y *= -1;
      }
      if (x >= width) {
        restart();
        paddles[1].addPoint();
        timer = 40;
      }
      if (x < 0) {
        restart();
        paddles[0].addPoint();
        timer = 40;
      }
      // check against paddles
      for (int i = 0; i < pads.length; i++) {
        if (x > pads[i].x - (pads[i].w / 2)
            && x < pads[i].x + (pads[i].w / 2)
            && y > pads[i].y - (pads[i].h / 2)
            && y < pads[i].y + (pads[i].h / 2)) {
          speed.x *= -1;

          float friction = 0.5f;
          println(pads[i].vel.y);
          speed.y += friction * pads[i].vel.y;
        }
      }
    }
コード例 #5
0
ファイル: FastMath.java プロジェクト: TofuWatagashi/NextText
  /**
   * Converts a point from Spherical coordinates to Cartesian (using positive Z as up) and stores
   * the results in the store var.
   */
  public static PVector sphericalToCartesianZ(PVector sphereCoords, PVector store) {
    store.z = sphereCoords.x * FastMath.sin(sphereCoords.z);
    float a = sphereCoords.x * FastMath.cos(sphereCoords.z);
    store.x = a * FastMath.cos(sphereCoords.y);
    store.y = a * FastMath.sin(sphereCoords.y);

    return store;
  }
コード例 #6
0
    public void update(float newY) {
      y = newY;
      vel.x = x - px;
      vel.y = y - py;

      px = x;
      py = y;
    }
コード例 #7
0
  @Override
  public void setTexCoords(PVector[] i_texCoords) {

    float xSize = bottomRightBound.x - topLeftBound.x;
    float ySize = bottomRightBound.y - topLeftBound.y;

    TL.x = i_texCoords[0].x * xSize;
    TL.y = i_texCoords[0].y * ySize;

    TR.x = i_texCoords[1].x * xSize;
    TR.y = i_texCoords[1].y * ySize;

    BR.x = i_texCoords[2].x * xSize;
    BR.y = i_texCoords[2].y * ySize;

    BL.x = i_texCoords[0].x * xSize;
    BL.y = i_texCoords[2].y * ySize;
  }
コード例 #8
0
 /** @exclude {@inheritDoc} */
 @ControlP5.Invisible
 public T updateEvents() {
   if (isOpen) {
     for (int i = controllers.size() - 1; i >= 0; i--) {
       ((ControllerInterface<?>) controllers.get(i)).updateEvents();
     }
   }
   if (isVisible) {
     if ((isMousePressed == _myControlWindow.mouselock)) {
       if (isMousePressed && cp5.keyHandler.isAltDown() && isMoveable) {
         if (!cp5.isMoveable) {
           positionBuffer.x += _myControlWindow.mouseX - _myControlWindow.pmouseX;
           positionBuffer.y += _myControlWindow.mouseY - _myControlWindow.pmouseY;
           if (cp5.keyHandler.isShiftDown) {
             position.x = ((int) (positionBuffer.x) / 10) * 10;
             position.y = ((int) (positionBuffer.y) / 10) * 10;
           } else {
             position.set(positionBuffer);
           }
           updateAbsolutePosition();
         }
       } else {
         if (isInside) {
           setMouseOver(true);
         }
         if (inside()) {
           if (!isInside) {
             isInside = true;
             onEnter();
             setMouseOver(true);
           }
         } else {
           if (isInside && !isMousePressed) {
             onLeave();
             isInside = false;
             setMouseOver(false);
           }
         }
       }
     }
   }
   return me;
 }
コード例 #9
0
ファイル: box.java プロジェクト: newshorts/pingpong
    public void wallCollisions() {

      // x
      if (x > (bounds.x / 2)) {
        velocity.x *= -1;
        //      velocity.x *= damping;
      }

      if (x < -(bounds.x / 2)) {
        velocity.x *= -1;
        //      velocity.x *= damping;
      }

      // y
      if (g) {
        velocity.y += gravity;
        if (y > bounds.y / 2) {
          velocity.y *= -0.95f;
          y = bounds.y / 2;
        }
      } else {
        if (y > (bounds.y / 2)) {
          velocity.y *= -1;
          velocity.y *= damping;
        }

        if (y < -(bounds.y / 2)) {
          velocity.y *= -1;
          velocity.y *= damping;
        }
      }

      // z
      if (z > (bounds.z / 2)) {
        velocity.z *= -1;
        //      velocity.z *= damping;
      }

      if (z < -(bounds.z / 2)) {
        velocity.z *= -1;
        //      velocity.z *= damping;
      }
    }
コード例 #10
0
  /** Triangulate the glyph, but first save the original outline. */
  public void triangulate() {
    // Save the outline and calculate normals
    outline = new Vector<PlanarEdge>();
    for (PlanarEdge e : subdivision.getEdges()) {
      if (e.isRealEdge()) {
        outline.add(e);
      }
    }
    // Calculate outline normals
    outline_normals = new PVector[outline.size()];
    for (PlanarEdge e : outline) {
      TriangulationVertex vert = (TriangulationVertex) e.getDestination();
      // Normal 1
      PVector normal1 = vert.getOutGoingEdge().getDestination().getPoint().get();
      normal1.sub(vert.getPoint());
      normal1.normalize();
      // Vector3 normal1 = new
      // Vector3(vert.getOutGoingEdge().getDestination().getPoint()).subtractLocal(vert.getPoint());
      normal1.z = -normal1.x;
      normal1.x = normal1.y;
      normal1.y = normal1.z;
      normal1.z = 0;
      // Normal 2
      PVector normal2 = vert.getPoint().get();
      normal2.sub(vert.getInGoingEdge().getOrigin().getPoint());
      normal2.normalize();
      // Vector3 normal2 = new
      // Vector3(vert.getPoint()).subtractLocal(vert.getInGoingEdge().getOrigin().getPoint());
      normal2.z = -normal2.x;
      normal2.x = normal2.y;
      normal2.y = normal2.z;
      normal2.z = 0;
      normal1.add(normal2);
      normal1.normalize();

      outline_normals[vert.getIndex()] = normal1;
    }

    // Calculate the triangulation of the surface.
    surface = subdivision.triangulate();
  }
コード例 #11
0
ファイル: Quaternion.java プロジェクト: Diex/residua
 /**
  * Returns the normalized axis direction of the rotation represented by the Quaternion.
  *
  * <p>The result is null for an identity Quaternion.
  *
  * @see #angle()
  */
 public final PVector axis() {
   PVector res = new PVector(this.x, this.y, this.z);
   float sinus = res.mag();
   if (sinus > 1E-8f) res.div(sinus);
   if (PApplet.acos(this.w) <= HALF_PI) return res;
   else {
     res.x = -res.x;
     res.y = -res.y;
     res.z = -res.z;
     return res;
   }
 }
コード例 #12
0
    public void update(float db) {
      // we can use the db value here to change the speed of the particles
      loc.add(vel.mult(vel, map(db, -100, 100, .05f, 5)));
      if (loc.x < 0 || loc.x > width) {
        vel.x *= -1;
      }
      if (loc.y < 0 || loc.y > height) {
        vel.y *= -1;
      }

      radius = constrain(db, 2, 100);
    }
コード例 #13
0
    public void display() {
      location.x = (sin(radians(angle)) * r) + 5;
      location.y = cos(radians(angle)) * r;

      pushMatrix();
      translate(location.x, location.y, 0);
      fill(220);
      noStroke();
      sphere(size);
      popMatrix();

      angle += speed;
    }
コード例 #14
0
    public PVector getSmoothedVelocity() {

      PVector total = new PVector(0, 0, 0);
      for (int i = 0; i < buffer.length; i++) {
        total.x += buffer[i].x;
        total.y += buffer[i].y;
        total.z += buffer[i].z;
      }

      PVector smthd =
          new PVector(total.x / buffer.length, total.y / buffer.length, total.z / buffer.length);
      return smthd;
    }
コード例 #15
0
ファイル: plante2.java プロジェクト: radeise/Collection2
    Background(float _sizeX, float _sizeY, Repulseur[] _r) {

      sizeX = _sizeX;
      sizeY = _sizeY;
      repulseurPoint = _r;

      for (int i = 0; i < 20000; i++) {

        PVector p = new PVector();
        p.x = random(sizeX);
        p.y = random(sizeY);

        points.add(p);
      }
    }
コード例 #16
0
ファイル: plante2.java プロジェクト: radeise/Collection2
    // -------------------------------------------
    public void calcul() {

      // UP - left side
      for (int i = 0; i < position.size(); i++) {

        PVector p = position.get(i);
        PVector pp = new PVector();

        pp.x = cos(angles.get(i) + HALF_PI) * radius[i] + p.x + initPosition.x;
        pp.y = sin(angles.get(i) + HALF_PI) * radius[i] + p.y + initPosition.y;
        pointForm.add(pp);
      }

      // DOWN - right side
      for (int i = position.size() - 1; i >= 0; i--) {

        PVector p = position.get(i);
        PVector pp = new PVector();

        pp.x = cos(angles.get(i) - HALF_PI) * radius[i] + p.x + initPosition.x;
        pp.y = sin(angles.get(i) - HALF_PI) * radius[i] + p.y + initPosition.y;
        pointForm.add(pp);
      }
    }
コード例 #17
0
ファイル: plante2.java プロジェクト: radeise/Collection2
    // ------------------------------------------------------
    public PVector updatedPointPosition(float _x, float _y) {

      p = new PVector(_x, _y);
      distance = dist(p.x, p.y, x, y);

      if (distance < radius) {

        angle = atan2(p.y - y, p.x - x);
        force = map(distance, 0, radius, maxForce, 0);

        p.x += cos(angle) * force;
        p.y += sin(angle) * force;
      }

      return p;
    }
コード例 #18
0
    public void updateAll(PVector newPos) {
      // update current joint position
      currentPos = newPos;
      // map velocity to depth image size - I can't find how to get the depth of this context
      velocity.x = map(newPos.x - prevPos.x, -context.depthWidth(), context.depthWidth(), -1, 1);
      velocity.y = map(newPos.y - prevPos.y, -context.depthHeight(), context.depthHeight(), -1, 1);
      velocity.z = newPos.z - prevPos.z;

      // overwrite the circular buffer
      buffer[bufferIndex] = velocity;
      // and incrememnt the buffer index
      bufferIndex++;
      if (bufferIndex >= buffer.length) {
        bufferIndex = 0;
      }
      prevPos = newPos;
      smoothedVelocity = getSmoothedVelocity();
    }
コード例 #19
0
ファイル: PlanetScape.java プロジェクト: kmshiva/PlanetScape
  public void mouseDragged() {
    if (paused) {
      ArrayList objects = timeline.getStatefulObjects();
      for (int i = 0; i < objects.size(); i++) {
        CelestialObject obj = (CelestialObject) objects.get(i);
        if (obj.isMouseOver()) {
          dragging = true;
          PVector pos = obj.getPosition();
          pos.x = mouseX;
          pos.y = mouseY;

          timeline.reset();
          timeline.setCurrentState(objects);
          sliderTimeline.setValue(0);
          break;
        }
      }
    }
  }
コード例 #20
0
  public void track() {

    // Get the raw depth as array of integers
    depth = kinect.getRawDepth();

    // Being overly cautious here
    if (depth == null) return;

    float sumX = 0;
    float sumY = 0;
    float count = 0;

    for (int x = 0; x < kw; x++) {
      for (int y = 0; y < kh; y++) {
        // Mirroring the image
        int offset = kw - x - 1 + y * kw;
        // Grabbing the raw depth
        int rawDepth = depth[offset];

        // Testing against threshold
        if (rawDepth < threshold) {
          sumX += x;
          sumY += y;
          count++;
        }
      }
    }
    // As long as we found something
    if (count != 0) {
      loc = new PVector(sumX / count, sumY / count);
    }

    // Interpolating the location, doing it arbitrarily for now
    lerpedLoc.x = PApplet.lerp(lerpedLoc.x, loc.x, 0.3f);
    lerpedLoc.y = PApplet.lerp(lerpedLoc.y, loc.y, 0.3f);
  }
コード例 #21
0
ファイル: ACADCam.java プロジェクト: orange-vertex/ACADCam
  private void calcCam(boolean is3D) {
    if (rotVector.mag() != 0 || panVector.mag() != 0 || camDist != prevCamDist) {
      prevCamDist = camDist;
      camRot += rotVector.x;
      if ((camPitch + rotVector.y) < 0.99 && (camPitch + rotVector.y) > 0.01)
        camPitch += rotVector.y;
      if (is3D) {
        PVector camPan =
            new PVector(
                (panVector.x * (float) Math.sin(Math.PI * 0.5 + (Math.PI * camRot)))
                    + (panVector.y * (float) Math.sin(Math.PI * 1.0 + (Math.PI * camRot))),
                (panVector.y * (float) Math.cos(Math.PI * 1.0 + (Math.PI * camRot)))
                    + (panVector.x * (float) Math.cos(Math.PI * 0.5 + (Math.PI * camRot))));
        camPan.mult(0.05f * PVector.dist(camPos, camCenter));
        camCenter.x += camPan.x;
        camCenter.y += camPan.y;
        camPan.x = 0;
        camPan.y = 0;
      } else {
        camCenter.x -= 0.05f * (camPos.z - camCenter.z) * panVector.x;
        camCenter.y += 0.05f * (camPos.z - camCenter.z) * panVector.y;
      }
      panVector.x = 0;
      panVector.y = 0;
      rotVector.x = 0;
      rotVector.y = 0;

      camPos.x =
          camCenter.x
              - camDist * (float) Math.sin(Math.PI * camRot) * (float) Math.sin(Math.PI * camPitch);
      camPos.y =
          camCenter.y
              - camDist * (float) Math.cos(Math.PI * camRot) * (float) Math.sin(Math.PI * camPitch);
      camPos.z = camCenter.z - camDist * (float) Math.cos(Math.PI * camPitch);
    }
  }
コード例 #22
0
 // Wraparound
 public void borders() {
   if (loc.x < -r) loc.x = width + r;
   if (loc.y < -r) loc.y = height + r;
   if (loc.x > width + r) loc.x = -r;
   if (loc.y > height + r) loc.y = -r;
 }
コード例 #23
0
 public void motion() {
   xMove += random(-6, 6);
   theta = radians(xMove);
   loc.x += cos(theta);
   lifespan -= 0.29f;
 }
コード例 #24
0
ファイル: ACADCam.java プロジェクト: orange-vertex/ACADCam
  public void mouseEvent(processing.event.MouseEvent e) {

    switch (e.getAction()) {
      case MouseEvent.PRESS:
        if (e.getButton() == mouseButton) {
          startX = e.getX();
          startY = e.getY();
          mousePressed = 1 + ctrlPressed;
        }
        if (extra > 0 && e.getButton() == extra) {
          startX = e.getX();
          startY = e.getY();
          mousePressed = 1 + ctrlPressed + extra;
        }
        break;
      case MouseEvent.RELEASE:
        if (e.getButton() == mouseButton) {
          panVector.x = 0;
          panVector.y = 0;
          rotVector.x = 0;
          rotVector.y = 0;
          mousePressed = 0;
        }
        break;
        //		case MouseEvent.CLICK:
        //			// do something for mouse clicked
        //			break;
      case MouseEvent.DRAG:
        if (mousePressed > 0) {
          if (mousePressed == 1 && extra == 0) {
            if (switchPanOrbit == 0) {
              panVector.x = panFactor * (startX - e.getX());
              panVector.y = -1 * panFactor * (startY - e.getY());
            } else {
              rotVector.x = rotFactor * (startX - e.getX());
              rotVector.y = pitchFactor * (startY - e.getY());
            }
          }
          if (mousePressed == 2) {
            if (switchPanOrbit == 0) {
              rotVector.x = rotFactor * (startX - e.getX());
              rotVector.y = pitchFactor * (startY - e.getY());
            } else {
              panVector.x = panFactor * (startX - e.getX());
              panVector.y = -1 * panFactor * (startY - e.getY());
            }
          }
          if (extra > 0 && mousePressed == 2 + extra) {
            if (switchPanOrbit == 0) {
              panVector.x = panFactor * (startX - e.getX());
              panVector.y = -1 * panFactor * (startY - e.getY());

            } else {
              rotVector.x = rotFactor * (startX - e.getX());
              rotVector.y = pitchFactor * (startY - e.getY());
            }
          }
          startX = e.getX();
          startY = e.getY();
        }
        break;
      case MouseEvent.MOVE:
        // umm... forgot
        break;
      case MouseEvent.WHEEL:
        System.out.println("the wheel works!");
        break;
    }
  }
コード例 #25
0
ファイル: plante2.java プロジェクト: radeise/Collection2
    // --------------------------------------------------------
    private void calculPositionAndAngle() {

      PVector prev = new PVector(0, 0);
      PVector next = new PVector(0, 0);
      float lastAngle = 0, randomAngle, tempAmplitude;

      // Position
      for (int i = 0; i < n; i++) {

        if (i == 0) {

          position.add(next);

        } else {

          tempAmplitude = amplitude;
          next = new PVector(0, 0);

          do {

            randomAngle = random(-tempAmplitude, tempAmplitude) + lastAngle;
            next.x = prev.x + cos(randomAngle + beginAngle) * distance;
            next.y = prev.y + sin(randomAngle + beginAngle) * distance;
            tempAmplitude += radians(1);
          } while (outside(next, border));

          // Angle
          float a = atan2(prev.y - next.y, prev.x - next.x);
          lastAngle = randomAngle;

          // Add position
          position.add(next);

          // Set prev to next
          prev.set(next);
        }
      }

      // Angle
      for (int i = 0; i < n; i++) {

        float a;

        if (i == 0) {

          // a = atan2(position.get(0).y-position.get(1).y,position.get(0).x-position.get(1).x);
          angle.append(beginAngle - PI);

        } else if (i == n - 1) {

          a =
              atan2(
                  position.get(n - 2).y - position.get(n - 1).y,
                  position.get(n - 2).x - position.get(n - 1).x);
          angle.append(a);

        } else {

          a =
              atan2(
                  position.get(i - 1).y - position.get(i + 1).y,
                  position.get(i - 1).x - position.get(i + 1).x);
          angle.append(a);
        }
      }
    }
コード例 #26
0
ファイル: Tooltip.java プロジェクト: poqudrof/Skatolo
 /**
  * adds an offset to the position of the controller relative to the mouse cursor's position.
  * default offset is (10,20)
  *
  * @param theX
  * @param theY
  * @return Tooltip
  */
 public Tooltip setPositionOffset(float theX, float theY) {
   offset.x = theX;
   offset.y = theY;
   return this;
 }