Skip to content

Commit dc0a77e

Browse files
committed
Allow setting cube center point
1 parent cd86b91 commit dc0a77e

File tree

2 files changed

+41
-40
lines changed

2 files changed

+41
-40
lines changed

demosys/geometry/cube.py

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,56 +3,57 @@
33
from demosys.opengl import VAO
44

55

6-
def cube(width, height, depth, normals=True, uvs=True):
6+
def cube(width, height, depth, center=(0.0, 0.0, 0.0), normals=True, uvs=True) -> VAO:
77
"""
8-
Generates a cube VAO
8+
Generates a cube VAO. The cube center is (0.0, 0.0 0.0) unless other is specified.
99
1010
:param width: Width of the cube
1111
:param height: height of the cube
1212
:param depth: depth of the cube
13+
:param center: center of the cube
1314
:param normals: (bool) Include normals
1415
:param uvs: (bool) include uv coordinates
1516
:return: VAO representing the cube
1617
"""
1718
width, height, depth = width / 2.0, height / 2.0, depth / 2.0
18-
19+
1920
pos = numpy.array([
20-
width, -height, depth,
21-
width, height, depth,
22-
-width, -height, depth,
23-
width, height, depth,
24-
-width, height, depth,
25-
-width, -height, depth,
26-
width, -height, -depth,
27-
width, height, -depth,
28-
width, -height, depth,
29-
width, height, -depth,
30-
width, height, depth,
31-
width, -height, depth,
32-
width, -height, -depth,
33-
width, -height, depth,
34-
-width, -height, depth,
35-
width, -height, -depth,
36-
-width, -height, depth,
37-
-width, -height, -depth,
38-
-width, -height, depth,
39-
-width, height, depth,
40-
-width, height, -depth,
41-
-width, -height, depth,
42-
-width, height, -depth,
43-
-width, -height, -depth,
44-
width, height, -depth,
45-
width, -height, -depth,
46-
-width, -height, -depth,
47-
width, height, -depth,
48-
-width, -height, -depth,
49-
-width, height, -depth,
50-
width, height, -depth,
51-
-width, height, -depth,
52-
width, height, depth,
53-
-width, height, -depth,
54-
-width, height, depth,
55-
width, height, depth,
21+
center[0] + width, center[1] - height, center[2] + depth,
22+
center[0] + width, center[1] + height, center[2] + depth,
23+
center[0] - width, center[1] - height, center[2] + depth,
24+
center[0] + width, center[1] + height, center[2] + depth,
25+
center[0] - width, center[1] + height, center[2] + depth,
26+
center[0] - width, center[1] - height, center[2] + depth,
27+
center[0] + width, center[1] - height, center[2] - depth,
28+
center[0] + width, center[1] + height, center[2] - depth,
29+
center[0] + width, center[1] - height, center[2] + depth,
30+
center[0] + width, center[1] + height, center[2] - depth,
31+
center[0] + width, center[1] + height, center[2] + depth,
32+
center[0] + width, center[1] - height, center[2] + depth,
33+
center[0] + width, center[1] - height, center[2] - depth,
34+
center[0] + width, center[1] - height, center[2] + depth,
35+
center[0] - width, center[1] - height, center[2] + depth,
36+
center[0] + width, center[1] - height, center[2] - depth,
37+
center[0] - width, center[1] - height, center[2] + depth,
38+
center[0] - width, center[1] - height, center[2] - depth,
39+
center[0] - width, center[1] - height, center[2] + depth,
40+
center[0] - width, center[1] + height, center[2] + depth,
41+
center[0] - width, center[1] + height, center[2] - depth,
42+
center[0] - width, center[1] - height, center[2] + depth,
43+
center[0] - width, center[1] + height, center[2] - depth,
44+
center[0] - width, center[1] - height, center[2] - depth,
45+
center[0] + width, center[1] + height, center[2] - depth,
46+
center[0] + width, center[1] - height, center[2] - depth,
47+
center[0] - width, center[1] - height, center[2] - depth,
48+
center[0] + width, center[1] + height, center[2] - depth,
49+
center[0] - width, center[1] - height, center[2] - depth,
50+
center[0] - width, center[1] + height, center[2] - depth,
51+
center[0] + width, center[1] + height, center[2] - depth,
52+
center[0] - width, center[1] + height, center[2] - depth,
53+
center[0] + width, center[1] + height, center[2] + depth,
54+
center[0] - width, center[1] + height, center[2] - depth,
55+
center[0] - width, center[1] + height, center[2] + depth,
56+
center[0] + width, center[1] + height, center[2] + depth,
5657
], dtype=numpy.float32)
5758

5859
if normals:

docs/source/reference/geometry.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Functions
1212

1313
.. autofunction:: quad_fs() -> VAO
1414
.. autofunction:: quad_2d(width, height, xpos=0.0, ypos=0.0) -> VAO
15-
.. autofunction:: cube(width, height, depth, normals=True, uvs=True) -> VAO
15+
.. autofunction:: cube(width, height, depth, center=(0.0, 0.0, 0.0), normals=True, uvs=True) -> VAO
1616
.. autofunction:: bbox(width=1.0, height=1.0, depth=1.0) -> VAO
1717
.. autofunction:: plane_xz(size=(10, 10), resolution=(10, 10)) -> VAO
1818
.. autofunction:: points_random_3d(count, range_x=(-10.0, 10.0), range_y=(-10.0, 10.0), range_z=(-10.0, 10.0), seed=None) -> VAO

0 commit comments

Comments
 (0)