-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels2D.py
More file actions
56 lines (49 loc) · 2.24 KB
/
models2D.py
File metadata and controls
56 lines (49 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from BaseModel import BaseModel
from OpenGL.GL import *
from matutils import *
class TriangleModel(BaseModel):
'''
A very simple model for drawing a single triangle. This is only for illustration purpose.
'''
def __init__(self, scene, M, color=[1., 1., 1.]):
BaseModel.__init__(self, scene, M=M, color=color)
# each row encodes the coordinate for one vertex.
# given that we are drawing in 2D, the last coordinate is always zero.
self.vertices = np.array(
[
[0.0, 0.0, 0.0],
[0.0, 1.0, 0.0],
[1.0, 0.0, 0.0]
], 'f')
self.bind()
class ComplexModel(BaseModel):
def __init__(self, scene, M):
BaseModel.__init__(self, scene, M=M)
self.components = []
def draw(self, Mp):
# draw all component primitives
for component in self.components:
component.draw(np.matmul(Mp, self.M))
class SquareModel(BaseModel):
def __init__(self, scene, M, color=[1., 1., 1.]):
BaseModel.__init__(self, scene, M=M, color=color, primitive=GL_QUADS)
self.vertices = np.array([
[0., 0., 0.],
[1., 0., 0.],
[1., 1., 0.],
[0., 1., 0.]
], 'f')
self.bind()
class TreeModel(ComplexModel):
def __init__(self, scene, M ):
ComplexModel.__init__(self, scene=scene, M=M)
# list of simple components
self.components = [
SquareModel(scene, M=poseMatrix(position=[-0.125, 0., 0], scale=[0.25,0.5,1.], orientation=0.), color=[0.6, 0.2, 0.2]),
TriangleModel(scene, M=poseMatrix(position=[0, 0.5, 0], scale=[0.25,0.5,1]), color=[0., 1., 0.]),
TriangleModel(scene, M=poseMatrix(position=[0, 0.5, 0], scale=[-0.25,0.5,1]), color=[0., 1., 0.]),
TriangleModel(scene, M=poseMatrix(position=[0, 0.75, 0], scale=[0.25, 0.5, 1]), color=[0., 1., 0.]),
TriangleModel(scene, M=poseMatrix(position=[0, 0.75, 0], scale=[-0.25, 0.5, 1]), color=[0., 1., 0.]),
TriangleModel(scene, M=poseMatrix(position=[0, 1.0, 0], scale=[0.25, 0.5, 1]), color=[0., 1., 0.]),
TriangleModel(scene, M=poseMatrix(position=[0, 1.0, 0], scale=[-0.25, 0.5, 1]), color=[0., 1., 0.]),
]