Cube Chopper

Now we are finally getting to 3D. Here the object consist of triangles which are rasterized similarly as we rasterized them with the Bresenham algorithm before. In order to define an object, first one needs to define its geometry: vertices and faces.

Task is to construct a cubistic looking chopper (the aircraft, not the motorcycle). In the most simple form it will consist of 3 cuboids: 1 big one for the body and 2 smaller ones for the blades. Those will currently be monochrome, we will see how to calculate some better colors based on the illumination later. For now, just pick a single color for the body and another for the blades.

We will define our own cuboid geometry construction function. A cuboid is just a scaled cube, so our function can return a geometry for a cube and we can scale it afterwards. The cube, however, needs to be made up of triangles. This means that each face of the cube consists of 2 triangles. So in total there are 12 triangle faces. The vertex count for a cube is 8. The cube should be centered at (0, 0, 0), so that the scaling and other transformations would work as intended. Here is an illustration of such a cube:

You may define the vertices in another order. This means that the faces you have, will be made up of other vertices. Keep in mind that the positive rotational direction in our right-handed coordinate system is counter-clockwise. This means that the front face of a triangle is such, where the vertices go in a counter-clockwise order.

For example, if you define a face consisting of ordered vertices: 1, 5, 6, then that face's front side will be pointing outwards from the cube, which is correct.

Task is to create a function that creates such a cube. Then use that function to have a chopper, with 1 cuboid as the body and 2 cuboids as the blades, in the scene. After this make the blades rotate around the y axis at some speed.

Overall the result would look something like:

Feel free to pick your own colors, scale factors and positions for the geometry.

JavaScript

Base code is located at:
https://cglearn.codelight.eu/files/course/3/CubeChopperJS.zip

Do not use THREE.BoxGeometry, but try to write your own function.

C++

This week we will be making use of two new libraries GLEW and GLM.

GLEW (OpenGL Extension Wrangler library) GLEW provides efficient run-time mechanisms for determining which OpenGL extensions are supported on the target platform. This makes it much easier to use the latest OpenGL version available on current system.

GLM (OpenGL Mathematics) is a header only C++ mathematics library for graphics software based on the OpenGL Shading Language (GLSL) specifications. We will (mainly) use this for matrices and transformations.

Base code is located at:

https://cglearn.codelight.eu/files/course/3/CubeChopperCPP.zip

Try to follow this object hierarchy (when using the matrix stack in C++) for the chopper:

 

;