diff options
author | Tavian Barnes <tavianator@gmail.com> | 2011-07-13 13:47:17 -0600 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2011-07-13 13:47:17 -0600 |
commit | 3ec26ddd28cbcc279a4fa65de8d68c68b3950576 (patch) | |
tree | eddc68447868b1c0dd9c7f357527a9e8c7670ff9 /libdimension-python | |
parent | f034b0cba4c028b4b156f7d8824b6ccf84f1f277 (diff) | |
download | dimension-3ec26ddd28cbcc279a4fa65de8d68c68b3950576.tar.xz |
Implement triangles.
Diffstat (limited to 'libdimension-python')
-rw-r--r-- | libdimension-python/dimension.pxd | 3 | ||||
-rw-r--r-- | libdimension-python/dimension.pyx | 14 | ||||
-rwxr-xr-x | libdimension-python/tests/demo.py | 20 |
3 files changed, 37 insertions, 0 deletions
diff --git a/libdimension-python/dimension.pxd b/libdimension-python/dimension.pxd index 6ac6319..f675501 100644 --- a/libdimension-python/dimension.pxd +++ b/libdimension-python/dimension.pxd @@ -307,6 +307,9 @@ cdef extern from "../libdimension/dimension.h": dmnsn_object *dmnsn_new_object() void dmnsn_delete_object(dmnsn_object *object) + dmnsn_object *dmnsn_new_triangle(dmnsn_vector a, + dmnsn_vector b, + dmnsn_vector c) dmnsn_object *dmnsn_new_plane(dmnsn_vector normal) dmnsn_object *dmnsn_new_sphere() dmnsn_object *dmnsn_new_cube() diff --git a/libdimension-python/dimension.pyx b/libdimension-python/dimension.pyx index 8c25538..addba7e 100644 --- a/libdimension-python/dimension.pyx +++ b/libdimension-python/dimension.pyx @@ -939,6 +939,20 @@ cdef class Object: self._object.texture.trans = dmnsn_matrix_mul(self._object.texture.trans, trans.inverse()._m) +cdef class Triangle(Object): + """A triangle.""" + def __init__(self, a, b, c, *args, **kwargs): + """ + Create a Triangle. + + Keyword arguments: + a, b, c -- the corners of the triangle + + Additionally, Triangle() accepts any arguments that Object() accepts. + """ + self._object = dmnsn_new_triangle(Vector(a)._v, Vector(b)._v, Vector(c)._v) + Object.__init__(self, *args, **kwargs) + cdef class Plane(Object): """A plane.""" def __init__(self, normal, double distance, *args, **kwargs): diff --git a/libdimension-python/tests/demo.py b/libdimension-python/tests/demo.py index 96ef22c..e4e1e14 100755 --- a/libdimension-python/tests/demo.py +++ b/libdimension-python/tests/demo.py @@ -19,6 +19,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # ######################################################################### +from math import * from dimension import * # Treat warnings as errors for tests @@ -116,6 +117,24 @@ torii = Union( spike = Union([arrow, torii]).transform(rotate(-45*X)) +strip_textures = [ + Texture(pigment = Red), + Texture(pigment = Orange), + Texture(pigment = Yellow), +] +strip_triangles = [] + +a = 0 +b = Vector(0, sqrt(3)/2, 0.5) +c = Z +for i in range(128): + strip_triangles.append(Triangle(a, b, c, texture = strip_textures[i%3])) + a = b + b = c + c = a + Z + +strip = Union(strip_triangles).transform(translate(5, -2, -4)) + ground = Plane( normal = Y, distance = -2, @@ -131,6 +150,7 @@ ground = Plane( objects = [ hollow_cube, spike, + strip, ground, ] |