Пример #1
0
def drawCameraFrame():  # create frame and draw its contents
    global  cam_box, cent_plane,  cam_lab, cam_tri, range_lab, linelen, fwd_line
    global fwd_arrow, mouse_line, mouse_arrow, mouse_lab, fov, range_x, cam_dist, cam_frame
    global ray
    cam_frame = vs.frame( pos = vs.vector(0,2,2,),  axis = (0,0,1))
               # NB: contents are rel to this frame.  start with camera looking "forward"
               # origin is at simulated scene.center
    fov = vs.pi/3.0  # 60 deg 
    range_x = 6  # simulates scene.range.x  
    cam_dist = range_x / vs.tan(fov/2.0)  # distance between camera and center. 
    ray = vs.vector(-20.0, 2.5, 3.0).norm()  # (unit) direction of ray vector (arbitrary)
                                         #  REL TO CAMERA FRAME
    cam_box = vs.box(frame=cam_frame, length=1.5, height=1, width=1.0, color=clr.blue,
                                                   pos=(cam_dist,0,0)) # camera-box
    cent_plane = vs.box(frame=cam_frame, length=0.01, height=range_x*1.3, width=range_x*2,
                                                    pos=(0,0,0), opacity=0.5 )  # central plane
    cam_lab = vs.label(frame=cam_frame, text= 'U', pos= (cam_dist,0,0), height= 9, xoffset= 6)
    cam_tri = vs.faces( frame=cam_frame, pos=[(0,0,0), (0,0,-range_x), (cam_dist,0,0)])
    cam_tri.make_normals()
    cam_tri.make_twosided()
    range_lab = vs.label(frame=cam_frame, text= 'R', pos= (0, 0, -range_x), height= 9, xoffset= 6)
    linelen = scene_size + vs.mag( cam_frame.axis.norm()*cam_dist + cam_frame.pos)
                                                                   # len of lines from camera
    fwd_line = drawLine( vs.vector(cam_dist,0,0), linelen, vs.vector(-1,0,0))
    fwd_arrow = vs.arrow(frame=cam_frame, axis=(-2,0,0), pos=(cam_dist, 0, 0), shaftwidth=0.08,
                                                                            color=clr.yellow)
    vs.label(frame=cam_frame, text='C', pos=(0,0,0), height=9, xoffset=6, color=clr.yellow)
    mouse_line = drawLine ( vs.vector(cam_dist,0,0), linelen, ray ) 
    mouse_arrow = vs.arrow(frame=cam_frame, axis=ray*2, pos=(cam_dist,0,0), shaftwidth=0.08,
                                                                                   color=clr.red)
    mouse_lab = vs.label(frame=cam_frame, text= 'M', height= 9, xoffset= 10, color=clr.red, 
                                pos=  -ray*(cam_dist/vs.dot(ray,(1,0,0))) + (cam_dist,0,0))
Пример #2
0
def draw_camera_frame():
    """Create frame and draw its contents."""
    global  CAM_BOX, CENT_PLANE, CAM_LAB, CAN_TRI, RANGE_LAB, LINELEN, FWD_LINE
    global FWR_ARROW, MOUSE_LINE, MOUSE_ARROW, MOUSE_LAB, FOV, RANGE_X, CAM_DIST, CAM_FRAME
    global RAY
    CAM_FRAME = vs.frame(pos=vs.vector(0, 2, 2, ), axis=(0, 0, 1))
               # NB: contents are rel to this frame.  start with camera looking "forward"
               # origin is at simulated scene.center
    FOV = vs.pi/3.0  # 60 deg
    RANGE_X = 6  # simulates scene.range.x
    CAM_DIST = RANGE_X / vs.tan(FOV/2.0)  # distance between camera and center.
    RAY = vs.vector(-20.0, 2.5, 3.0).norm()  # (unit) direction of ray vector (arbitrary)
                                         #  REL TO CAMERA FRAME
    CAM_BOX = vs.box(frame=CAM_FRAME, length=1.5, height=1, width=1.0,
                     color=CLR.blue, pos=(CAM_DIST, 0, 0)) # camera-box
    CENT_PLANE = vs.box(frame=CAM_FRAME, length=0.01, height=RANGE_X*1.3,
                        width=RANGE_X*2, pos=(0, 0, 0), opacity=0.5)  # central plane
    CAM_LAB = vs.label(frame=CAM_FRAME, text='U', pos=(CAM_DIST, 0, 0),
                       height=9, xoffset=6)
    CAN_TRI = vs.faces(frame=CAM_FRAME, pos=[
        (0, 0, 0), (0, 0, -RANGE_X), (CAM_DIST, 0, 0)])
    CAN_TRI.make_normals()
    CAN_TRI.make_twosided()
    RANGE_LAB = vs.label(frame=CAM_FRAME, text='R', pos=(0, 0, -RANGE_X),
                         height=9, xoffset=6)
    LINELEN = SCENE_SIZE + vs.mag(
        CAM_FRAME.axis.norm()*CAM_DIST + CAM_FRAME.pos)  # len of lines from camera

    FWD_LINE = draw_line(vs.vector(CAM_DIST, 0, 0), LINELEN, vs.vector(-1, 0, 0))
    FWR_ARROW = vs.arrow(frame=CAM_FRAME, axis=(-2, 0, 0), pos=(CAM_DIST, 0, 0),
                         shaftwidth=0.08, color=CLR.yellow)
    vs.label(frame=CAM_FRAME, text='C', pos=(0, 0, 0), height=9, xoffset=6,
             color=CLR.yellow)
    MOUSE_LINE = draw_line(vs.vector(CAM_DIST, 0, 0), LINELEN, RAY)
    MOUSE_ARROW = vs.arrow(frame=CAM_FRAME, axis=RAY*2, pos=(CAM_DIST, 0, 0),
                           shaftwidth=0.08, color=CLR.red)
    MOUSE_LAB = vs.label(
        frame=CAM_FRAME, text='M', height=9, xoffset=10,
        color=CLR.red,
        pos=-RAY*(CAM_DIST/vs.dot(RAY, (1, 0, 0))) + (CAM_DIST, 0, 0))
