def update(dt): global zpos, earth_rot, earth_orbit, moon_orbit zpos *= 0.5**dt # Update the solar system earth_rot += tau * dt moon_orbit += tau * dt / 28.0 earth_orbit += tau * dt / 365.25 # Apply the positions to the scene earth.rotation = (math.degrees(earth_rot), 0, 1, 0) moon.rotation = (math.degrees(moon_orbit) - 90, 0, 1, 0) mx = MOON_DISTANCE * math.cos(-moon_orbit) mz = MOON_DISTANCE * math.sin(-moon_orbit) moon.pos = mx, 0, mz sx = SUN_DISTANCE * math.cos(earth_orbit) sz = SUN_DISTANCE * math.sin(earth_orbit) sunlight.pos = sx, 0, sz c.pos = v3((0, 3, zpos + 10))
def update(dt): global camera_rot camera_rot += 0.1 * dt c.pos = v3((math.cos(camera_rot) * 15, 5, math.sin(camera_rot) * 15))
zpos = 10 camera_rot = 0 tau = 2 * math.pi def update(dt): global camera_rot camera_rot += 0.1 * dt c.pos = v3((math.cos(camera_rot) * 15, 5, math.sin(camera_rot) * 15)) c = Camera(pos=v3((0, 0, -20)), width=WIDTH, height=HEIGHT) def on_draw(): scene.render(c) if __name__ == '__main__': from optparse import OptionParser parser = OptionParser() parser.add_option('-s', '--screenshot', metavar='FILE', help='Write screenshot to FILE') options, _ = parser.parse_args()
def test_airborne(): """looking down on the point, -z, -y direction""" root2 = math.sqrt(2) camera = Camera(pos=v3(2, 10 * root2, 10 * root2), look_at=v3(2, 0, 0)) vec_eq(project(point, camera), v3(0, 0.5 * root2, 0.5 * root2 - 20))
def test_minusxaligned(): """looking down the x axis in the +x direction""" camera = Camera(pos=v3(-20, 0, 0)) vec_eq(project(point, camera), v3(0, 1, -22))
def test_xaligned(): """looking down the x axis in the -x direction""" camera = Camera(pos=v3(20, 0, 0)) vec_eq(project(point, camera), v3(0, 1, -18))
def test_zaligned(): """looking down the z axis in the -z direction""" camera = Camera(pos=v3(0, 0, 20)) vec_eq(project(point, camera), v3(2, 1, -20))
import math from wasabisg.scenegraph import Matrix4, v3, Camera def vec_eq(a, b): """Return True if vectors a and b are approximately equal.""" return (a - b).magnitude_squared() < 1e-6 point = v3(2, 1, 0) def project(point, camera): return camera.get_view_matrix() * point def test_zaligned(): """looking down the z axis in the -z direction""" camera = Camera(pos=v3(0, 0, 20)) vec_eq(project(point, camera), v3(2, 1, -20)) def test_xaligned(): """looking down the x axis in the -x direction""" camera = Camera(pos=v3(20, 0, 0)) vec_eq(project(point, camera), v3(0, 1, -18)) def test_minusxaligned(): """looking down the x axis in the +x direction""" camera = Camera(pos=v3(-20, 0, 0))
robots.append(robot) angle = 180 tau = 2 * math.pi def update(dt): global angle angle += 90.0 * dt for r in robots: r.rotation = (angle, 0, 1, 0) c = Camera(pos=v3((0, 5, -20)), look_at=Point3(0, 5, 0), width=WIDTH, height=HEIGHT) def on_draw(): window.clear() scene.render(c) if __name__ == '__main__': from optparse import OptionParser parser = OptionParser() parser.add_option('-s', '--screenshot',