To get the Transform component to affect the drawing, further changes need to be made to the add_component and update functions in the Object class. Therefore, next we test if the component is of type Transform and push it into first position in the list.
from Transform import *
.
def add_component(self, component) :
if isinstance (component, Transform) :
self.components.insert ( 0 , self.components)
self.components.append (component)
def update (self):
for $c$ in self.components:
if isinstance(c, Transform) :
pos $=c \cdot$ get_position ()
glTranslatef(pos.x, pos.y, pos.z)
if isinstance (c, Mesh3D) :
c. draw ()
There are a couple of things to take note of in this code. First, a Transform component is treated as a very special case, and you will see that it is inserted first in the component list. This is because the position needs to be set before any drawing is done by Mesh3D. Next, the update method, before drawing the mesh, calls a glTranslatef () method to ensure that the movement from the Transform component is taken into consideration and sent to OpenGL.