Пример #3
0
            GEARING = 4
        else:
            GEARING = 1
        CAM_DIST = CAM_DIST + (MOUSE_CHANGE.x + MOUSE_CHANGE.y + MOUSE_CHANGE.z)*GEARING
        if CAM_DIST <= 0:
            CAM_DIST = 0.001  # allow only positive
        LIMIT = SCENE_SIZE*2
        if CAM_DIST > LIMIT:
            CAM_DIST = LIMIT # limit size
        redraw_lines()
        CAM_BOX.pos = (CAM_DIST, 0, 0)
        CAM_LAB.pos = (CAM_DIST, 0, 0)
        FWR_ARROW.pos = (CAM_DIST, 0, 0)
        MOUSE_ARROW.pos = (CAM_DIST, 0, 0)
        MOUSE_LAB.pos = -RAY*(CAM_DIST/vs.dot(RAY, (1, 0, 0))) + (CAM_DIST, 0, 0)
        RANGE_X = CAM_DIST * vs.tan(FOV/2.0)
        CENT_PLANE.width = RANGE_X*2
        CENT_PLANE.height = RANGE_X*4.0/3
        redraw_tri()  # redraw the camera triangle
        RANGE_LAB.pos = (0, 0, -RANGE_X)
        MODE_LAB.SetLabel('scene.range:\n' + format(RANGE_X, "9.3"))
        if not Q_PY:
            VSS.range = RANGE_X

    elif MODE == 'v': # demonstrate altering scene.fov
        CAM_DIST = CAM_DIST + (MOUSE_CHANGE.x + MOUSE_CHANGE.y + MOUSE_CHANGE.z)*4
        if CAM_DIST <= 0:
            CAM_DIST = 0.001  # allow only positive
        RAY = (MOUSE_LAB.pos - (CAM_DIST, 0, 0)).norm()
        redraw_lines()
        CAM_BOX.pos = (CAM_DIST, 0, 0)
Пример #4
0
       if not qPy:  vss.forward = - cam_frame.axis                
       
    elif mode == 'r': # demonstrate altering scene.range.  Alters size of camera triangle.
        if qPy: gearing = 4
        else: gearing = 1 
        cam_dist = cam_dist + (mouse_change.x + mouse_change.y + mouse_change.z)*gearing
        if cam_dist <= 0:  cam_dist = 0.001  # allow only positive
        limit = scene_size*2
        if cam_dist > limit: cam_dist = limit # limit size 
        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_lab.pos = -ray*(cam_dist/vs.dot(ray,(1,0,0))) + (cam_dist,0,0)
        range_x = cam_dist * vs.tan(fov/2.0)
        cent_plane.width = range_x*2
        cent_plane.height = range_x*4.0/3
        reDrawTri()  # redraw the camera triangle
        range_lab.pos= (0,0,-range_x)
        mode_lab.SetLabel( 'scene.range:\n' + format( range_x, "9.3")) 
        if not qPy:  vss.range = range_x

    elif mode == 'v': # demonstrate altering scene.fov
        cam_dist = cam_dist + (mouse_change.x + mouse_change.y + mouse_change.z)*4
        if cam_dist <= 0:  cam_dist = 0.001  # allow only positive
        ray = (mouse_lab.pos - (cam_dist, 0,0)).norm()  
        reDrawLines()
        cam_box.pos = (cam_dist,0,0) 
        cam_lab.pos = (cam_dist,0,0) 
        fwd_arrow.pos = (cam_dist,0,0)
