コード例 #1
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;
        }
      }
    }
コード例 #2
0
    public void update(float newY) {
      y = newY;
      vel.x = x - px;
      vel.y = y - py;

      px = x;
      py = y;
    }
コード例 #3
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;
    }
コード例 #4
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();
    }
コード例 #5
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;
        }
      }
    }
  }
コード例 #6
0
  public void setup() {

    mFont = createFont("ArialRoundedMTBold-36", 48);
    size(1440, 900, OPENGL);
    background(0);
    frameRate(120);
    //  model   = new OBJModel(this, "alyson_laugh.obj", "absolute", TRIANGLES);
    model = new OBJModel(this, "alyson_scared.obj", "absolute", TRIANGLES);
    //  model   = new OBJModel(this, "alyson_crying.obj", "absolute", TRIANGLES);

    smooth();
    colorMode(HSB);
    strokeWeight(4);

    model.scale(800);
    model.translateToCenter();

    detailValue = 3;
    scaleValue = 10;
    vertices = new ArrayList();
    ps = new ParticleSystem(this, scaleValue);

    PVector averagePosition = new PVector(0, 0, 0);

    for (int i = 0; i < model.getVertexCount(); i += detailValue) {
      PVector destinationPoint = model.getVertex(i);

      vertices.add(destinationPoint);

      averagePosition.add(destinationPoint);
    }

    averagePosition.div(vertices.size());

    for (int i = 0; i < vertices.size(); i++) {
      PVector destination = (PVector) vertices.get(i);
      Particle p = new Particle(this, averagePosition, destination);
      ps.addParticle(p);
    }
  }
コード例 #7
0
ファイル: PlanetScape.java プロジェクト: kmshiva/PlanetScape
    public void calculateForces(ArrayList objects) {
      for (int i = 0; i < objects.size(); i++) {
        CelestialObject obj = (CelestialObject) objects.get(i);
        ArrayList forces = obj.getForces();
        float totalForceX = 0;
        float totalForceY = 0;

        for (int j = 0; j < forces.size(); j++) {
          totalForceX += ((PVector) forces.get(j)).x;
          totalForceY += ((PVector) forces.get(j)).y;
        }

        PVector newAccel = new PVector(totalForceX / obj.getMass(), totalForceY / obj.getMass());

        obj.setAcceleration(newAccel);
      }

      for (int i = 0; i < objects.size(); i++) {
        CelestialObject obj1 = (CelestialObject) objects.get(i);
        float forceX = 0;
        float forceY = 0;
        obj1.clearForces();

        if (obj1.getClass() == Star.class) {
          println(obj1.getVelocity());
          continue;
        }

        for (int j = 0; j < objects.size(); j++) {
          CelestialObject obj2 = (CelestialObject) objects.get(j);

          if (i == j) continue;

          PVector pvDistance = PVector.sub(obj2.getPosition(), obj1.getPosition());
          //    println("distance: x:" + pvDistance.x + " y:" + pvDistance.y);
          float distance = sqrt(sq(pvDistance.y) + sq(pvDistance.x));
          float angle = degrees(atan2(pvDistance.y, pvDistance.x));

          float force = (G * obj1.getMass() * obj2.getMass()) / sq(distance);
          forceX = force * cos(radians(angle));
          forceY = force * sin(radians(angle));
          //        println("FORCES on " + obj1.getName() + ":" + forceX + "," + forceY);
          obj1.addForce(new PVector(forceX, forceY));

          println();
        }
      }
    }
コード例 #8
0
ファイル: PlanetScape.java プロジェクト: kmshiva/PlanetScape
 public void setAcceleration(PVector acceleration) {
   this.acceleration = acceleration;
   velocity.add(acceleration);
   position.add(velocity);
 }
