from libs import * class Entity: def __init__(self, verts, col, pos, mode=GL_TRIANGLE_STRIP): self.verts = vec(verts) self.col = vec(col) self.pos = vec(pos) self.draw_mode = mode self.orient = np.identity(4, dtype=FLOAT) self.vao = None self.onclick = lambda s, b: print(f"clicked {s} with button {b}") def build_vao(self): self.vao = glGenVertexArrays(1) glBindVertexArray(self.vao) vbo = glGenBuffers(1) glBindBuffer(GL_ARRAY_BUFFER, vbo) glBufferData(GL_ARRAY_BUFFER, self.verts.nbytes, self.verts, GL_STATIC_DRAW) glEnableVertexAttribArray(0) glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, None) def translate(self): m = np.identity(4, dtype=FLOAT) m[:3, 3] = self.pos return m def rotate(self, theta, axis): x, y, z = axis c, s = np.cos(theta), np.sin(theta) t = 1 - c self.orient = vec([ [t*x*x + c, t*x*y - s*z, t*x*z + s*y, 0], [t*x*y + s*z, t*y*y + c, t*y*z - s*x, 0], [t*x*z - s*y, t*y*z + s*x, t*z*z + c, 0], [0, 0, 0, 1] ]) @ self.orient def click(self, button): self.onclick(self, button)