May 2019
Intermediate to advanced
542 pages
13h 37m
English
To make a 3D object, we need to draw the back and sides of our wedge object. We'll start by calculating the coordinates for the back of the wedge using a list comprehension:
back_vertices = [ qtg.QVector3D(x.toVector2D(), -0.5) for x in front_vertices]
To create the back face, we only need to copy each of the front face coordinates and move the z axis back a bit. So, we're using the QVector3D object's toVector2D() method to produce a new vector with only the x and y axes, then passing that to the constructor of a new QVector3D object along with a second argument specifying the new z coordinate.
Now, we'll pass this set of vertices to OpenGL and draw as follows:
self.program.setAttributeArray( self.vertex_location, reversed(back_vertices)) ...
Read now
Unlock full access