MOVEMENT OF 3D OBJECTS IN PROCESSING
In order to create 3D objects in processing, we can do it in several ways:
- use built-in processing methods to draw basic 3d shapes:
- Use the PShape class
- Create the shape yourself using: beginShape().....endShape()
Drawing basic 3D shapes using Processing methods
In this way we can create basic shapes: ball, cube:
Methods used:
Methods used:
3D animation: Earth's movement around the sun - processing
An animation of the Earth's motion around the Sun is shown below. At the same time, the Earth performs two rotations:
- rotation of the Earth around the Sun
- rotation of the Earth on its axis
Animation3D: Rotation of the Earth around the Sun
Animation not working? Please refresh the page
← scroll horizontal →
Movement of the Earth around the Sun 3d animation - code in processing
In the animation of the rotation of the Earth around the Sun, the class PShape is used, as can be seen in the code in Figure 1. In order to create the texture of the image, it is necessary to insert the images that we will use for the texture of the Earth and the Sun into the data folder, which is located in the root folder of the application. Inside the main scatch, objects of class PImage, sunIm and earthIm are defined, which will represent the images for creating the texture. Then constants are declared, which respectively represent the radii of the Earth, the Sun and the 2 semi-axes of the ellipse, which represents the path of the Earth around the Sun. Variables used to define the position of the camera in the x, y and z direction and the rotation angles are also defined.
fiZ - the angle of rotation of the Earth around its axis
fiS - angle of rotation of the Earth around the Sun
wiz- the angular speed of rotation of the Earth around its axis
wis - angular velocity of rotation of the Earth around the Sun
The rotation speed of the Earth is arbitrary and does not correspond to real values, but is modified so that the movement of the Earth can be observed.
Within the setup method, Earth and Sun objects, Earth and Sun images are created.
A texture is set on an object with the setTexture(image) method, where the image is passed to the method as a parameter.
fiZ - the angle of rotation of the Earth around its axis
fiS - angle of rotation of the Earth around the Sun
wiz- the angular speed of rotation of the Earth around its axis
wis - angular velocity of rotation of the Earth around the Sun
The rotation speed of the Earth is arbitrary and does not correspond to real values, but is modified so that the movement of the Earth can be observed.
Within the setup method, Earth and Sun objects, Earth and Sun images are created.
A texture is set on an object with the setTexture(image) method, where the image is passed to the method as a parameter.
In the draw() method, the background image, space in this example, is placed first. The coordinate system is translated to the middle of the frame, using the translate(width/2,height/2,0) method. We see that the z coordinate is set to zero.
The camera is then positioned at camX, camY and camZ coordinates, and the camera focus is at the center of the coordinate system. The last 3 parameters define which coordinate axis is at the top of the display, and in this case it is the z axis.
For a more beautiful display, the directional light directionalLight() is used, approximately white in color and directed between the x and z axes and in the negative direction.
The camera is then positioned at camX, camY and camZ coordinates, and the camera focus is at the center of the coordinate system. The last 3 parameters define which coordinate axis is at the top of the display, and in this case it is the z axis.
For a more beautiful display, the directional light directionalLight() is used, approximately white in color and directed between the x and z axes and in the negative direction.
Within the translated coordinate system, which is now in the center of the display, the Sun is rendered, by calling the shape(sun) method, which is passed the previously created object representing the sun of class PShape. An elliptical path is then drawn, drawn in the X0Y plane and temporarily rotated by an angle of PI/2 around the X axis(rotateX(HALF_PI)). After drawing, ie. after the call to popMatrix(), see line 46, figure 2, the coordinate system returns to the position it was in before the call to pushMatrix(), the method called in line 41, see figure 2.
Before drawing the object representing the planet Earth, the coordinate system is rotated about the Y axis by an angle fis, which is actually the angle of rotation of the Earth around the Sun.
Before drawing the object representing the planet Earth, the coordinate system is rotated about the Y axis by an angle fis, which is actually the angle of rotation of the Earth around the Sun.
Before drawing the Earth, the coordinate system is translated by the value of the radius of the path of the Earth around the Sun. Here, it is roughly assumed that the path is circular even if it is actually an ellipse. Furthermore, the coordinate system is rotated by the angle fiz, i.e. for the angle of rotation of the Earth around its axis.
At the end of the draw() method, the rotation angles fis and fis are increased by the values of the angular velocities of the Earth around the Sun and the Earth around its axis.
At the end of the draw() method, the rotation angles fis and fis are increased by the values of the angular velocities of the Earth around the Sun and the Earth around its axis.
After launching the application:
Previous
|< Introduction to 3D processing
|< Introduction to 3D processing