shapes 3D questions about rotation and face center, manipulating 3d shapes local variables

edited April 2014 in Library Questions

hello Everyone,

we are trying to use the rotate function in shapes 3D library by quarks.

The problem when we use time in rotate function it continuously rotate till it gets to the final position. we would like it to go to that position in One rotation.

the second problem is we are trying to use box method and we want to get the box local variables like box up vector and face center in short Box properties.

I hope you guys can gives a quick tutorial or something we can use. ultimately we are using shapes 3d library because we would like to use it with rigid bodies library.

thanks!

have a great day!

Answers

  • Answer ✓

    The problem when we use time in rotate function it continuously rotate till it gets to the final position. we would like it to go to that position in One rotation.

    There are 5 rotateBy methods, 6 rotateTo methods as well as rotateX, rotateY and rotateZ. Some of these methods give you the option to automatically rotate the shape based on a delay and rotation time provided by the user. Some methods rotate the shape immediately by/to values provided the user. Look at the reference (comes with the library) for the Shape3D class.

    the second problem is we are trying to use box method and we want to get the box local variables like box up vector and face center in short Box properties.

    In the shapes local coordinate system, the 'up' vector is always [0,1,0]. Movement and rotation a shape is done by moving and rotating the local coordinate system. It is not done by recalculating the vertices position in the 'world' coordinate system. You would have to get the angle between the local [0,1,0] and the world [0,1,0] to get close to what you want.

  • edited March 2014

    Thank you for responding very quickly.

    we are now trying to use time , rotation and move. But we cannot seem to have the right approach . When we use update function ( in our class) in keyPressed() it works , but it doesn't work in main sketch draw function.

    Eventually we will you collision detection with bRigid , is that possible to use your box class with bRigid or any other physics library.

    Here is our code so far:

    ////////////////////
    import peasy.org.apache.commons.math.*;
    import peasy.*;
    import peasy.org.apache.commons.math.geometry.*;
    import shapes3d.utils.*;
    import shapes3d.animation.*;
    import shapes3d.*;
    
    PeasyCam cam; 
    
    //  Clicking  
    boolean clicked = false;
    Shape3D picked = null;
    
    // Change angle smoothing factors
    final float ANG_SMOOTH = 0.25f;
    final float DIST_SMOOTH = 0.8f;
    float d = 50;
    
    // box 
    Voxel[] voxels = new Voxel[2];
    
    void setup() {
      size(600, 800, P3D);
    
      // cursor type 
      cursor(HAND);
    
      // Create camera
      cam = new PeasyCam(this, 400);
      cam.setMinimumDistance(200);
      cam.setMaximumDistance(1000);
      cam.setResetOnDoubleClick(false); 
    
      //
      for (int i=0;i < voxels.length ; i++) {
        voxels[i]= new Voxel(this, new PVector (random(50), random(50), random(50)), new PVector (random(50), 0, 0));
      }
    }
    
    void draw() {
      background(0);
      smooth();
    
      // click in draw 
      if (clicked) {
        clicked = false;
        picked = Shape3D.pickShape(this, mouseX, mouseY);
        if (picked != null)
          picked.fill(randomColor());
      }
    
      for (int i=0;i < voxels.length; i++) {
        voxels[i].display();
        voxels[i].update();
      }
    }
    
    // clicking function 
    void mouseClicked() {
      clicked = true;
    }
    
    void keyPressed() {
    }
    
    int randomColor() {
      return color(random(100, 220), random(100, 220), random(100, 220));
    }
    
    /////////////// class 
    
    class Voxel {
      PApplet app;
      PVector rot;
      PVector pos;
      PVector newPos;
      Box mybox;
      //Rot globRot;
    
      Voxel( PApplet _app, PVector _pos, PVector _rot){
        app=_app;
        pos=_pos.get();
        rot=_rot.get();
        newPos=_pos.get();
        mybox = new Box ( app);
        mybox.setSize(25,25,25);
      }
    
       void display() {
    
         mybox.draw();
    
       }
       void update() {
         updatePos();
         updateRot();
       }
       void updatePos() {
    
          mybox.moveTo(newPos,10,0);
          pos=mybox.getPosVec();
       }
       void updateRot() {
         mybox.rotateTo(radians(rot.x),radians(rot.y),radians(rot.z),10,0);
       }
    }
    

    Thank you very much for your help and quick response.

  • To format code correctly in the forum, first select the code and click on the C button or press Ctrl+k . In this instance I have done it for you.

    we are now trying to use time , rotation and move. But we cannot seem to have the right approach .

    The PeasyCam library moves the view point around a fixed point in world space. It does not affect the relationship between the world space and the shapes local coordinate space. In other words PeasyCam does not rotate or move the shape.

    is that possible to use your box class with bRigid or any other physics library.

    I don't know the answer to that. Perhaps someone else might.

  • I am looking for some code similar to what you have, except that it uses the Shapes3D library and the Box command to enable to use of more parameters. If anybody knows of any samples that do just what this code does, a box with 6 different colored sides and uses PEasyCam camera and rotation, please let me know about the sample.

    THANKS to EVERYONE for your help

Sign In or Register to comment.