• fullscreen
  • Alcys_vis_et_ecrou1.pde
  • Ecrou.pde
  • Manivelle.pde
  • Tige.pde
  • import remixlab.proscene.*;
    
    
    Scene scene;
    Manivelle manivelle;
    Tige tige;
    Ecrou ecrou;
    InteractiveFrame vis, manette;
    WorldConstraint cPlane, cMain;
    float angleVis, angle, delta;
    PVector prevdif;
    void setup() {
    
         size(800, 800, P3D);
         scene=new Scene(this);
         scene.setAxisIsDrawn(false);
         scene.setGridIsDrawn(false);
         scene.camera().setPosition(new PVector(0, 0, 600));
         vis=new InteractiveFrame(scene);
         manette=new InteractiveFrame(scene);
         // manette.setReferenceFrame(vis);
         vis.setTranslation(0, 0, 170);
         manette.setTranslation(100, 0, 170);
    
         cPlane=new WorldConstraint();
         cPlane.setTranslationConstraint(AxisPlaneConstraint.Type.FORBIDDEN, new PVector(0, 0, 1));
         cPlane.setRotationConstraint(AxisPlaneConstraint.Type.AXIS, new PVector(0, 0, 1));
    
         cMain=new WorldConstraint();
         cMain.setTranslationConstraint(AxisPlaneConstraint.Type.PLANE, new PVector(0, 0, 1));
         cMain.setRotationConstraint(AxisPlaneConstraint.Type.FORBIDDEN, new PVector(0, 0, 0));
    
         manette.setConstraint(cMain);
         vis.setConstraint(cPlane);
         prevdif=new PVector(1, 0, 0);
         manivelle=new Manivelle();
         tige=new Tige();
         ecrou=new Ecrou();
    }
    
    void draw() {
         background(40);
         lights();
         directionalLight(255,100,55,-1,-1,-1);
         pushMatrix();
         fill(150);
    box(100,100,20);
         vis.applyTransformation();
      // scene.drawAxis(100);
         stroke(0, 0, 255);
        noFill();
         ellipse(0, 0, 200, 200);
          translate(0,0,-170);
            manivelle.draw();
            translate(0,0,-200);
            tige.draw();
         popMatrix();
    
         pushMatrix();
         manette.applyTransformation();
        // scene.drawAxis(100);
         if (manette.isInInteraction()&&(mouseButton == RIGHT)) {
              PVector dif=comb(1.0, manette.position(), -1.0, vis.position());
              dif.normalize();
              delta = angleEntre(prevdif, dif);
              prevdif=dif;
              angleVis+=delta;
         }
         println("angleVis   "+angleVis);
    
         noStroke();
         fill(255, 0, 0);
         sphere(5);
    
         popMatrix();
         vis.setRotation(new Quaternion(0, 0, sin(angleVis/2), cos(angleVis/2)));
         ecrou.draw();
         //contrainte circulaire pour la sphere rouge
         float ray=sqrt(sq(manette.position().x)+sq(manette.position().y));
         float nx=manette.position().x*100/ray;
         float ny=manette.position().y*100/ray;
         manette.setPosition(new PVector(nx,ny,manette.position().z));
     
    }
    //
    //
    //
    
    PVector comb(float t1, PVector v1, float t2, PVector v2) {
         PVector res=PVector.add(PVector.mult(v1, t1), PVector.mult(v2, t2));
         return res;
    }
    
    float angleEntre(PVector u, PVector v) {
         u.normalize();
         v.normalize();
         float sinus=u.x*v.y-u.y*v.x;
         return asin(sinus);
    }     //
    //
    
    
    class Ecrou{
         
    float positionZ,pas;
    Ecrou(){
    positionZ=-180;
    pas=15;
    }
    void draw(){
      pushStyle();   
      pushMatrix();
         translate( 0,0,positionZ-pas*angleVis/TWO_PI);
         fill(155);
         box(100,100,20);
      popMatrix(); 
    popStyle(); 
    
    }
    
    }
    
    class Manivelle{
     float hauteur,rayon;
    Manivelle(){
         hauteur=50;
         rayon =50;
    
    
    
    
    }
    
    void draw(){
    pushMatrix();
    fill(200);
    noStroke();
     scene.cone(20,0,0,40,20,80);
     translate(0,0,100);
    
     sphere(30);
      rotateY(HALF_PI);
      translate(0,0,-90);
      scene.cone(20,0,0,10,10,180);
       translate(0,0,-10);
      sphere(25); 
        translate(0,0,200);
       sphere(25);
    rotateY(-HALF_PI);
          translate(0,0,20);
    scene.cone(20,0,0,10,15,50);
    popMatrix();
    }
    }//fin de classe
    
    class Tige{
    float rayon, hauteur,pas;
    Tige(){
    rayon=16;
    hauteur=200;
    pas=15;
    }
    void draw(){
          pushMatrix();
          pushStyle();
         fill(155);
          scene.cone(20,0,0,rayon-3,rayon-3,hauteur);
         
          noFill();stroke(170,50,50);
          for(int i=0;i<200;i++){
               rotateZ(PI/10);
               strokeWeight(9);
               line(rayon,0,pas*i/20,rayon*cos(PI/10),rayon*sin(PI/10),pas*(i+1)/20);
          
        
          }
          popStyle();
          popMatrix(); 
       
     }
          }//fin de classe
    

    code

    tweaks (0)

    about this sketch

    This sketch is running as Java applet, exported from Processing.

    license

    advertisement

    jacques maire

    Crank and Nut

    Add to Faves Me Likey@!
    You must login/register to add this sketch to your favorites.

    Right-click and drag on the red sphere.
    Made with Proscene
    Merci à Jean-Pierre Charalambos pour ce pluggin extraordinaire qu'est Proscene.

    You need to login/register to comment.