forked from mcedit/mcedit
-
Notifications
You must be signed in to change notification settings - Fork 1
/
compass.py
61 lines (45 loc) · 1.74 KB
/
compass.py
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
"""
compass
"""
from __future__ import absolute_import, division, print_function, unicode_literals
import logging
from OpenGL import GL
from drawable import Drawable
from glutils import gl
from mceutils import loadPNGTexture
log = logging.getLogger(__name__)
def makeQuad(minx, miny, width, height):
return [minx, miny, minx+width, miny, minx+width, miny+height, minx, miny + height]
class CompassOverlay(Drawable):
_tex = None
_yawPitch = (0., 0.)
def __init__(self, small=False):
super(CompassOverlay, self).__init__()
self.small = small
@property
def yawPitch(self):
return self._yawPitch
@yawPitch.setter
def yawPitch(self, value):
self._yawPitch = value
self.invalidate()
def drawSelf(self):
if self._tex is None:
if self.small:
filename = "compass_small.png"
else:
filename = "compass.png"
self._tex = loadPNGTexture("toolicons/" + filename)#, minFilter=GL.GL_LINEAR, magFilter=GL.GL_LINEAR)
self._tex.bind()
size = 0.075
with gl.glPushMatrix(GL.GL_MODELVIEW):
GL.glLoadIdentity()
yaw, pitch = self.yawPitch
GL.glTranslatef(1.-size, size, 0.0) # position on upper right corner
GL.glRotatef(180-yaw, 0., 0., 1.) # adjust to north
GL.glColor3f(1., 1., 1.)
with gl.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY):
GL.glVertexPointer(2, GL.GL_FLOAT, 0, makeQuad(-size, -size, 2*size, 2*size))
GL.glTexCoordPointer(2, GL.GL_FLOAT, 0, makeQuad(0, 0, 256, 256))
with gl.glEnable(GL.GL_BLEND, GL.GL_TEXTURE_2D):
GL.glDrawArrays(GL.GL_QUADS, 0, 4)