コード例 #1
0
 // Function to update location
 public void update() {
   // As long as we aren't dragging the pendulum, let it swing!
   if (!dragging) {
     float G = 0.4f; // Arbitrary universal gravitational constant
     theta_acc = (-1 * G / r) * sin(theta); // Calculate acceleration (see:
     // http://www.myphysicslab.com/pendulum1.html)
     theta_vel += theta_acc; // Increment velocity
     theta_vel *= damping; // Arbitrary damping
     theta += theta_vel; // Increment theta
   }
   loc.setXY(r * sin(theta), r * cos(theta)); // Polar to cartesian conversion
   loc.add(origin); // Make sure the location is relative to the pendulum's origin
 }
コード例 #2
0
    void wander() {
      float wanderR = 10.0f; // radius for our "wander circle"
      float wanderD = 20.0f; // distance for our "wander circle"
      wandertheta += random(-1, 1); // randomly changet wander theta

      // now we have to calculate the new location to steer towards on the wander circle
      Vector3D v = vel.copy();
      v.normalize(); // our heading
      float xoff =
          wanderD * v.x() + wanderR * cos(wandertheta); // x spot on circle based on heading
      float yoff =
          wanderD * v.y() + wanderR * sin(wandertheta); // y spot on circle based on heading
      Vector3D target = Vector3D.add(loc, new Vector3D(xoff, yoff)); // add the location
      acc.add(steer(target, false)); // steer towards it
    }
コード例 #3
0
 // function to update location
 void update() {
   vel.add(acc);
   loc.add(vel);
   timer -= 1.0f;
 }