<< back to Examples page

Example 4: Using setPivot()

setPivot(): In this example, we use setPivot() to change the rotation/scale Pivot Point. In previous examples, we did so by modifying the Positioning Axis of the BSpace using setAxis().

By default, the rotation/scale Pivot Point is set on the Positioning Axis. setPivot() enables us to separate the two.

 

// Using SetPivot()

BSpace s1;
BImage img1;
float angle;
void setup(){

   size(200,200);
   background(200);
   smooth();


   img1 = loadImage("arch.jpg");
   s1 = new BSpace(this);
}
void loop(){
   angle += 0.04;
           
   // Set the pivot point for rotating/scaling the BSpace.
   // In result, the image will always rotate arround the mouse cursor.
   s1.setPivot(mouseX ,mouseY,0);

   s1.rotateZ(angle); 
   s1.image(img1,0,0);

   // cosmetic: draw the rotation pivot point -- the mouse cursor. 
   stroke(255,0,0);
   line(mouseX-5, mouseY , mouseX+5, mouseY);
    line(mouseX, mouseY - 5, mouseX, mouseY + 5);
    stroke(0); 
}