Documente Academic
Documente Profesional
Documente Cultură
================================================================================
"""
# make a 3D panel
clr = vs.color
vss = scene
def axes( frame, colour, sz, posn ): # Make axes visible (of world or frame).
texts = ["X","Y","Z"]
posn = vs.vector(posn)
""" Draw grid of squares in XY, XZ or YZ plane with corner nearest origin at given posn.
sq= length of side of square. H = number of squares high (Y). W = number of squares wide (X).
"""
ht = H*sq
wd = W*sq
def drawLine( posn, length, direction): # draw straight line STARTING at given posn, with given
global ray
# NB: contents are rel to this frame. start with camera looking "forward"
pos=(cam_dist,0,0)) # camera-box
cam_tri.make_normals()
cam_tri.make_twosided()
color=clr.yellow)
color=clr.red)
drawCameraFrame()
def reDrawLines():
cam_tri.make_normals()
cam_tri.make_twosided()
global saved_pyvars
# save VPython GUI status (so that we can restore it later ). tuple()is NEEDED so the data
vss.forward = - cam_frame.axis
vss.center = cam_frame.pos
vss.fov = fov
vss.range = range_x
cam_tri.visible = False
def setPyView(): # set so we see view from py-cam (ie std VPython)
# Restore py-vars to what they were when qPy was turned off.
cam_tri.visible = True
global qPy
qPy = False
else:
qPy = True
global cam_frame
obj.visible = False
del obj
del cam_frame
global mode
wx.MessageBox(
"""The BLUE BOX (at U) represents the camera - ie your viewpoint in the model.
The WHITE rectangle represents the VPython window on your display device.
The RED ARROW marks the scene.mouse.ray (unit) vector. It is READ ONLY.
The right-angled triangle U-C-R shows the relationship between the main scene attributes:
The camera position is also held (as scene.mouse.camera) - but is READ ONLY.
In this simulation scene.range is the same on all 3 axes.
The control panel lets you see the effect of altering each of the above scene attributes.
The "Switch camera" button shows you the view from the camera in the model. It toggles.
The "Reset model" button resets the model to its initial state. It does not alter your view.
qDragging = True
global qDragging
qDragging = False
x1 = scene.width + 5
# Positions and sizes are in pixels, and pos(0,0) is the upper left corner of the window.
bRadio.Bind(wx.EVT_RADIOBOX, hRadio)
def str2(object): # convert tuple or vector to char values with 2 sig figs. Ie is like str()
RC = ''
for i in object:
RC += format( i, " 9.2") # Means output has: pad LHS with spaces, width 9, 2 sig figs.
return RC
bb.Bind(wx.EVT_BUTTON, func)
mode = None
qDragging = False
mouse_pos_old = vss.mouse.pos
vss.autoscale = False
vss.autocenter = False
while True:
vs.rate(20)
mouse_pos_old = vss.mouse.pos
reDrawLines()
mode_lab.SetLabel('scene.center:\n' + str2(cam_frame.pos))
cam_frame.up = (0,1,0)
mode_lab.SetLabel('scene.forward:\n' + str2( - cam_frame.axis))
elif mode == 'r': # demonstrate altering scene.range. Alters size of camera triangle.
if qPy: gearing = 4
else: gearing = 1
limit = scene_size*2
reDrawLines()
cam_box.pos = (cam_dist,0,0)
cam_lab.pos = (cam_dist,0,0)
fwd_arrow.pos = (cam_dist,0,0)
mouse_arrow.pos = (cam_dist,0,0)
cent_plane.width = range_x*2
cent_plane.height = range_x*4.0/3
range_lab.pos= (0,0,-range_x)
reDrawLines()
cam_box.pos = (cam_dist,0,0)
cam_lab.pos = (cam_dist,0,0)
fwd_arrow.pos = (cam_dist,0,0)
mouse_arrow.pos = (cam_dist,0,0)
mouse_arrow.axis = ray*2
m_pos = cam_frame.world_to_frame(hit)
mouse_lab.pos = m_pos
mouse_arrow.axis = 2*ray