There are three functions for 3D rotation: rotateX(angle)
, rotateY(angle)
and rotateZ(angle)
for rotation in their respective axes where angle
is in radians.
size(200, 200, P3D); //Starting P3D renderer
fill(255, 0, 0, 150); //transparent red
translate(width/2, height/2);//translate to centre, ie (100, 100)
rectMode(CENTER);//This makes the rectangle centre in (100, 100)
rect(0, 0, 100, 100); //first rectangle
fill(0, 0, 255, 150); //transparent blue
rotateX(PI/4); //rotate in the x-axis by PI/4 radians (45 degrees)
rect(0, 0, 100, 100); //second rectangle (same dimensions as the first one)
rotateY(radians(45)); //rotate in the y-axis by passing the radians conversion of 45 degrees
rotateZ(3*PI/4); //rotate in the z-axis by 3*PI/4 radians (270 degrees)
Note: transformations (such as translations and rotations) add on to the previous transformation.