|
From: Jeremy F. <Jer...@lo...> - 2007-01-17 14:53:32
|
Hello !
I've got few questions about vpython.
I'm trying to build a little environnement in which i can control the camera
with a program. Below that message is the code i wrote. This is largely
inspired from stonehenge.py and display_kernel as advised on the list. It's
working ... (i think) but i'm wondering if i'm doing it in the right way ....
especially the things like :
old = scene.range [....] scene.range=old .. i don't really understand what
i'm doing there
and
using scene.up to compute the orth vector = norm(cross(forward,up)). I
thought the up vector was fixed .... to compute the orth vector that
corresponds to a local horizontal axis for the camera, i should use a local
up axis ... moving as i move my camera ?! am i wrong ?
What do you think about it ?
Thanks !
Jeremy.
#!/usr/bin/env python
from visual import *
cylinder()
def rotate_camera(pan,tilt):
old = scene.range
newforward = rotate(scene.forward,axis=scene.up,angle=pan)
scene.center =
scene.mouse.camera+newforward*mag(scene.center-scene.mouse.camera)
scene.forward = newforward
scene.range = old
orth = norm(cross( scene.forward,scene.up))
newforward = rotate(scene.forward,axis = orth,angle=tilt)
scene.center =
scene.mouse.camera+newforward*mag(scene.center-scene.mouse.camera)
scene.forward = newforward
scene.range = old
while 1:
# The camera is moved with the mouse and up,down,left,right keys
if scene.kb.keys: # is there an event waiting to be processed?
s = scene.kb.getkey() # obtain keyboard information
if(s == 'up'):
rotate_camera(0,0.1)
elif(s=='down'):
rotate_camera(0,-0.1)
elif(s=='left'):
rotate_camera(0.1,0)
elif(s=='right'):
rotate_camera(-0.1,0)
|