-
-
Notifications
You must be signed in to change notification settings - Fork 179
Expand file tree
/
Copy pathtranslate.py
More file actions
67 lines (47 loc) · 1.74 KB
/
translate.py
File metadata and controls
67 lines (47 loc) · 1.74 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
# -----------------------------------------------------------------------------
# Copyright (c) 2009-2016 Nicolas P. Rougier. All rights reserved.
# Distributed under the (new) BSD License.
# -----------------------------------------------------------------------------
from glumpy import library
from glumpy.transforms.transform import Transform
import numpy as np
class Translate(Transform):
"""
Translation transform
:param 3-tuple translate:
Translation vector. Default is (0,0,0).
The transform is connected to the following events:
* ``on_attach``: Transform initialization
**Usage example**:
.. code:: python
vertex = '''
attribute vec2 position;
void main()
{
gl_Position = <transform>;
} '''
...
window = app.Window(width=800, height=800)
program = gloo.Program(vertex, fragment, count=4)
...
program['transform'] = Translate("position", translate=(0,0,0))
window.attach(program['transform'])
...
"""
aliases = { "translate" : "translate_translate" }
def __init__(self, *args, **kwargs):
code = library.get("transforms/translate.glsl")
Transform.__init__(self, code, *args, **kwargs)
self.translate = Transform._get_kwarg("translate", kwargs) or (0,0,0)
@property
def translate(self):
""" Translate vector """
return self._translate
@translate.setter
def translate(self, value):
""" Translate vector """
self._translate = np.asarray(value,dtype=np.float32)
if self.is_attached:
self["translate"] = self._translate
def on_attach(self, program):
self["translate"] = self._translate