This repository was archived by the owner on Aug 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviewport_experimental.py
More file actions
79 lines (72 loc) · 3.18 KB
/
Copy pathviewport_experimental.py
File metadata and controls
79 lines (72 loc) · 3.18 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"""
module containing experimental features relating to extending viewports
"""
from pygletExample import *
class VDKViewPort3D(VDKViewPort):
"""
Viewport quad with 3D faces, used for constructing ViewPrisms
"""
def __init__(self, width, height, centreX, centreY, parent, horizontalDirection = [1,0,0], verticalDirection = [0,1,0]):
self._width = width
self._height = height
self._centre = [centreX, centreY, 0]
self.parent = parent
self.vec1 = horizontalDirection
self.vec2 = verticalDirection
#self.vec1 = [0.707, -0.707,0.01]
#self.vec2 = [0.707, 0.707,0.01]
super(VDKViewPort3D, self).__init__(width, height, centreX, centreY, parent)
def orient(self, centre, vec1, vec2):
#position the plane such that it is parallel to vectors 1 and 2 and centred at centre:
# these are the vertices at the corners of the quad, each line is the pixel coordinates of the
self._vertex_list.vertices = \
[
# bottom left
centre[0] - vec1[0] * self._width / 2 - vec2[0] * self._height / 2,
centre[1] - vec1[1] * self._width / 2 - vec2[1] * self._height / 2,
centre[2] - vec1[2] * self._width / 2 - vec2[2] * self._height / 2,
# bottom right
centre[0] + vec1[0] * self._width / 2 - vec2[0] * self._height / 2,
centre[1] + vec1[1] * self._width / 2 - vec2[1] * self._height / 2,
centre[2] + vec1[2] * self._width / 2 - vec2[2] * self._height / 2,
#top right
centre[0] + vec1[0] * self._width/2 + vec2[0] * self._height/2,
centre[1] + vec1[1] * self._width / 2 + vec2[1] * self._height / 2,
centre[2] + vec1[2] * self._width / 2 + vec2[2] * self._height / 2,
# top left
centre[0] - vec1[0] * self._width / 2 + vec2[0] * self._height / 2,
centre[1] - vec1[1] * self._width / 2 + vec2[1] * self._height / 2,
centre[2] - vec1[2] * self._width / 2 + vec2[2] * self._height / 2,
]
#position the camera such that it is a fixed distance from the
import numpy as np
v1 = np.array(vec1)
v2 = np.array(vec2)
normal = np.cross(v1, v2)/(np.linalg.norm(v1)*np.linalg.norm(v2))
normal = normal.dot(np.array([
[1, 0, 0],
[0, 0, 1],
[0, 1, 0],
]))
self.camera.look_at([0, 0, 0], normal)
#self._camera.set_view(normal[0], normal[1], normal[2])
def make_vertex_list(self):
self._vertex_list = pyglet.graphics.vertex_list(4,'v3f/stream','t2f/static')
self._vertex_list.tex_coords = \
[
0, 1,
1, 1,
1, 0,
0, 0,
]
self.orient(self._centre, self.vec1, self.vec2)
class VDKViewPrism:
"""
Class representing a sectional view of a model
it is a rectangular prism with a UD view for each face
"""
def __init__(self, width, height, depth):
self.height = height
self.width = width
self.depth = depth
self.viewPorts = []