コード例 #1
0
 // The Constructor (called when the object is first created)
 Particle(Vector3D a, Vector3D v, Vector3D l, float r_) {
   acc = a.copy();
   vel = v.copy();
   loc = l.copy();
   r = r_;
   timer = 100.0f;
 }
コード例 #2
0
 // look, we can have more than one constructor!
 Particle(Vector3D l) {
   acc = new Vector3D(0, 0.05f, 0);
   // ooooh, bad random, random bad
   vel = new Vector3D(random(-1, 1), random(-2, 0), 0);
   loc = l.copy();
   r = 10.0f;
   timer = 100.0f;
 }
コード例 #3
0
    // This constructor could be improved to allow a greater variety of pendulums
    Pendul(Vector3D origin_, float r_) {
      // Fill all variables
      origin = origin_.copy();
      r = r_;
      theta = 0.0f;

      // calculate the location of the ball using polar to cartesian conversion
      float x = r * sin(theta);
      float y = r * cos(theta);
      loc = new Vector3D(origin.x + x, origin.y + y);
      theta_vel = 0.0f;
      theta_acc = 0.0f;
      damping = 0.995f; // Arbitrary damping
      ballr = 16.0f; // Arbitrary ball radius
    }