private void drawShooter() {
   stroke(255);
   double x2 =
       width / 2
           - 75
               * (Math.cos(radians((float) angledegrees))); // calculates point to draw line from
   double y2 =
       75
           * (Math.sin(
               radians(
                   (float)
                       angledegrees))); // calculates y co-ord to draw line from using trig
                                        // fucntions
   line(
       width / 2,
       height - (15 * height / 480),
       (float) x2,
       height - (15 * height / 480) - (float) y2); // draws line
   if (angledegrees == 170
       || angledegrees == 10) { // stop ball being shot horizontally. HAHA WE DIDN'T FORGET!!!
     increase = increase * -1; // sets shooter to rotate in opposite direction
   }
   if (canfire) { // checks if can fire
     angledegrees +=
         increase; // increases only when true. This stops the animation whil ball is moving
   }
 }
示例#2
0
  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);
    }
  }