예제 #1
0
def test_show_entity():
    """Test showing an entity"""
    # Create a figure
    app = Application()
    fig = scene.CanvasWithScene(app=app)
    app.create()
    fig.size = 1, 1
    fig.show()
    camcontainer = scene.PixelCamera(fig.viewbox)
    camera = scene.ThreeDCamera(camcontainer)
    camera._fov = 90
    fig.viewbox.camera = camera
    pointscontainer = scene.Entity(fig.viewbox)
    scene.PointsEntity(pointscontainer, 1000)
    app.process_events()
    app.process_events()  # for good measure

    # Now do first-person
    camcontainer = scene.PixelCamera(fig.viewbox)
    camera = scene.FirstPersonCamera(camcontainer)
    camera.update_angles()
    fig.viewbox.camera = camera
    pointscontainer = scene.Entity(fig.viewbox)
    scene.PointsEntity(pointscontainer, 1000)
    app.process_events()
    app.process_events()  # for good measure

    # Now do 2D
    camcontainer = scene.PixelCamera(fig.viewbox)
    camera = scene.TwoDCamera(camcontainer)
    camera.xlim = -100, 500
    camera.ylim = -100, 500
    fig.viewbox.camera = camera
    pointscontainer = scene.Entity(fig.viewbox)
    scene.PointsEntity(pointscontainer, 1000)
    transforms.translate(camcontainer.transform, 50, 50)
    transforms.rotate(camcontainer.transform, 10, 0, 0, 1)
    app.process_events()
    app.process_events()  # for good measure

    fig.close()
    app.quit()
예제 #2
0
# Create a world object to act as a container
# It is a child of both viewports
world = scene.Entity()
world.parents = vp1, vp2

# Create two cameras
cam0 = scene.TwoDCamera(world)  # Placeholder camera
cam1 = scene.TwoDCamera(cam0)
cam2 = scene.TwoDCamera(cam0)

# Set limits of cam0, this is only to set position right, its fov is not used
cam0.xlim = -100, 500
cam0.ylim = -100, 500

# Set fov of cam1 and cam2, and translate both cameras a bit
cam1.fov = cam2.fov = 600, 600
transforms.translate(cam1.transform, -50, 0)
transforms.translate(cam2.transform, +50, 0)

# Apply cameras
vp1.camera = cam1
vp2.camera = cam2
vp1.bgcolor = (0, 0, 0.2)
vp2.bgcolor = (0, 0.2, 0)

# Create a entity
points = scene.PointsEntity(world)

app.run()
예제 #3
0
fig = scene.CanvasWithScene()
fig.size = 600, 600
fig.show()

# Create a camera inside a container
camcontainer = scene.PixelCamera(fig.viewbox)
camera = scene.ThreeDCamera(camcontainer)
camera._fov = 90  # or other between 0 and 179


# Explicitly set the second camera, or the ViewBox will pick the second
fig.viewbox.camera = camera

# Create a points entity inside a container
pointscontainer = scene.Entity(fig.viewbox)
points = scene.PointsEntity(pointscontainer, 1000)


# Count FPS
t0, frames, t = time.time(), 0, 0


@fig.connect
def on_paint(event):
    global t, t0, frames
    t = time.time()
    frames = frames + 1
    elapsed = (t - t0)  # seconds
    if elapsed > 2.5:
        print("FPS : %.2f (%d frames in %.2f second)"
              % (frames / elapsed, frames, elapsed))
@fig.connect
def on_mouse_move(event):
    cam0.on_mouse_move(event)


# Create two viewboxes
vp1 = scene.ViewBox(fig.viewbox)
vp2 = scene.ViewBox(fig.viewbox)
vp1.bgcolor = (0, 0, 0.2)
vp2.bgcolor = (0, 0.2, 0)

# Put them next to each-other
transforms.scale(vp1.transform, 400, 400)
transforms.scale(vp2.transform, 400, 400)
transforms.translate(vp1.transform, 0)
transforms.translate(vp2.transform, 400, 0, 0)

# Create one object in each scene
points1 = scene.PointsEntity(vp1, 100)
points2 = scene.PointsEntity(vp2, 1000)

# Create a camera
cam0 = scene.TwoDCamera()
cam0.parents = vp1, vp2

# Set limits of cam0, this is only to set position right, its fov is not used
cam0.xlim = -100, 500
cam0.ylim = -100, 500

app.run()
fig.show()

# Add a simple normal pixelcamera. This camera looks at the many
# subplots. Each subplot has its own world with a visual and a camera.
scene.PixelCamera(fig.viewbox)

for col in range(NCOLS):
    for row in range(NROWS):
        # Create "viewbox"
        box = scene.Entity(fig.viewbox)
        box.transform[-1, 0] = col * RES / NCOLS + 100 / NCOLS
        box.transform[-1, 1] = row * RES / NROWS + 100 / NROWS
        box.transform[0, 0] = 1 / NCOLS
        box.transform[1, 1] = 1 / NROWS
        # Create a points visual in the "viewbox"
        points = scene.PointsEntity(box, 100)

# Count FPS
t0, frames, t = time.time(), 0, 0


@fig.connect
def on_paint(event):
    global t, t0, frames
    t = time.time()
    frames = frames + 1
    elapsed = (t - t0)  # seconds
    if elapsed > 2.5:
        print("FPS : %.2f (%d frames in %.2f second)" %
              (frames / elapsed, frames, elapsed))
        t0, frames = t, 0