Exemplo n.º 1
0
 def __init__(self, prototype, azimuth, incl, speed, origin, distance, now):
     self.azimuth = azimuth
     self.incl = incl
     self.speed = speed
     eom = numpy.array(util.spher_to_cart(azimuth, incl, distance))
     self.motion = util.LinearMotion(origin, eom, speed, now)
     p = prototype
     self.bullet_model = pi3d.Shape(None, None, "bullet", p.unif[0],
                                    p.unif[1], p.unif[2], p.unif[3],
                                    p.unif[4], p.unif[5], p.unif[6],
                                    p.unif[7], p.unif[8], p.unif[9],
                                    p.unif[10], p.unif[11])
     self.bullet_model.buf = p.buf
     self.bullet_model.shader = p.shader
     self.bullet_model.textures = p.textures
     self.pos = origin
     self.direction = eom / numpy.linalg.norm(eom)
     self.destination = None
Exemplo n.º 2
0
def mesh_init(uv_steps, uv_offset, closed, lid):
    """Given number of U and V steps, generate boilerplate object with
       given texture coordinates and point indices. The initial vertex
       positions can be dummies (all 0,0,0) and will be reassigned later.
       If it's an eyelid, add an extra row with V=0.0."""
    # U steps might be determined by passing in a pointlist instead,
    # even though we're not using the coordinates yet, it'd provide some
    # consistency and avoid trouble later.
    verts = []
    tex = []
    idx = []
    norms = []
    if closed:
        uv_steps = (uv_steps[0] + 1, uv_steps[1])
    uv_div = (float(uv_steps[0] - 1), float(uv_steps[1] - 1))

    if lid: # Add extra row of vertices (with V=0) if eyelid
        for u_pos in range(uv_steps[0]):
            verts.append((0, 0, 0))
            tex.append((u_pos / uv_div[0] + uv_offset[0], uv_offset[1]))
            norms.append((0, 0, -1))
        v_range = uv_steps[1]
    else:
        v_range = uv_steps[1] - 1

    for v_pos in range(uv_steps[1]):
        v_pos_2 = (uv_offset[1] +
                   (v_pos / uv_div[1]) * (1.0 - uv_offset[1] * 2.0))
        for u_pos in range(uv_steps[0]):
            verts.append((0, 0, 0))
            tex.append((u_pos / uv_div[0] + uv_offset[0], v_pos_2))
            norms.append((0, 0, -1))

    for v_pos in range(v_range):
        for u_pos in range(uv_steps[0] - 1):
            pos = v_pos * uv_steps[0] + u_pos
            idx.append((pos + uv_steps[0], pos, pos + 1))
            idx.append((pos + 1, pos + uv_steps[0] + 1, pos + uv_steps[0]))

    shape = pi3d.Shape(None, None, "foo", 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
                       1.0, 1.0, 1.0, 0.0, 0.0, 0.0)
    shape.buf = [pi3d.Buffer(shape, verts, tex, idx, norms, False)]

    return shape
Exemplo n.º 3
0
 def __init__(self, camera):
     vertices = [((i % 60.0) / 3.0 - 10.0, int(i / 60.0) / 3.0 - 10.0,
                  random.gauss(0.0, 10.0)) for i in range(4320)]
     normals = None
     n_v = len(vertices)
     indices = [(a, a + 1, a + 2) for a in range(0, n_v, 3)]
     tex_coords = [(v[0] / 20.0 + 0.5, v[1] / 20.0 + 0.5) for v in vertices]
     points = pi3d.Shape(camera, None, '2', 0, 0, 160.0, 0, 0, 0, 1, 1, 1,
                         0, 0, 0)
     points.buf = [
         pi3d.Buffer(points,
                     vertices,
                     tex_coords,
                     indices,
                     normals,
                     smooth=False)
     ]
     super(SimplePoints, self).__init__(camera, points)
     self.geometry.set_point_size(50)