コード例 #9
0
ファイル: GUI.java プロジェクト: BNHeadrick/AFM-GUI
    public void checkThirtyDegreeRule(
        ArrayList<Cam> cameras, ArrayList<Character> characters, int selectedIdx) {
      if (cameras == null || cameras.isEmpty()) {
        println("No cameras in the scene!");
      }

      if (characters.size() != 2) {
        println("Only two characters supported for now");
        // TODO (sanjeet): Hack! Fix this once more characters are allowed
      }

      Cam selectedCamera = cameras.get(selectedIdx);

      // TODO The characters.get results in a runtime error because there aren't currently any
      // characters allocated in the input file.
      Character ch1 = characters.get(0);
      Character ch2 = characters.get(1);

      // Obtaining (x,y,z) for characters and selected camera
      PVector ch1Location = ch1.getTranslation();
      PVector ch2Location = ch2.getTranslation();
      PVector selectedCameraLocation = selectedCamera.getTranslation();

      PVector cameraPoint = new PVector();
      cameraPoint.add(selectedCameraLocation);
      for (int i = 0; i < 100; i++) {
        cameraPoint.add(selectedCamera.getZAxis());
      }
      PVector intersection =
          getTwoLinesIntersection(
              new PVector(ch1Location.x, ch1Location.z),
              new PVector(ch2Location.x, ch2Location.z),
              new PVector(selectedCameraLocation.x, selectedCameraLocation.z),
              new PVector(cameraPoint.x, cameraPoint.z));

      PVector diff = PVector.sub(selectedCameraLocation, intersection);
      diff.normalize();
      FloatBuffer fb = selectedCamera.modelViewMatrix;
      float[] mat = fb.array();
      float[] fbMatrix = new float[mat.length];
      for (int i = 0; i < fbMatrix.length; i++) {
        fbMatrix[i] = mat[i];
      }
      fbMatrix[0] = -diff.x;
      fbMatrix[1] = diff.y;
      fbMatrix[2] = -diff.z;
      fbMatrix[9] = diff.x;
      fbMatrix[10] = diff.y;
      fbMatrix[11] = diff.z;
      fbMatrix[13] = intersection.x;
      fbMatrix[14] = intersection.y;
      fbMatrix[15] = intersection.z;
      PMatrix3D matrix = new PMatrix3D();
      matrix.set(fbMatrix);
      matrix.transpose();
      pushMatrix();
      applyMatrix(matrix);
      rotateY(radians(30));
      line(0, 0, 0, 0, 0, 1000);
      rotateY(radians(-2 * 30));
      line(0, 0, 0, 0, 0, 1000);
      popMatrix();

      for (int i = 0; i < cameras.size(); i++) {
        if (i == selectedIdx) {
          continue;
        }

        if (!cameras.get(i).isInView(ch1Location) && !cameras.get(i).isInView(ch2Location)) {
          continue;
        }
        PVector currCamLocation = cameras.get(i).getTranslation();
        PVector vect1 = PVector.sub(currCamLocation, intersection);
        PVector vect2 = PVector.sub(selectedCameraLocation, intersection);
        float dotP = vect1.dot(vect2) / (vect1.mag() * vect2.mag());
        if (acos(dotP) <= PI / 6) {
          cameras.get(i).setColor(255, 0, 0);
        } else {
          cameras.get(i).setColor(0, 0, 255);
        }
      }
    }
コード例 #10
0
ファイル: GUI.java プロジェクト: BNHeadrick/AFM-GUI
 /**
  * Given two points p1, p2 and a line passing through a,b check whether p1 and p2 are on the
  * same side of the line. In our case a,b are characters and p1, p2 are cameras
  */
 public boolean isInSameHalfPlane(PVector p1, PVector p2, PVector a, PVector b) {
   PVector copyP1 = new PVector(p1.x, p1.y, p1.z);
   PVector copyP2 = new PVector(p2.x, p2.y, p2.z);
   PVector copyA = new PVector(a.x, a.y, a.z);
   PVector copyB = new PVector(b.x, b.y, b.z);
   copyB.sub(copyA);
   copyP1.sub(copyA);
   copyP2.sub(copyA);
   PVector p1a = copyB.cross(copyP1);
   PVector p2a = copyB.cross(copyP2);
   if (p1a.dot(p2a) > 0) {
     return true;
   }
   return false;
 }
コード例 #11
0
ファイル: GUI.java プロジェクト: BNHeadrick/AFM-GUI
 public boolean isInView(PVector vect) {
   PVector z = getZAxis();
   PVector v1 = PVector.sub(vect, getTranslation());
   float dotP = PVector.dot(v1, z) / (z.mag() * v1.mag());
   if ((acos(dotP) * 180 / PI) <= fov) {
     return true;
   }
   return false;
 }