|
|
Examples:
- Getting started (example on this page)
- Using
the NestIn() feature
- Creating
an Array of BSpace objects
- Using
setPivot()
- Translating coordinates:
Using BSpace.objectX() / Y /Z
| |
Getting Started: This example demonstrates the
most basic use of the BSpace object; how two objects can be manipulated
separately from each other. Compare this code to the old-school
push/pop methods below.
Benefits of the BSpace object will become apparent through the
remaining examples.
|
// EXAMPLE 1: GETTING STARTED...
BSpace s1,s2; float angle;
void setup(){
s1 = new BSpace(this); //First, create a new BSpace object
s2 = new BSpace(this);
s1.setAxis(25,50); //Set the Positioning Axis of this BSpace.
// This 'moves' the entire space by 25,50 pixles.
s2.setAxis(75,50);
}
void loop(){
angle += 0.05;
//DRAW SHAPE 1
s1.rotateZ(angle); // rotate the BSpace around the Axis point (now set to 25,50).
// learn how to use setPivot() for more control over transformations.
s1.rotateX(angle);
s1.rectMode(CENTER_DIAMETER);
s1.rect(0,0,20,20); //Draw a rectangle in the transformed s1.
//DRAW SHAPE 2
s2.rotateY(angle/2);
s2.box(20); // draw a box in the transformed s2.
}
Here's how the same program would be written without BSPace. Notice, that both methods require the same
amount of lines. Yet for more complex programs, the BSpace method may prove efficient and intuitive.
float angle;
void setup(){
int angle = 0;
}
void loop(){
angle += 0.05;
push();
translate(25,50);
rotateZ(angle);
rotateX(angle);
rectMode(CENTER_DIAMETER);
rect(0,0,20,20);
pop();
translate(75,50);
rotateY(angle/2);
box(20);
}
|