World State Manipulation

World State Manipulation#

This exercise shows how to manipulate the state of an active connection.

You will:

  • Create a world with a prismatic connection

  • Update the connection position via its convenience property

0. Setup#

1. Create and move a prismatic connection#

Your goal:

  • Create a World with two bodies named root and slider

  • Add a small red box shape to root, and a small green box shape to slider for visibility

  • Add a PrismaticConnection along the X axis from root to slider

  • Keep a reference to this connection in a variable named root_C_slider

  • Set root_C_slider.position = 0.2

world = World()
red_box = ShapeCollection([Box(
    scale=Scale(0.1, 0.1, 0.1),
    color=Color(1.0, 0.0, 0.0),
)])
green_box = ShapeCollection([Box(
    scale=Scale(0.1, 0.1, 0.1),
    color=Color(0.0, 1.0, 0.0),
)])
root = Body(name=PrefixedName("root"), visual=red_box, collision=red_box)
slider = Body(name=PrefixedName("slider"), visual=green_box, collision=green_box)
root_C_slider: PrismaticConnection = PrismaticConnection(
    parent=root,
    child=slider,
    axis=Vector3.X(reference_frame=root),
)
with world.modify_world():
    world.add_connection(root_C_slider)
rt = RayTracer(world); rt.update_scene(); rt.scene.show("jupyter")
root_C_slider.position = 0.2