3D 旋转
3D 旋转有三个功能:rotateX(angle)
,rotateY(angle)
和 rotateZ(angle)
在各自的轴上旋转,其中 angle
是弧度。
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)
注意:转换(例如翻译和旋转)会添加到上一个转换。