|
3 | 3 | from demosys.opengl import VAO |
4 | 4 |
|
5 | 5 |
|
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: |
7 | 7 | """ |
8 | | - Generates a cube VAO |
| 8 | + Generates a cube VAO. The cube center is (0.0, 0.0 0.0) unless other is specified. |
9 | 9 |
|
10 | 10 | :param width: Width of the cube |
11 | 11 | :param height: height of the cube |
12 | 12 | :param depth: depth of the cube |
| 13 | + :param center: center of the cube |
13 | 14 | :param normals: (bool) Include normals |
14 | 15 | :param uvs: (bool) include uv coordinates |
15 | 16 | :return: VAO representing the cube |
16 | 17 | """ |
17 | 18 | width, height, depth = width / 2.0, height / 2.0, depth / 2.0 |
18 | | - |
| 19 | + |
19 | 20 | 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, |
56 | 57 | ], dtype=numpy.float32) |
57 | 58 |
|
58 | 59 | if normals: |
|
0 commit comments