def material_matrix(self): """ Creates a transformation matrix scaled to the size of the torus :return: the transformation matrix :return: pyglet_helper.util.Tmatrix """ out = Tmatrix() out.translate(Vector([.5, .5, .5])) out.scale(Vector([self.radius, self.radius, self.radius]) * (.5 / (self.radius + self.thickness))) return out
def material_matrix(self): """ Creates a transformation matrix for spherical objects :return: the transformation matrix :rtype: pyglet_helper.util.Tmatrix """ out = Tmatrix() out.translate(Vector([.5, .5, .5])) scale = self.scale out.scale(scale * (.5 / max(scale.x_component, max(scale.y_component, scale.z_component)))) return out
def material_matrix(self): """ Creates a transformation matrix for spherical objects :return: the transformation matrix :rtype: pyglet_helper.util.Tmatrix """ out = Tmatrix() out.translate(Vector([.5, .5, .5])) scale = self.scale out.scale(scale * (.5 / max( scale.x_component, max(scale.y_component, scale.z_component)))) return out
def material_matrix(self): """ Creates a transformation matrix for pyramid objects :return: the transformation matrix :rtype: pyglet_helper.util.Tmatrix """ out = Tmatrix() out.translate(Vector([0, .5, .5])) scale = Vector([self.axis.mag(), self.height, self.width]) out.scale(Vector([self.scale,self.scale,self.scale]) * (1.0 /max(scale.x_component, max(scale.y_component, scale.z_component)))) return out
def material_matrix(self): """ Creates a transformation matrix scaled to the size of the axial object :return: the transformation matrix :return: pyglet_helper.util.Tmatrix """ out = Tmatrix() out.translate(Vector([.0005, .5, .5])) out.scale(self.scale * (.999 / max(self.scale.x_component, self.scale.y_component * 2))) out_vector = Vector([0, 1, 0]) out_vector = out_vector.rotate(angle=.5*pi) out = out * out_vector return out
def material_matrix(self): """ Creates a transformation matrix scaled to the size of the axial object :return: the transformation matrix :return: pyglet_helper.util.Tmatrix """ out = Tmatrix() out.translate(Vector([.0005, .5, .5])) out.scale( self.scale * (.999 / max(self.scale.x_component, self.scale.y_component * 2))) out_vector = Vector([0, 1, 0]) out_vector = out_vector.rotate(angle=.5 * pi) out = out * out_vector return out
def render(self, scene): """ Render the arrow on the current view. :param scene: The view to render the model into. :type scene: pyglet_helper.objects.View """ mat = Material() if self.degenerate: return self.init_model(scene) self.color.gl_set(self.opacity) _head_width, _shaft_width, _len, _head_length = \ self.effective_geometry(1.0) if self.mat and self.mat.get_shader_program(): model_material_loc = self.mat.get_shader_program().\ get_uniform_location(scene, "model_material") else: model_material_loc = -1 # Render the shaft and the head in back to front order (the shaft is in # front of the head if axis points away from the camera) shaft = self.axis.dot(scene.camera - (self.pos + self.axis * (1 - _head_length / _len))) < 0 gl.glPushMatrix() self.model_world_transform(scene.gcf).gl_mult() for part in range(0, 2): if part == shaft: gl.glScaled(_len - _head_length, _shaft_width, _shaft_width) gl.glTranslated(0.5, 0, 0) if model_material_loc >= 0: model_mat = Tmatrix() scale = 1.0 / max(_len, _head_width) _translation_magnitude = (_len - _head_length) * scale *\ 0.5 model_mat.translate( Vector([_translation_magnitude, 0.5, 0.5])) model_mat.scale( Vector([(_len - _head_length), _shaft_width, _shaft_width]) * scale) mat.get_shader_program().\ set_uniform_matrix(scene, model_material_loc, model_mat) scene.box_model.gl_render() gl.glTranslated(-0.5, 0, 0) gl.glScaled(1 / (_len - _head_length), 1 / _shaft_width, 1 / _shaft_width) else: gl.glTranslated(_len - _head_length, 0, 0) gl.glScaled(_head_length, _head_width, _head_width) if model_material_loc >= 0: model_mat = Tmatrix() _scale = 1.0 / max(_len, _head_width) model_mat.translate( Vector([(_len - _head_length) * _scale, 0.5, 0.5])) model_mat.scale( Vector([_head_length, _head_width, _head_width]) * _scale) mat.get_shader_program().\ set_uniform_matrix(scene, model_material_loc, model_mat) scene.pyramid_model.gl_render() gl.glScaled(1 / _head_length, 1 / _head_width, 1 / _head_width) gl.glTranslated(-_len + _head_length, 0, 0) gl.glPopMatrix()