Buscar..


Sintaxis

  • traducir (flotar x, flotar y, flotar z)
  • rotateX (ángulo de flotación)
  • rotarY (ángulo de flotación)
  • rotateZ (ángulo de flotación)
  • caja (tamaño del flotador)
  • caja (flotador w, flotador h, flotador d)

Parámetros

Parámetros Detalles
ángulo el angulo esta en radianes
tamaño La dimensión de la caja que se utilizará para todas sus dimensiones.
w La dimensión de la caja en el x-axis
h La dimensión de la caja en el y-axis
re La dimensión de la caja en el z-axis

Traducción 3D

Aquí es cómo traducir objetos en P3D:

size(200, 200, P3D); //Starting P3D renderer
fill(255, 0, 0, 150); //transparent red
rect(10, 10, 100, 100); //first rectangle
fill(0, 0, 255, 150); //transparent blue
translate(50, 50, 50); //translate x, y and z by 50 pixels
rect(0, 0, 100, 100); //second rectangle (same dimensions as the first one)

Ejemplo de traducción

Rojo: primer rectángulo Azul: segundo rectángulo

Como puede verse en el boceto anterior, el segundo rectángulo solo parece ser más grande que el primero, cuando en realidad está "más cerca" de la pantalla como resultado de traducir el rectángulo 50 píxeles a lo largo del z-axis (y de Por supuesto, el rectángulo se ha traducido a lo largo de los ejes x e y ).

Rotación 3D

Hay tres funciones para la rotación 3D: rotateX(angle) , rotateY(angle) y rotateZ(angle) para rotar en sus respectivos ejes donde el angle está en radianes.

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)

rotarX

rotateY(radians(45)); //rotate in the y-axis by passing the radians conversion of 45 degrees

rotarY

rotateZ(3*PI/4); //rotate in the z-axis by 3*PI/4 radians (270 degrees)

rotarZ

Nota: las transformaciones (como las traducciones y rotaciones) se agregan a la transformación anterior.

Dibujando un cuboide

Para dibujar un cuboide, tienes que usar la función box() dando sus dimensiones como sus parámetros.

size(200, 200, P3D); //Starting the P3D renderer
translate(width/2, height/2); //Translating to the centre of the sketch
rotateY(PI/4); //rotate so that...
rotateX(PI/6); //... it will be easy to see the box
noFill(); //disabling the box's fill, so that we will be able to see its edges
box(100, 50, 75); //the box function requires its dimensions as its parameters

caja con tres parámetros

Tenga en cuenta que la función box() no acepta su posición como parámetros

También hay una forma de llamar a la función box() con un solo parámetro. En este caso, será un cubo.

stroke(0, 100, 255); //change the edges' colour
fill(0, 0, 255); //fill the `box` in a blue colour
box(100); //draw a cube

cubo con función de caja



Modified text is an extract of the original Stack Overflow Documentation
Licenciado bajo CC BY-SA 3.0
No afiliado a Stack Overflow