| 1 |
import numpy as np |
| 2 |
import dartpy as dart |
| 3 |
|
| 4 |
|
| 5 |
def main(): |
| 6 |
world = dart.simulation.World() |
| 7 |
|
| 8 |
tf = dart.math.Isometry3() |
| 9 |
|
| 10 |
tf.set_translation([4, -4, 0]) |
| 11 |
frame = dart.gui.osg.InteractiveFrame( |
| 12 |
dart.dynamics.Frame.World(), 'interactive frame', tf, 2) |
| 13 |
world.addSimpleFrame(frame) |
| 14 |
|
| 15 |
tf.set_translation([-4, 4, 0]) |
| 16 |
draggable = dart.dynamics.SimpleFrame(frame, 'draggable', tf) |
| 17 |
draggable.setShape(dart.dynamics.BoxShape([1, 1, 1])) |
| 18 |
draggable.getVisualAspect(True).setColor([0.9, 0, 0]) |
| 19 |
world.addSimpleFrame(draggable) |
| 20 |
|
| 21 |
tf.set_translation([8, 0, 0]) |
| 22 |
x_marker = dart.dynamics.SimpleFrame(dart.dynamics.Frame.World(), 'X', tf) |
| 23 |
x_shape = dart.dynamics.BoxShape([0.2, 0.2, 0.2]) |
| 24 |
x_marker.setShape(x_shape) |
| 25 |
x_marker.getVisualAspect(True).setColor([0.9, 0, 0]) |
| 26 |
world.addSimpleFrame(x_marker) |
| 27 |
|
| 28 |
tf.set_translation([0, 8, 0]) |
| 29 |
y_marker = dart.dynamics.SimpleFrame(dart.dynamics.Frame.World(), 'Y', tf) |
| 30 |
y_shape = dart.dynamics.BoxShape([0.2, 0.2, 0.2]) |
| 31 |
y_marker.setShape(y_shape) |
| 32 |
y_marker.getVisualAspect(True).setColor([0, 0.9, 0]) |
| 33 |
world.addSimpleFrame(y_marker) |
| 34 |
|
| 35 |
tf.set_translation([0, 0, 8]) |
| 36 |
z_marker = dart.dynamics.SimpleFrame(dart.dynamics.Frame.World(), 'Z', tf) |
| 37 |
z_shape = dart.dynamics.BoxShape([0.2, 0.2, 0.2]) |
| 38 |
z_marker.setShape(z_shape) |
| 39 |
z_marker.getVisualAspect(True).setColor([0, 0, 0.9]) |
| 40 |
world.addSimpleFrame(z_marker) |
| 41 |
|
| 42 |
node = dart.gui.osg.WorldNode(world) |
| 43 |
|
| 44 |
viewer = dart.gui.osg.Viewer() |
| 45 |
viewer.addWorldNode(node) |
| 46 |
viewer.enableDragAndDrop(frame) |
| 47 |
viewer.enableDragAndDrop(draggable) |
| 48 |
|
| 49 |
viewer.addInstructionText("\nCtrl + Left-click: Rotate the box\n") |
| 50 |
print(viewer.getInstructions()) |
| 51 |
|
| 52 |
viewer.setUpViewInWindow(0, 0, 640, 480) |
| 53 |
viewer.setCameraHomePosition([20, 17, 17], [0, 0, 0], [0, 0, 1]) |
| 54 |
viewer.run() |
| 55 |
|
| 56 |
|
| 57 |
if __name__ == "__main__": |
| 58 |
main() |