def test_operators_matrix44(self): m1 = Matrix44.identity() m2 = Matrix44.from_x_rotation(0.5) # add self.assertTrue(np.array_equal(m1 + m2, matrix44.create_identity() + matrix44.create_from_x_rotation(0.5))) # subtract self.assertTrue(np.array_equal(m1 - m2, matrix44.create_identity() - matrix44.create_from_x_rotation(0.5))) # multiply self.assertTrue(np.array_equal(m1 * m2, matrix44.multiply(matrix44.create_from_x_rotation(0.5), matrix44.create_identity()))) # divide self.assertRaises(ValueError, lambda: m1 / m2) # inverse self.assertTrue(np.array_equal(~m2, matrix44.inverse(matrix44.create_from_x_rotation(0.5)))) # == self.assertTrue(Matrix44() == Matrix44()) self.assertFalse(Matrix44() == Matrix44([1. for n in range(16)])) # != self.assertTrue(Matrix44() != Matrix44([1. for n in range(16)])) self.assertFalse(Matrix44() != Matrix44())
def _gl_look_at(self, pos, target, up) -> numpy.ndarray: """The standard lookAt method. Args: pos: current position target: target position to look at up: direction up Returns: numpy.ndarray: The matrix """ z = vector.normalise(pos - target) x = vector.normalise(vector3.cross(vector.normalise(up), z)) y = vector3.cross(z, x) translate = matrix44.create_identity() translate[3][0] = -pos.x translate[3][1] = -pos.y translate[3][2] = -pos.z rotate = matrix44.create_identity() rotate[0][0] = x[0] # -- X rotate[1][0] = x[1] rotate[2][0] = x[2] rotate[0][1] = y[0] # -- Y rotate[1][1] = y[1] rotate[2][1] = y[2] rotate[0][2] = z[0] # -- Z rotate[1][2] = z[1] rotate[2][2] = z[2] return matrix44.multiply(translate, rotate)
def test_operators_matrix44(self): m1 = Matrix44.identity() m2 = Matrix44.from_x_rotation(0.5) # add self.assertTrue( np.array_equal( m1 + m2, matrix44.create_identity() + matrix44.create_from_x_rotation(0.5))) # subtract self.assertTrue( np.array_equal( m1 - m2, matrix44.create_identity() - matrix44.create_from_x_rotation(0.5))) # multiply self.assertTrue( np.array_equal( m1 * m2, matrix44.multiply(matrix44.create_identity(), matrix44.create_from_x_rotation(0.5)))) # divide self.assertRaises(ValueError, lambda: m1 / m2) # inverse self.assertTrue( np.array_equal( ~m2, matrix44.inverse(matrix44.create_from_x_rotation(0.5))))
def init(): global shaderProgram global vao global vbo global mvp glClearColor(0, 0, 0, 0) vertex_code = readShaderFile('piramide.vp') fragment_code = readShaderFile('piramide.fp') # compile shaders and program vertexShader = shaders.compileShader(vertex_code, GL_VERTEX_SHADER) fragmentShader = shaders.compileShader(fragment_code, GL_FRAGMENT_SHADER) shaderProgram = shaders.compileProgram(vertexShader, fragmentShader) # Create and bind the Vertex Array Object vao = GLuint(0) glGenVertexArrays(1, vao) glBindVertexArray(vao) # Create and bind the Vertex Buffer Object vbo = glGenBuffers(1) glBindBuffer(GL_ARRAY_BUFFER, vbo) glBufferData(GL_ARRAY_BUFFER, piramide['vertices'], GL_STATIC_DRAW) glVertexAttribPointer( 0, 3, GL_FLOAT, False, 6 * sizeof(GLfloat), ctypes.c_void_p(0)) # first 0 is the location in shader glVertexAttribPointer( 1, 3, GL_FLOAT, False, 6 * sizeof(GLfloat), ctypes.c_void_p(3 * sizeof(GLfloat))) # first 0 is the location in shader glEnableVertexAttribArray(0) # 0=location do atributo, tem que ativar todos os atributos inicialmente sao desabilitados por padrao glEnableVertexAttribArray(1) # 1=location do atributo, tem que ativar todos os atributos inicialmente sao desabilitados por padrao # cria a matriz de transformação mvp['model'] = matrix44.create_identity() # rotacao rot = matrix44.create_from_y_rotation(math.radians(10)) mvp['model'] = matrix44.multiply(mvp['model'], rot) # matrix model mvp['view'] = matrix44.create_identity() # matrix view mvp['projection'] = matrix44.create_identity() # matrix projection # atribui uma variavel uniforme para cada matriz mvp['idMod'] = glGetUniformLocation(shaderProgram, "model") mvp['idView'] = glGetUniformLocation(shaderProgram, "view") mvp['idProj'] = glGetUniformLocation(shaderProgram, "projection") # Note that this is allowed, the call to glVertexAttribPointer registered VBO # as the currently bound vertex buffer object so afterwards we can safely unbind glBindBuffer(GL_ARRAY_BUFFER, 0) # Unbind VAO (it's always a good thing to unbind any buffer/array to prevent strange bugs) glBindVertexArray(0)
def test_operators_matrix33(self): m1 = Matrix44.identity() m2 = Matrix33.from_x_rotation(0.5) # add self.assertTrue(np.array_equal(m1 + m2, matrix44.create_identity() + matrix44.create_from_x_rotation(0.5))) # subtract self.assertTrue(np.array_equal(m1 - m2, matrix44.create_identity() - matrix44.create_from_x_rotation(0.5))) # multiply self.assertTrue(np.array_equal(m1 * m2, matrix44.multiply(matrix44.create_identity(), matrix44.create_from_x_rotation(0.5)))) # divide self.assertRaises(ValueError, lambda: m1 / m2)
def __init__(self, name, **kwargs): """Create a scene with a name. Args: name (str): Unique name or path for the scene """ self.name = name self.root_nodes = [] # References resources in the scene self.nodes = [] self.materials = [] self.meshes = [] self.cameras = [] self.bbox_min = None # Type: numpy.ndarray self.bbox_max = None # Type: numpy.ndarray self.diagonal_size = 1.0 self.bbox_vao = geometry.bbox() global DEFAULT_BBOX_PROGRAM if DEFAULT_BBOX_PROGRAM is None: DEFAULT_BBOX_PROGRAM = programs.load( ProgramDescription(path='scene_default/bbox.glsl'), ) self.bbox_program = DEFAULT_BBOX_PROGRAM global DEFAULT_WIREFRAME_PROGRAM if DEFAULT_WIREFRAME_PROGRAM is None: DEFAULT_WIREFRAME_PROGRAM = programs.load( ProgramDescription(path='scene_default/wireframe.glsl'), ) self.wireframe_program = DEFAULT_WIREFRAME_PROGRAM self._matrix = matrix44.create_identity(dtype='f4')
def __init__(self, name, mesh_programs=None, **kwargs): """ :param name: Unique name or path for the scene :param mesh_programs: List of MeshPrograms to apply to the scene :param loader: Loader class for the scene if relevant """ self.name = name self.root_nodes = [] # References resources in the scene self.nodes = [] self.materials = [] self.meshes = [] self.cameras = [] self.bbox_min = None self.bbox_max = None self.diagonal_size = 1.0 self.bbox_vao = geometry.bbox() self.bbox_program = programs.load(ProgramDescription( label='scene_default/bbox.glsl', path='scene_default/bbox.glsl')) self._view_matrix = matrix44.create_identity()
def __init__(self, data): self.children = data.get('children') self.matrix = data.get('matrix') self.mesh = data.get('mesh') self.camera = data.get('camera') self.translation = data.get('translation') self.rotation = data.get('rotation') self.scale = data.get('scale') if self.matrix is None: self.matrix = matrix44.create_identity() if self.translation is not None: self.matrix = matrix44.create_from_translation(self.translation) if self.rotation is not None: quat = quaternion.create(self.rotation[0], self.rotation[1], self.rotation[2], self.rotation[3]) mat = matrix44.create_from_quaternion(quat) self.matrix = matrix44.multiply(mat, self.matrix) if self.scale is not None: self.matrix = matrix44.multiply( matrix44.create_from_scale(self.scale), self.matrix)
def __init__(self, name, color, nVet, vao, vbo): self.name = name # nome self.color = color # cor self.model = mat4.create_identity() # matrix model self.nVet = nVet # num de vertices self.vao = vao self.vbo = vbo
def __init__(self, **kwargs): super().__init__(**kwargs) if self.wnd.name != 'pygame2': raise RuntimeError( 'This example only works with --window pygame2 option') self.pg_res = (160, 160) # Create a 24bit (rgba) offscreen surface pygame can render to self.pg_screen = pygame.Surface(self.pg_res, flags=pygame.SRCALPHA) # 24 bit (rgba) moderngl texture self.pg_texture = self.ctx.texture(self.pg_res, 4) self.pg_texture.filter = moderngl.NEAREST, moderngl.NEAREST # Simple geometry and shader to render self.cube = geometry.cube(size=(2.0, 2.0, 2.0)) self.texture_prog = self.load_program( 'programs/cube_simple_texture.glsl') self.texture_prog['m_proj'].write( matrix44.create_perspective_projection(60, self.wnd.aspect_ratio, 1, 100, dtype='f4')) self.texture_prog['m_model'].write( matrix44.create_identity(dtype='f4'))
def prepare(self) -> None: """prepare the scene for rendering. Calls ``apply_mesh_programs()`` assigning default meshprograms if needed and sets the model matrix. """ self.apply_mesh_programs() # Recursively calculate model matrices self.matrix = matrix44.create_identity(dtype='f4')
def test_create_identity( self ): result = matrix44.create_identity() expected = numpy.eye( 4 ) self.assertTrue( numpy.array_equal( result, expected ), "Matrix44 identity incorrect" )
def test_create_matrix33_view( self ): mat = matrix44.create_identity() result = matrix44.create_matrix33_view( mat ) expected = numpy.eye( 3 ) self.assertTrue( numpy.array_equal( result, expected ), "Matrix44 create_matrix33_view incorrect" )
def calc_scene_bbox(self) -> None: """Calculate scene bbox""" bbox_min, bbox_max = None, None for node in self.root_nodes: bbox_min, bbox_max = node.calc_global_bbox( matrix44.create_identity(dtype='f4'), bbox_min, bbox_max) self.bbox_min = bbox_min self.bbox_max = bbox_max self.diagonal_size = vector3.length(self.bbox_max - self.bbox_min)
def __init__(self): self.objs = [] self.view = mat4.create_identity() # matriz view self.projection = mat4.create_orthogonal_projection(-2, 2, -2, 2, -2, 2) # matriz projection self.lights = [] self.camPos = [0.0, 0.0, 0.0] self.camLookAt = [0.0, 0.0, -1.0] self.shader = None self.diffuse = 0.2 self.ambient = 0.2 self.specular = 0.2
def identity(): mat = matrix44.create_identity() vec = vector3.unit.x result = matrix44.apply_to_vector( mat, vec ) expected = vec self.assertTrue( numpy.array_equal( result, expected ), "Matrix44 apply_to_vector incorrect with identity" )
def translation(): mat = matrix44.create_identity() vec = numpy.array([0.0, 0.0, 0.0]) mat[3,0:3] = [1.0, 2.0, 3.0] result = matrix44.apply_to_vector( mat, vec ) expected = mat[3,0:3] self.assertTrue( numpy.allclose( result, expected ), "Matrix44 apply_to_vector incorrect with translation" )
def test_operators_vector4(self): m = Matrix44.identity() v = Vector4([1,1,1,1]) # add self.assertRaises(ValueError, lambda: m + v) # subtract self.assertRaises(ValueError, lambda: m - v) # multiply self.assertTrue(np.array_equal(m * v, matrix44.apply_to_vector(matrix44.create_identity(), [1,1,1,1]))) # divide self.assertRaises(ValueError, lambda: m / v)
def test_operators_quaternion(self): m = Matrix44.identity() q = Quaternion.from_x_rotation(0.7) # add self.assertRaises(ValueError, lambda: m + q) # subtract self.assertRaises(ValueError, lambda: m - q) # multiply self.assertTrue(np.array_equal(m * q, matrix44.multiply(matrix44.create_identity(), matrix44.create_from_quaternion(quaternion.create_from_x_rotation(0.7))))) # divide self.assertRaises(ValueError, lambda: m / q)
def test_create(self): self.instance.add_point_light(position=[0.0, 0.0, 0.0], radius=40.0) cube = geometry.cube(width=8.0, height=8.0, depth=8.0) geo_shader_color = self.load_program( path="deferred/geometry_color.glsl") projection = Projection() with self.instance.gbuffer_scope: cube.render(geo_shader_color) self.instance.render_lights( matrix44.create_identity(dtype='f4'), projection, ) self.instance.combine() self.instance.clear()
def __init__(self, name, **kwargs): """Create a scene with a name. Args: name (str): Unique name or path for the scene """ self.name = name self.root_nodes = [] # References resources in the scene self.nodes = [] self.materials = [] self.meshes = [] self.cameras = [] self.bbox_min = None # Type: numpy.ndarray self.bbox_max = None # Type: numpy.ndarray self.diagonal_size = 1.0 self.bbox_vao = geometry.bbox() if self.ctx.extra is None: self.ctx.extra = {} # Load bbox program and cache in the context self.bbox_program = self.ctx.extra.get("DEFAULT_BBOX_PROGRAM") if not self.bbox_program: self.bbox_program = programs.load( ProgramDescription(path="scene_default/bbox.glsl"), ) self.ctx.extra["DEFAULT_BBOX_PROGRAM"] = self.bbox_program # Load wireframe program and cache in the context self.wireframe_program = self.ctx.extra.get( "DEFAULT_WIREFRAME_PROGRAM") if not self.wireframe_program: self.wireframe_program = programs.load( ProgramDescription(path="scene_default/wireframe.glsl"), ) self.ctx.extra[ "DEFAULT_WIREFRAME_PROGRAM"] = self.wireframe_program self._matrix = matrix44.create_identity(dtype="f4")
def test_operators_quaternion(self): m = Matrix44.identity() q = Quaternion.from_x_rotation(0.7) # add self.assertRaises(ValueError, lambda: m + q) # subtract self.assertRaises(ValueError, lambda: m - q) # multiply self.assertTrue( np.array_equal( m * q, matrix44.multiply( matrix44.create_identity(), matrix44.create_from_quaternion( quaternion.create_from_x_rotation(0.7))))) # divide self.assertRaises(ValueError, lambda: m / q)
def __init__(self, order, shader, parent=None, x=0.0, y=0.0, active=True): super().__init__(order, parent=parent) if active: CameraGrp.active_cam = self self.x, self.y = x, y self.width = 1280 self.height = 720 self.hw, self.hh = self.width / 2, self.height / 2 self._zoom = 50.0 self.shader = shader self.is_ortho = True #ortho self.ortho = None self.persp = None self.projection = None self.view = None self.default_proj = None self.default_view = matrix44.create_identity() self.up_x = 0.0 self.up_y = 1.0 self._angle = 0.0 self.calc_projection()
def __init__(self, name, **kwargs): """Create a scene with a name. Args: name (str): Unique name or path for the scene """ self.name = name self.root_nodes = [] # References resources in the scene self.nodes = [] self.materials = [] self.meshes = [] self.cameras = [] self.bbox_min = None # Type: numpy.ndarray self.bbox_max = None # Type: numpy.ndarray self.diagonal_size = 1.0 self.bbox_vao = geometry.bbox() self.bbox_program = programs.load( ProgramDescription(path='scene_default/bbox.glsl'), ) self._model_matrix = matrix44.create_identity()
def __init__(self): self.sky_sphere = geometry.sphere(100.0) self.sky_texture = self.get_texture('milkyway') self.sky_shader = self.get_program('milkyway') self.sun_sphere = geometry.sphere(10.0) self.sun_shader = self.get_program('sun') self.sun_texture = self.get_texture('sun') # Matrices self.projection_bytes = self.sys_camera.projection.tobytes() self.sun_matrix = matrix44.create_identity() # Default shader parameters self.sky_shader['m_proj'].write(self.projection_bytes) self.sky_shader['texture0'].value = 0 self.sky_texture.use(location=0) # self.sun_shader['m_proj'].write(self.projection_bytes) # self.sun_shader['texture0'].value = 1 self.sun_pos = None self.earth = EarthEffect(parent=self)
def init(): global shaderProgram global vao global vbo global model global idMod global view global idView global projection global idProj global idColor global idLight global idLightPos global idViewPos global posCam glClearColor(0, 0, 0, 0) vertex_code = readShaderFile('cuboLuz.vp') fragment_code = readShaderFile('cuboLuz.fp') # compile shaders and program vertexShader = shaders.compileShader(vertex_code, GL_VERTEX_SHADER) fragmentShader = shaders.compileShader(fragment_code, GL_FRAGMENT_SHADER) shaderProgram = shaders.compileProgram(vertexShader, fragmentShader) # cria um vao vao = GLuint(0) glGenVertexArrays(1, vao) glBindVertexArray(vao) # dados do objeto q serao passados para o shaders (vertices e vetores normais) vertices = np.array(readVertexData(), dtype='f') print("vertices:", len(vertices) // 6) print(vertices) vbo = glGenBuffers(1) # gera vbos glBindBuffer(GL_ARRAY_BUFFER, vbo) glBufferData(GL_ARRAY_BUFFER, vertices, GL_STATIC_DRAW) glVertexAttribPointer(0, 3, GL_FLOAT, False, 6 * sizeof(GLfloat), ctypes.c_void_p(3 * sizeof(GLfloat))) # vertices glVertexAttribPointer(1, 3, GL_FLOAT, False, 6 * sizeof(GLfloat), ctypes.c_void_p(0)) # vertores normais # habilita os atributos glEnableVertexAttribArray(0) glEnableVertexAttribArray(1) # cria a matriz de transformação model = matrix44.create_identity() #ratacoes rotY = matrix44.create_from_y_rotation(math.radians(45)) rotx = matrix44.create_from_x_rotation(math.radians(45)) rotT = matrix44.multiply(rotY, rotx) model = matrix44.multiply(model, rotT) posCam = [0.0, 0.0, 0.0] view = matrix44.create_look_at(posCam, [0.0, 0.0, -0.1], [0.0, 1.0, 0.0]) projection = matrix44.create_orthogonal_projection(-2.0, 2.0, -2.0, 2.0, 2.0, -2.0) # amplia a visao print(f'Model:\n{model}\n') print(f'View:\n{view}\n') print(f'Projection:\n{projection}\n') # atribui uma variavel uniforme para cada matriz idMod = glGetUniformLocation(shaderProgram, "model") idView = glGetUniformLocation(shaderProgram, "view") idProj = glGetUniformLocation(shaderProgram, "projection") # iluminação idColor = glGetUniformLocation(shaderProgram, "objectColor") idLight = glGetUniformLocation(shaderProgram, "lightColor") idLightPos = glGetUniformLocation(shaderProgram, "lightPos") idViewPos = glGetUniformLocation(shaderProgram, "viewPos") # Note that this is allowed, the call to glVertexAttribPointer registered VBO # as the currently bound vertex buffer object so afterwards we can safely unbind glBindBuffer(GL_ARRAY_BUFFER, 0) # Unbind VAO (it's always a good thing to unbind any buffer/array to prevent strange bugs) glBindVertexArray(0)
def prepare(self): self.apply_mesh_programs() self.view_matrix = matrix44.create_identity()
def test_multiply_identity(self): m1 = matrix44.create_identity() m2 = matrix44.create_identity() result = matrix44.multiply(m1, m2) self.assertTrue(np.allclose(result, np.dot(m1,m2)))
while True: inputHandler.handleInput() glBindFramebuffer(GL_FRAMEBUFFER, framebufferName); glViewport(0,0,HEIGHT,WIDTH) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ) glUseProgram( programId ) timePassed = clock.tick() camera.regenProjectionMatrix() projection = camera.getProjectionMatrix() camera.regenViewMatrix() view = camera.getViewMatrix() model = array(mat4.create_identity(), dtype=float32) MVP = array( mat4.multiply(mat4.multiply(model, view), projection ), dtype=float32) glUniformMatrix4fv( matrixId, 1, GL_FALSE, MVP ) glActiveTexture(GL_TEXTURE0) glBindTexture(GL_TEXTURE_2D, textureId) glUniform1i(textureSamplerId, 0); glEnableClientState(GL_VERTEX_ARRAY) glEnableClientState(GL_NORMAL_ARRAY) vert_norm_vbo.bind() index_vbo.bind() glVertexPointerf( vert_norm_vbo ) glNormalPointerf( vert_norm_vbo + len(vert_array) )
def test_create_identity(self): result = matrix44.create_identity() np.testing.assert_almost_equal(result, np.eye(4), decimal=5)
def test_apply_to_vector_identity(self): mat = matrix44.create_identity() result = matrix44.apply_to_vector(mat, [1.,0.,0.]) np.testing.assert_almost_equal(result, [1.,0.,0.], decimal=5)
def test_multiply_identity(self): m1 = matrix44.create_identity() m2 = matrix44.create_identity() result = matrix44.multiply(m1, m2) self.assertTrue(np.allclose(result, np.dot(m1, m2)))
def test_apply_to_vector_identity(self): mat = matrix44.create_identity() result = matrix44.apply_to_vector(mat, [1., 0., 0.]) np.testing.assert_almost_equal(result, [1., 0., 0.], decimal=5)
def __init__(self, entityName, componentInfo): Component.__init__(self, entityName, componentInfo) self.position = vector3.create(self.pos[0], self.pos[1], self.pos[2]) self.rotation = quaternion.create_from_z_rotation(self.rotAngle) self.worldMatrix = matrix44.create_identity() self.dirty = True
def test_create_matrix33_view( self ): mat = matrix44.create_identity() result = matrix44.create_matrix33_view(mat) np.testing.assert_almost_equal(result, mat[:3,:3], decimal=5) mat[0,0] = 2. np.testing.assert_almost_equal(result, mat[:3,:3], decimal=5)
def test_operators_number(self): m = Matrix44.identity() fv = np.empty((1,), dtype=[('i', np.int16, 1),('f', np.float32, 1)]) fv[0] = (2, 2.0) # add self.assertTrue(np.array_equal(m + 1.0, matrix44.create_identity()[:] + 1.0)) self.assertTrue(np.array_equal(m + 1, matrix44.create_identity()[:] + 1.0)) self.assertTrue(np.array_equal(m + np.float(1.), matrix44.create_identity()[:] + 1.0)) self.assertTrue(np.array_equal(m + fv[0]['f'], matrix44.create_identity()[:] + 2.0)) self.assertTrue(np.array_equal(m + fv[0]['i'], matrix44.create_identity()[:] + 2.0)) # subtract self.assertTrue(np.array_equal(m - 1.0, matrix44.create_identity()[:] - 1.0)) self.assertTrue(np.array_equal(m - 1, matrix44.create_identity()[:] - 1.0)) self.assertTrue(np.array_equal(m - np.float(1.), matrix44.create_identity()[:] - 1.0)) self.assertTrue(np.array_equal(m - fv[0]['f'], matrix44.create_identity()[:] - 2.0)) self.assertTrue(np.array_equal(m - fv[0]['i'], matrix44.create_identity()[:] - 2.0)) # multiply self.assertTrue(np.array_equal(m * 2.0, matrix44.create_identity()[:] * 2.0)) self.assertTrue(np.array_equal(m * 2, matrix44.create_identity()[:] * 2.0)) self.assertTrue(np.array_equal(m * np.float(2.), matrix44.create_identity()[:] * 2.0)) self.assertTrue(np.array_equal(m * fv[0]['f'], matrix44.create_identity()[:] * 2.0)) self.assertTrue(np.array_equal(m * fv[0]['i'], matrix44.create_identity()[:] * 2.0)) # divide self.assertTrue(np.array_equal(m / 2.0, matrix44.create_identity()[:] / 2.0)) self.assertTrue(np.array_equal(m / 2, matrix44.create_identity()[:] / 2.0)) self.assertTrue(np.array_equal(m / np.float(2.), matrix44.create_identity()[:] / 2.0)) self.assertTrue(np.array_equal(m / fv[0]['f'], matrix44.create_identity()[:] / 2.0)) self.assertTrue(np.array_equal(m / fv[0]['i'], matrix44.create_identity()[:] / 2.0))
def set_state(self): #self.shader.uniforms.colorize = 1 #self.shader.uniforms.clr_clr = self.color self.shader.uniforms.trfm = matrix44.create_identity( ) #Clean transform matrix before draw lables TODO move somewhere
def test_create_matrix33_view(self): mat = matrix44.create_identity() result = matrix44.create_matrix33_view(mat) np.testing.assert_almost_equal(result, mat[:3, :3], decimal=5) mat[0, 0] = 2. np.testing.assert_almost_equal(result, mat[:3, :3], decimal=5)
def test_operators_number(self): m = Matrix44.identity() fv = np.empty((1, ), dtype=[('i', np.int16, 1), ('f', np.float32, 1)]) fv[0] = (2, 2.0) # add self.assertTrue( np.array_equal(m + 1.0, matrix44.create_identity()[:] + 1.0)) self.assertTrue( np.array_equal(m + 1, matrix44.create_identity()[:] + 1.0)) self.assertTrue( np.array_equal(m + np.float(1.), matrix44.create_identity()[:] + 1.0)) self.assertTrue( np.array_equal(m + fv[0]['f'], matrix44.create_identity()[:] + 2.0)) self.assertTrue( np.array_equal(m + fv[0]['i'], matrix44.create_identity()[:] + 2.0)) # subtract self.assertTrue( np.array_equal(m - 1.0, matrix44.create_identity()[:] - 1.0)) self.assertTrue( np.array_equal(m - 1, matrix44.create_identity()[:] - 1.0)) self.assertTrue( np.array_equal(m - np.float(1.), matrix44.create_identity()[:] - 1.0)) self.assertTrue( np.array_equal(m - fv[0]['f'], matrix44.create_identity()[:] - 2.0)) self.assertTrue( np.array_equal(m - fv[0]['i'], matrix44.create_identity()[:] - 2.0)) # multiply self.assertTrue( np.array_equal(m * 2.0, matrix44.create_identity()[:] * 2.0)) self.assertTrue( np.array_equal(m * 2, matrix44.create_identity()[:] * 2.0)) self.assertTrue( np.array_equal(m * np.float(2.), matrix44.create_identity()[:] * 2.0)) self.assertTrue( np.array_equal(m * fv[0]['f'], matrix44.create_identity()[:] * 2.0)) self.assertTrue( np.array_equal(m * fv[0]['i'], matrix44.create_identity()[:] * 2.0)) # divide self.assertTrue( np.array_equal(m / 2.0, matrix44.create_identity()[:] / 2.0)) self.assertTrue( np.array_equal(m / 2, matrix44.create_identity()[:] / 2.0)) self.assertTrue( np.array_equal(m / np.float(2.), matrix44.create_identity()[:] / 2.0)) self.assertTrue( np.array_equal(m / fv[0]['f'], matrix44.create_identity()[:] / 2.0)) self.assertTrue( np.array_equal(m / fv[0]['i'], matrix44.create_identity()[:] / 2.0))