summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2011-09-18 11:26:35 -0400
committerTavian Barnes <tavianator@gmail.com>2011-09-18 11:26:35 -0400
commitca6ed9f1a186c79a17d03050d737b29f6f0edc94 (patch)
treeafc6d4708457e8b2daa6568c01e50a27df8ce947
parent5e13aa2d3c8a0ed11b061641eb0f6bc8b81a6f4c (diff)
downloaddimension-ca6ed9f1a186c79a17d03050d737b29f6f0edc94.tar.xz
Add .scale(), .translate(), and .rotate() methods to transformable objects.
-rw-r--r--dimension/tests/demo.dmnsn22
-rw-r--r--libdimension-python/dimension.pyx20
2 files changed, 23 insertions, 19 deletions
diff --git a/dimension/tests/demo.dmnsn b/dimension/tests/demo.dmnsn
index fbf51da..331c2b4 100644
--- a/dimension/tests/demo.dmnsn
+++ b/dimension/tests/demo.dmnsn
@@ -20,7 +20,7 @@
# Camera
camera = PerspectiveCamera(location = (0, 0.25, -4),
look_at = 0)
-camera.transform(rotate(53*Y))
+camera.rotate(53*Y)
# Background
background = PigmentMap(
@@ -51,7 +51,7 @@ hollow_cube = Difference(
ior = 1.1,
),
)
- .transform(rotate(45*X)),
+ .rotate(45*X),
Sphere(
center = 0, radius = 1.25,
@@ -84,19 +84,15 @@ arrow = Union(
6/6: Red,
},
)
- .transform(scale(1, 2.75, 1))
- .transform(translate(-1.25*Y)),
+ .scale(1, 2.75, 1)
+ .translate(-1.25*Y),
)
torii = Union(
[
- Torus(major_radius = 0.15, minor_radius = 0.05)
- .transform(translate(-Y)),
-
+ Torus(major_radius = 0.15, minor_radius = 0.05).translate(-Y),
Torus(major_radius = 0.15, minor_radius = 0.05),
-
- Torus(major_radius = 0.15, minor_radius = 0.05)
- .transform(translate(Y)),
+ Torus(major_radius = 0.15, minor_radius = 0.05).translate(Y),
],
texture = Texture(
pigment = Blue,
@@ -104,7 +100,7 @@ torii = Union(
),
)
-spike = Union([arrow, torii]).transform(rotate(-45*X))
+spike = Union([arrow, torii]).rotate(-45*X)
strip_textures = [
Texture(pigment = Red),
@@ -122,7 +118,7 @@ for i in range(128):
b = c
c = a + Z
-strip = Union(strip_triangles).transform(translate(5, -2, -4))
+strip = Union(strip_triangles).translate(5, -2, -4)
ground = Plane(
normal = Y, distance = -2,
@@ -131,7 +127,7 @@ ground = Plane(
Checker(),
[
White,
- PigmentMap(Checker(), [Black, White]).transform(scale(1/3))
+ PigmentMap(Checker(), [Black, White]).scale(1/3)
],
),
)
diff --git a/libdimension-python/dimension.pyx b/libdimension-python/dimension.pyx
index 60daf43..601fb69 100644
--- a/libdimension-python/dimension.pyx
+++ b/libdimension-python/dimension.pyx
@@ -347,6 +347,14 @@ def rotate(*args, **kwargs):
cdef Vector rad = dmnsn_radians(1.0)*Vector(*args, **kwargs)
return _Matrix(dmnsn_rotation_matrix(rad._v))
+cdef class _Transformable:
+ def scale(self, *args, **kwargs):
+ return self.transform(scale(*args, **kwargs))
+ def translate(self, *args, **kwargs):
+ return self.transform(translate(*args, **kwargs))
+ def rotate(self, *args, **kwargs):
+ return self.transform(rotate(*args, **kwargs))
+
##########
# Colors #
##########
@@ -617,7 +625,7 @@ cdef class Leopard(Pattern):
# Pigments #
############
-cdef class Pigment:
+cdef class Pigment(_Transformable):
"""Object surface coloring."""
cdef dmnsn_pigment *_pigment
@@ -788,7 +796,7 @@ cdef class Reflection(Finish):
# Textures #
############
-cdef class Texture:
+cdef class Texture(_Transformable):
"""Object surface properties."""
cdef dmnsn_texture *_texture
@@ -888,7 +896,7 @@ cdef Interior _Interior(dmnsn_interior *interior):
# Objects #
###########
-cdef class Object:
+cdef class Object(_Transformable):
"""Physical objects."""
cdef dmnsn_object *_object
@@ -1247,7 +1255,7 @@ cdef class PointLight(Light):
# Cameras #
###########
-cdef class Camera:
+cdef class Camera(_Transformable):
"""A camera."""
cdef dmnsn_camera *_camera
@@ -1283,7 +1291,7 @@ cdef class PerspectiveCamera(Camera):
Camera.__init__(self)
# Apply the field of view angle
- self.transform(scale(tan(dmnsn_radians(angle))*(X + Y) + Z))
+ self.scale(tan(dmnsn_radians(angle))*(X + Y) + Z)
cdef Vector dir = Vector(look_at) - Vector(location)
cdef Vector vsky = Vector(sky)
@@ -1299,7 +1307,7 @@ cdef class PerspectiveCamera(Camera):
vsky._v, right._v)))
# Move the camera into position
- self.transform(translate(Vector(location)))
+ self.translate(Vector(location))
##########
# Scenes #