We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOther Libraries › traer physics attractor problem
Page Index Toggle Pages: 1
traer physics attractor problem (Read 1287 times)
traer physics attractor problem
Nov 6th, 2006, 1:21am
 
i made one attractor which is using the mouse-coordinates.
it attracts the other particles, but then sends them bouncing around like mad.
whenever i use setMinimumDistance the attractor stops attracting.  i basically want the "puppet" to be attracted by the mouse and then hang there.

some spaghetti code for your amusement here:

//...............

import processing.core.PApplet;
import traer.physics.*;
import sms.*;

public class Puppet_traer extends PApplet {




 ParticleSystem physics;

 Particle p;

 Particle anchor;

 Particle head;

 Particle body;

 Particle arm_l;
 Particle arm_r;

 Particle foot_l;
 Particle foot_r;

 Spring[] s;
 Attraction[] a;

 Particle sideTractor;




 int[] vals = Unimotion.getSMSArray();

 int STRINGSIZE = 15;
 int BALLSIZE = 4;

 //make balls with more drag which are attached to the main ball


 public void setup() {
   size(1200, 800);
   smooth();
   fill(0);
   frameRate(24);
   ellipseMode(CENTER);




   physics = new ParticleSystem(5.0f, 0.1f);

   // sideTractor = physics.makeParticle(6.0f, vals[0],vals[1], 0);
   sideTractor = physics.makeParticle();
   sideTractor.makeFixed();


   head = physics.makeParticle(3.0f, width / 2, height/2, 0);
   //head.makeFixed();

   anchor = physics.makeParticle(1.0f, width / 2, 0, 0);
   anchor.makeFixed();

   arm_l = physics.makeParticle(1.0f, width / 2, height/2, 0);
   arm_r = physics.makeParticle(1.2f, width / 2, height/2, 0);

   foot_l = physics.makeParticle(2.0f, width / 2, height/2, 0);
   foot_r = physics.makeParticle(2.2f, width / 2, height/2, 0);

   body = physics.makeParticle(5.0f, width / 2, 0, 0);


   s = new Spring[6];
   s[0] = physics.makeSpring(anchor, head, 1.0f, 0.1f, 10*STRINGSIZE);
   s[1] = physics.makeSpring(body, head, 1.0f, 0.1f, 1*STRINGSIZE);
   s[2] = physics.makeSpring(body, arm_l, 1.0f, 0.1f, 2*STRINGSIZE);
   s[3] = physics.makeSpring(body, arm_r, 1.0f, 0.1f, 2*STRINGSIZE);
   s[4] = physics.makeSpring(body, foot_l, 1.0f, 0.1f, 4*STRINGSIZE);
   s[5] = physics.makeSpring(body, foot_r, 1.0f, 0.1f, 4*STRINGSIZE);

//end of first part

Re: traer physics attractor problem
Reply #1 - Nov 6th, 2006, 1:22am
 
//second part of the code



   //s.setDamping(4f);
   //s.setStrength(50f);
   // s.setRestLength(1f);
   a = new Attraction[8];
   a[0] = physics.makeAttraction( foot_l, foot_r, -200, 5 );
   a[1] = physics.makeAttraction( arm_l, arm_r, -120000, 5 );

   a[2] = physics.makeAttraction( sideTractor, head, 500000, 5 );
   a[3] = physics.makeAttraction( sideTractor, body, 500000, 5 );
   a[4] = physics.makeAttraction( sideTractor, arm_r, 500000, 5 );
   a[5] = physics.makeAttraction( sideTractor, arm_l, 500000, 5 );
   a[6] = physics.makeAttraction( sideTractor, foot_r, 500000, 5 );
   a[7] = physics.makeAttraction( sideTractor, foot_l, 500000, 5 );


   a[2].setMinimumDistance(280000);
   a[3].setMinimumDistance(280000);
   a[4].setMinimumDistance(280000);
   a[5].setMinimumDistance(280000);
   a[6].setMinimumDistance(280000);
   a[7].setMinimumDistance(280000);


 }


 //make boundary collision handler!!!

 public void draw() {

   int[] vals = Unimotion.getSMSArray();



   sideTractor.moveTo( mouseX, mouseY, 0 );

   if (!mousePressed)
     physics.advanceTime(0.5f);

   else {
     body.moveTo((vals[0]*-1)*-width/2, (vals[1]+1)*height/2, 0);
     arm_l.moveTo((vals[0]*-1)*-width/2, (vals[1]+1)*height/2, 0);
     arm_r.moveTo((vals[0]*-1)*-width/2, (vals[1]+1)*height/2, 0);
     //p.setVelocity((mouseX - pmouseX), (mouseY - pmouseY), 0);
   }



   background(255);
   stroke(0);
   // line(anchor.position().x(), anchor.position().y(), head.position().x(), head.position().y());
   line(body.position().x(), body.position().y(), head.position().x(), head.position().y());

   line(body.position().x(), body.position().y(), arm_l.position().x(), arm_l.position().y());
   line(body.position().x(), body.position().y(), arm_r.position().x(), arm_r.position().y());
   line(body.position().x(), body.position().y(), foot_l.position().x(), foot_l.position().y());
   line(body.position().x(), body.position().y(), foot_r.position().x(), foot_r.position().y());


   //strings
   stroke(180);
   line(arm_r.position().x(), arm_r.position().y(), 0, 0);
   line(arm_l.position().x(), arm_l.position().y(), width, 0);
   line(foot_r.position().x(), foot_r.position().y(), 0, 0);
   line(foot_l.position().x(), foot_l.position().y(), width, 0);

   noStroke();
   ellipse(head.position().x(), head.position().y(), 12*BALLSIZE, 3*BALLSIZE);
   ellipse(head.position().x(), head.position().y(), 9*BALLSIZE, 9*BALLSIZE);
   ellipse(body.position().x(), body.position().y(), 12*BALLSIZE, 12*BALLSIZE);
   ellipse(arm_l.position().x(), arm_l.position().y(), 6*BALLSIZE, 3*BALLSIZE);
   ellipse(arm_r.position().x(), arm_r.position().y(), 6*BALLSIZE, 3*BALLSIZE);
   ellipse(foot_l.position().x(), foot_l.position().y(), 8*BALLSIZE, 3*BALLSIZE);
   ellipse(foot_r.position().x(), foot_r.position().y(), 8*BALLSIZE, 3*BALLSIZE);

   ellipse(vals[0]*25,vals[1]*25,100,100);

   ellipse(sideTractor.position().x(),sideTractor.position().y(), 25,25);


   println(vals[0] + " " + vals[1] + " " + vals[2]);
 }

 public static void main(String[] args) {
   PApplet.main(new String[] {
     "Puppet_traer"                                                                                                                     }
   );
 }
}

Page Index Toggle Pages: 1