Geomerative translation question.

edited November 2013 in Library Questions

Hi, It's the first time I use Geomerative library, and I'm trying this for rotating rectangles collision detection. It works as expected, but I have a little question on RShape.translate(). I see it translate only relative, so i cannot simply put a RShape.translate(100,50) into the draw() code, because the rect will run away in a moment...

Is there a way to have an absolute positioning of a RShape?

thanks.

Answers

  • Then, I also need to know the position of the translating & rotating rectengle center. i have tried rect1.getCenter().getX() but it doesn't work... any suggestions?

    Thanks again.

  • edited November 2013

    I've found a little turnaround for my first Q.

    import geomerative.*;
    
    int bck = 0;
    float i = 0;
    int x;
    int y;
    float X;
    float Y;
    float R;
    
    RShape pan1;
    RShape pan2;
    
    void setup() {
      size(640, 480);
      RG.init(this);
      stroke(0,0,255);
      fill(250);
      pan1 = RShape.createRectangle(100,100,200,100);
      pan2 = RShape.createRectangle(300,150,100,20);
      delay(5);  
    }
    
    void draw() {
      background(bck);
      pan1.translate(0,-Y);
      pan1.rotate(radians(-R),pan1.getCenter());
      Y = 50;
      R = 45;
      pan1.translate(0,Y);
      pan1.rotate(radians(R),pan1.getCenter());
      pan1.draw();
      pan2.draw();
    
      if(pan1.intersects(pan2)) {
        println("Hit!");
      } else {
        println("Free.");
      }
    }
    

    I don't like it so much, but if there isn't any other solution it will be useable..

    any other suggestion will be much appreciated!

    Thanks.

    EDIT: In fact it doesn't work well, meaning that after a lot of movements the real position is lost.

    Is there a way to translate to an Absolute position? or anybody knows about another library that can do what I need?

    any help will be much appreciated.

Sign In or Register to comment.