Exemplo n.º 4
0
def meshInit(uSteps, vSteps, closed, uOffset, vOffset, lid):
    verts = []
    tex = []
    idx = []
    norms = []
    if closed is True: uSteps += 1
    uDiv = float(uSteps - 1)
    vDiv = float(vSteps - 1)

    if lid is True:  # Add extra row of vertices (with V=0) if eyelid
        for u in range(uSteps):
            verts.append((0, 0, 0))
            tex.append((u / uDiv + uOffset, vOffset))
            norms.append((0, 0, -1))
        vRange = vSteps
    else:
        vRange = vSteps - 1

    for v in range(vSteps):
        v2 = vOffset + (v / vDiv) * (1.0 - vOffset * 2.0)
        for u in range(uSteps):
            verts.append((0, 0, 0))
            tex.append((u / uDiv + uOffset, v2))
            norms.append((0, 0, -1))

    for v in range(vRange):
        for u in range(uSteps - 1):
            s = v * uSteps + u
            idx.append((s + uSteps, s, s + 1))
            idx.append((s + 1, s + uSteps + 1, s + uSteps))

    shape = pi3d.Shape(None, None, "foo", 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0,
                       1.0, 1.0, 0.0, 0.0, 0.0)
    shape.buf = []
    shape.buf.append(pi3d.Buffer(shape, verts, tex, idx, norms, False))

    return shape
Exemplo n.º 5
0
xy = np.array([[[x, y] for x in range(IX)] for y in range(IZ)])
verts[:, :, 0] = xy[:, :, 0] * ws - wh
verts[:, :, 2] = xy[:, :, 1] * hs - hh
verts[:, :, 1] = perlin.generate(xy) * HT  # y value perlin noise height
verts.shape = (IZ * IX, 3)  # pi3d uses semi-flattened arrays

s = 0
#create one long triangle_strip by alternating X directions
for z in range(0, IZ - 1):
    for x in range(0, IX - 1):
        i = (z * IX) + x
        idx.append([i, i + IX, i + IX + 1])
        idx.append([i + IX + 1, i + 1, i])
        s += 2

terrain = pi3d.Shape(None, None, "terrain", 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0,
                     1.0, 1.0, 0.0, 0.0, 0.0)
terrain.buf = []
terrain.buf.append(pi3d.Buffer(terrain, verts, tex_coords, idx, None, True))
terrain.set_material((0.2, 0.3, 0.5))
terrain.set_shader(shader)

axes = pi3d.Lines(vertices=[[2.0 * W, 0.0, 0.0], [0.0, 0.0, 0.0],
                            [0.0, 2.0 * HT, 0.0], [0.0, 0.0, 0.0],
                            [0.0, 0.0, 2.0 * D]],
                  line_width=3,
                  x=-W / 2.0,
                  z=-D / 2.0)
axes.set_shader(flatsh)

mouserot = 0.0  # rotation of camera
tilt = 15.0  # tilt of camera
Exemplo n.º 6
0
# Load shapes
mysphere = pi3d.Sphere(radius=2,
                       slices=24,
                       sides=24,
                       name="earth",
                       x=10,
                       y=-5,
                       z=180)
mysphere.set_draw_details(shader, [earthimg])
myplane = pi3d.Plane(w=500, h=500, name="stars", z=400)
myplane.set_draw_details(flatsh, [starsimg])
"""create the shape to hold the points. This could be encapsulated in its
own class to generate the required distribution and shield the user from
having to explicitly create the Buffer object and set the Shape.buf list
"""
mystars = pi3d.Shape(None, None, "stars", 0, 0, 250, 0, 0, 0, 100, 100, 500, 0,
                     0, 0)
verts, norms, texc, faces = [], [], [], []
for i in xrange(30000):
    verts.append(
        (random.random() - 0.5, random.random() - 0.5, random.random() - 0.5))
    norms.append((0, 0, 0))
    texc.append((0, 0))
for i in xrange(10000):
    faces.append((i * 3, i * 3 + 1, i * 3 + 2))
mystars.buf = [pi3d.Buffer(mystars, verts, texc, faces, norms)]
mystars.set_point_size(50)
mystars.set_material((0.9, 0.9, 1.0))
mystars.set_shader(matsh)

# Fetch key presses
mykeys = pi3d.Keyboard()