Wednesday, April 18, 2007

Simulation Test (Trunk r33)

import soy
white = soy.Color('#fff')
ltgrey = soy.Color('#ccc')
win = soy.Window('Simulation Test')
sce = soy.Scene()
cam = soy.bodies.Camera(sce)
cam.position = (0.0,0.0,5.0)
s1 = soy.widgets.Square(win, position=(25,25), size=(150,150), color=white)
pro = soy.widgets.Projector(win, size=(320,240), camera=cam)
s2 = soy.widgets.Square(win, position=(100,50), size=(25,25), color=ltgrey)
pyr = soy.bodies.Pyramid(sce)
pyr.rotation = (1.0,1.0,0.0)


What this does: Three widgets are created - a white square, a projector, and a grey square. The prior can be seen behind the 3d scene and the latter in front of it. A "Pyramid" body is created, something in the code just for testing, and is given a rotational velocity around two axis. Sure enough, the pyramid rotates before the camera.

When run from an interactive shell the .position .rotation and .velocity can be modified for either cam or pyr as the simulation runs. Unlike other Python-based engines Python does not need to be in some "loop" for the simulator to do it's job.

No comments: