[1231] | 1 | from visual import * |
---|
| 2 | # Example of use of faces object for building arbitrary shapes (here, a cone) |
---|
| 3 | # David Scherer July 2001 |
---|
| 4 | |
---|
| 5 | f = frame() |
---|
| 6 | |
---|
| 7 | box( size=(0.5,0.5,0.5) ) |
---|
| 8 | |
---|
| 9 | # Make a cone (smooth shading, no bottom, normals are not quite physical) |
---|
| 10 | |
---|
| 11 | N = 20 |
---|
| 12 | |
---|
| 13 | model = faces( pos = zeros( (N*3,3), Float ), frame = f ) |
---|
| 14 | |
---|
| 15 | t = arange(0,2*pi+2*pi/N,2*pi/N) |
---|
| 16 | |
---|
| 17 | # Vertex 0 of triangles |
---|
| 18 | model.pos[0::3, 0] = sin(t[:-1]) |
---|
| 19 | model.pos[0::3, 2] = cos(t[:-1]) |
---|
| 20 | |
---|
| 21 | # Vertex 1 of triangles |
---|
| 22 | model.pos[1::3, 0] = sin(t[1:]) |
---|
| 23 | model.pos[1::3, 2] = cos(t[1:]) |
---|
| 24 | |
---|
| 25 | # Vertex 2 of triangles (point of cone) |
---|
| 26 | model.pos[2::3, 1] = 2 |
---|
| 27 | |
---|
| 28 | # All normals point outward in XZ... not quite right, but there is already a cone primitive :) |
---|
| 29 | model.normal = model.pos |
---|
| 30 | model.normal[2::3,0] = sin((t[:-1]+t[1:])/2) |
---|
| 31 | model.normal[2::3,1] = 0 |
---|
| 32 | model.normal[2::3,2] = cos((t[:-1]+t[1:])/2) |
---|
| 33 | |
---|
| 34 | model.color = model.pos/2 + (0.5,0,0.5) |
---|
| 35 | |
---|
| 36 | model.color[0::3] = (1,1,1) # show where the triangles are |
---|
| 37 | |
---|
| 38 | while 1: |
---|
| 39 | rate(100) |
---|
| 40 | f.rotate(angle=0.01) |
---|