diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2014-06-07 15:43:19 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2014-06-07 15:44:11 -0400 |
commit | 6c95702123269a674f0ffa0b57ec756bc611c643 (patch) | |
tree | 271a4a4e7e3912899bb31d62764f3d2fb9975729 /libdimension-python | |
parent | a79085ab984979dbf4f78545f7592c8b47e4a794 (diff) | |
download | dimension-6c95702123269a674f0ffa0b57ec756bc611c643.tar.xz |
objects: Implement triangle fans.
Diffstat (limited to 'libdimension-python')
-rw-r--r-- | libdimension-python/dimension.pxd | 10 | ||||
-rw-r--r-- | libdimension-python/dimension.pyx | 27 |
2 files changed, 37 insertions, 0 deletions
diff --git a/libdimension-python/dimension.pxd b/libdimension-python/dimension.pxd index a7b8a53..0c62df6 100644 --- a/libdimension-python/dimension.pxd +++ b/libdimension-python/dimension.pxd @@ -37,6 +37,15 @@ cdef extern from "../libdimension/dimension.h": double dmnsn_epsilon + ########## + # Malloc # + ########## + + void *dmnsn_malloc(size_t size) + void *dmnsn_realloc(void *ptr, size_t size) + char *dmnsn_strdup(const char *s) + void dmnsn_free(void *ptr) + ######### # Pools # ######### @@ -321,6 +330,7 @@ cdef extern from "../libdimension/dimension.h": dmnsn_object *dmnsn_new_triangle(dmnsn_pool *pool, dmnsn_vector vertices[3]) dmnsn_object *dmnsn_new_smooth_triangle(dmnsn_pool *pool, dmnsn_vector vertices[3], dmnsn_vector normals[3]) + dmnsn_object *dmnsn_new_triangle_fan(dmnsn_pool *pool, dmnsn_vector *vertices, size_t nvertices) dmnsn_object *dmnsn_new_plane(dmnsn_pool *pool, dmnsn_vector normal) dmnsn_object *dmnsn_new_sphere(dmnsn_pool *pool) dmnsn_object *dmnsn_new_cube(dmnsn_pool *pool) diff --git a/libdimension-python/dimension.pyx b/libdimension-python/dimension.pyx index 0c4d665..1ad6d0b 100644 --- a/libdimension-python/dimension.pyx +++ b/libdimension-python/dimension.pyx @@ -1143,6 +1143,33 @@ cdef class Triangle(Object): self._object = dmnsn_new_smooth_triangle(_get_pool(), vertices, normals) Object.__init__(self, *args, **kwargs) +cdef class TriangleFan(Object): + """A triangle.""" + def __init__(self, vertices, *args, **kwargs): + """ + Create a TriangleFan. + + Keyword arguments: + vertices -- the vertices of the fan, starting in the center + + Additionally, TriangleFan() accepts any arguments that Object() accepts. + """ + cdef size_t nvertices = len(vertices) + if nvertices < 3: + raise TypeError("expected at least 3 vertices") + + cdef dmnsn_vector *varray + try: + varray = <dmnsn_vector *>dmnsn_malloc(nvertices*sizeof(dmnsn_vector)) + for i in range(nvertices): + varray[i] = Vector(vertices[i])._v + + self._object = dmnsn_new_triangle_fan(_get_pool(), varray, nvertices) + finally: + dmnsn_free(varray) + + Object.__init__(self, *args, **kwargs) + cdef class Plane(Object): """A plane.""" def __init__(self, normal, double distance, *args, **kwargs): |