Пример #5
0
def drawCameraFrame():  # create frame and draw its contents
    global cam_box, cent_plane, cam_lab, cam_tri, range_lab, linelen, fwd_line
    global fwd_arrow, mouse_line, mouse_arrow, mouse_lab, fov, range_x, cam_dist, cam_frame
    global ray
    cam_frame = vs.frame(pos=vs.vector(
        0,
        2,
        2,
    ), axis=(0, 0, 1))
    # NB: contents are rel to this frame.  start with camera looking "forward"
    # origin is at simulated scene.center
    fov = vs.pi / 3.0  # 60 deg
    range_x = 6  # simulates scene.range.x
    cam_dist = range_x / vs.tan(
        fov / 2.0)  # distance between camera and center.
    ray = vs.vector(-20.0, 2.5,
                    3.0).norm()  # (unit) direction of ray vector (arbitrary)
    #  REL TO CAMERA FRAME
    cam_box = vs.box(frame=cam_frame,
                     length=1.5,
                     height=1,
                     width=1.0,
                     color=clr.blue,
                     pos=(cam_dist, 0, 0))  # camera-box
    cent_plane = vs.box(frame=cam_frame,
                        length=0.01,
                        height=range_x * 1.3,
                        width=range_x * 2,
                        pos=(0, 0, 0),
                        opacity=0.5)  # central plane
    cam_lab = vs.label(frame=cam_frame,
                       text='U',
                       pos=(cam_dist, 0, 0),
                       height=9,
                       xoffset=6)
    cam_tri = vs.faces(frame=cam_frame,
                       pos=[(0, 0, 0), (0, 0, -range_x), (cam_dist, 0, 0)])
    cam_tri.make_normals()
    cam_tri.make_twosided()
    range_lab = vs.label(frame=cam_frame,
                         text='R',
                         pos=(0, 0, -range_x),
                         height=9,
                         xoffset=6)
    linelen = scene_size + vs.mag(cam_frame.axis.norm() * cam_dist +
                                  cam_frame.pos)
    # len of lines from camera
    fwd_line = drawLine(vs.vector(cam_dist, 0, 0), linelen,
                        vs.vector(-1, 0, 0))
    fwd_arrow = vs.arrow(frame=cam_frame,
                         axis=(-2, 0, 0),
                         pos=(cam_dist, 0, 0),
                         shaftwidth=0.08,
                         color=clr.yellow)
    vs.label(frame=cam_frame,
             text='C',
             pos=(0, 0, 0),
             height=9,
             xoffset=6,
             color=clr.yellow)
    mouse_line = drawLine(vs.vector(cam_dist, 0, 0), linelen, ray)
    mouse_arrow = vs.arrow(frame=cam_frame,
                           axis=ray * 2,
                           pos=(cam_dist, 0, 0),
                           shaftwidth=0.08,
                           color=clr.red)
    mouse_lab = vs.label(frame=cam_frame,
                         text='M',
                         height=9,
                         xoffset=10,
                         color=clr.red,
                         pos=-ray * (cam_dist / vs.dot(ray, (1, 0, 0))) +
                         (cam_dist, 0, 0))
Пример #6
0
    elif mode == 'r':  # demonstrate altering scene.range.  Alters size of camera triangle.
        if qPy: gearing = 4
        else: gearing = 1
        cam_dist = cam_dist + (mouse_change.x + mouse_change.y +
                               mouse_change.z) * gearing
        if cam_dist <= 0: cam_dist = 0.001  # allow only positive
        limit = scene_size * 2
        if cam_dist > limit: cam_dist = limit  # limit size
        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_lab.pos = -ray * (cam_dist / vs.dot(ray, (1, 0, 0))) + (cam_dist,
                                                                      0, 0)
        range_x = cam_dist * vs.tan(fov / 2.0)
        cent_plane.width = range_x * 2
        cent_plane.height = range_x * 4.0 / 3
        reDrawTri()  # redraw the camera triangle
        range_lab.pos = (0, 0, -range_x)
        mode_lab.SetLabel('scene.range:\n' + format(range_x, "9.3"))
        if not qPy: vss.range = range_x

    elif mode == 'v':  # demonstrate altering scene.fov
        cam_dist = cam_dist + (mouse_change.x + mouse_change.y +
                               mouse_change.z) * 4
        if cam_dist <= 0: cam_dist = 0.001  # allow only positive
        ray = (mouse_lab.pos - (cam_dist, 0, 0)).norm()
        reDrawLines()
        cam_box.pos = (cam_dist, 0, 0)
        cam_lab.pos = (cam_dist, 0, 0)