2

我有这个杂货岛,我应该让它看起来好像这个人正在穿过小岛,但为了做到这一点,物体必须通过相机,每次它靠近时,它都会撞到窗户,它几乎看起来像是后退并朝相反的方向移动。但如果我放大一点,它就会通过,但会在中途放慢速度。有没有办法让物体自动通过相机?谢谢

from visual import *

sphere(pos=(0,0,0), radius = 0.5)
text(pos=(-2,1,0), text="Center")

rightside = box(pos=(10,0,-40), axis=(1,300,0), height=0.5, width=60, length=12, material=materials.emissive)
leftside = box(pos=(-10,0,-40), axis=(-1,300,0), height=0.5, width=60, length=12, material=materials.emissive)
bottomside = box(pos=(0,-5.8,-40), axis=(1,0,0), height=0.5, width=60, length=20, color=color.cyan, material=materials.emissive)

leftfirstshelf = box(pos=(8,0,-40), axis=(1,0,0), height=0.5, width=60, length=4, color=color.cyan, material=materials.emissive)
leftsecondshelf = box(pos=(-8,0,-40), axis=(1,0,0), height=0.5, width=60, length=4, color=color.white, material=materials.emissive)
leftthirdshelf = box(pos=(-8,-4,-40), axis=(1,0,0), height=0.5, width=60, length=4, color=color.cyan, material=materials.emissive)


rightfirstshelf = box(pos=(8,4,-40), axis=(1,0,0), height=0.5, width=60, length=4, color=color.white, material=materials.emissive)
rightsecondshelf = box(pos=(-8,4,-40), axis=(1,0,0), height=0.5, width=60, length=4, color=color.cyan, material=materials.emissive)
rightthirdshelf = box(pos=(8,-4,-40), axis=(1,0,0), height=0.5, width=60, length=4, color=color.white, material=materials.emissive)


cheeriosbox = box(pos=(8,6,-60), axis=(1,0,0), height=4, width=2.5, length=0.8, color=color.yellow, material=materials.emissive)
cheeriostext = text(pos=(7.7,7,-61), axis=(0,0,25), height=0.5, width=2.5, length=0.8, color=color.black, text='Cheerios')


watermelon = ellipsoid(pos=(8,2,-40), height=3, width=3.5, length=3, color=color.green, material=materials.emissive)


cokecan = cylinder(pos=(-8,-3.5,-60), height=0, width=0, length=3, color=color.red, material=materials.emissive, axis=(0,7,0))
cokecantext = text(pos=(-7.1,-2,-59), height=1, width=2, length=1, axis=(0,0,-25), color=color.black, text="Coke")


leftcarrotbody = cone(pos=(-8,0.5,-30), radius=0.2, color=color.orange, axis=(0,0,3), material=materials.emissive)
leftcarrottop = sphere(pos=(-8,0.5,-30),radius=0.3, color=color.green, material=materials.emissive)

middlecarrotbody = cone(pos=(-7.5,0.5,-30), radius=0.2, color=color.orange, axis=(0,0,3), material=materials.emissive)
middlecarrottop = sphere(pos=(-7.5,0.5,-30),radius=0.3, color=color.green, material=materials.emissive)

rightcarrotbody = cone(pos=(-7,0.5,-30), radius=0.2, color=color.orange, axis=(0,0,3), material=materials.emissive)
rightcarrottop = sphere(pos=(-7,0.5,-30),radius=0.3, color=color.green, material=materials.emissive)


orangefruit = sphere(pos=(-7.5,5.3,-15), radius=1, color=color.orange, material=materials.emissive)


bottomrowcupone = cylinder(pos=(8,-3.75,-15), radius=0.5, height=2, axis=(0,0.9,0),color=color.blue, material=materials.emissive)
bottomrowcuptwo = cylinder(pos=(8,-3.75,-14), radius=0.5, height=2, axis=(0,0.9,0),color=color.blue, material=materials.emissive)
bottomrowcupthree = cylinder(pos=(8,-3.75,-13), radius=0.5, height=2, axis=(0,0.9,0),color=color.blue, material=materials.emissive)
bottomrowcupfour = cylinder(pos=(8,-3.75,-12), radius=0.5, height=2, axis=(0,0.9,0),color=color.blue, material=materials.emissive)

thirdrowcupone = cylinder(pos=(8,-2.86,-14.5), radius=0.5, height=2, axis=(0,0.9,0),color=color.blue, material=materials.emissive)
thirdrowcuptwo = cylinder(pos=(8,-2.86,-13.5), radius=0.5, height=2, axis=(0,0.9,0),color=color.blue, material=materials.emissive)
thirdrowcupthree = cylinder(pos=(8,-2.86,-12.5), radius=0.5, height=2, axis=(0,0.9,0),color=color.blue, material=materials.emissive)

secondrowcupone = cylinder(pos=(8,-1.97,-14), radius=0.5, height=2, axis=(0,0.9,0),color=color.blue, material=materials.emissive)
secondrowcuptwo = cylinder(pos=(8,-1.97,-13), radius=0.5, height=2, axis=(0,0.9,0),color=color.blue, material=materials.emissive)

topcup = cylinder(pos=(8,-1.08,-13.5), radius=0.5, height=2, axis=(0,0.9,0),color=color.blue, material=materials.emissive)


a = vector(10,0,-40)
b = vector(-10,0,-40)
c = vector(0,-5.8,-40)
d = vector(8,0,-40)
e = vector(-8,0,-40)
f = vector(-8,-4,-40)
g = vector(8,4,-40)
h = vector(-8,4,-40)
i = vector(8,-4,-40)
j = vector(8,6,-60)
k = vector(7.7,7,-61.15)
l = vector(8,2,-40)
m = vector(-8,-3.5,-60)
n = vector(-7.1,-2,-59)
o = vector(-8,0.5,-30)
p = vector(-8,0.5,-30)
q = vector(-7.5,0.5,-30)
r = vector(-7.5,0.5,-30)
s = vector(-7,0.5,-30)
t = vector(-7,0.5,-30)
u = vector(-7.5,5.3,-15)
v = vector(8,-3.75,-15)
w = vector(8,-3.75,-14)
x = vector(8,-3.75,-13)
y = vector(8,-3.75,-12)
z = vector(8,-2.86,-14.5)
aia = vector(8,-2.86,-13.5)
bib = vector(8,-2.86,-12.5)
cic = vector(8,-1.97,-14)
did = vector(8,-1.97,-13)
eie = vector(8,-1.08,-13.5)


while a.z < 100:

    rate(20)

    rightside.pos = a

    leftside.pos = b

    bottomside.pos = c

    leftfirstshelf.pos = d

    leftsecondshelf.pos = e

    leftthirdshelf.pos = f

    rightfirstshelf.pos = g

    rightsecondshelf.pos = h

    rightthirdshelf.pos = i

    cheeriosbox.pos = j

    cheeriostext.pos = k

    watermelon.pos = l

    cokecan.pos = m

    cokecantext.pos = n

    leftcarrotbody.pos = o

    leftcarrottop.pos = p

    middlecarrotbody.pos = q

    middlecarrottop.pos = r

    rightcarrotbody.pos = s

    rightcarrottop.pos = t

    orangefruit.pos = u

    bottomrowcupone.pos = v

    bottomrowcuptwo.pos = w

    bottomrowcupthree.pos = x

    bottomrowcupfour.pos = y

    thirdrowcupone.pos = z

    thirdrowcuptwo.pos = aia

    thirdrowcupthree.pos = bib

    secondrowcupone.pos = cic

    secondrowcuptwo.pos = did

    topcup.pos = eie


    a.z = a.z + 1

    b.z = b.z + 1

    c.z = c.z + 1

    d.z = d.z +1

    e.z = e.z + 1

    f.z = f.z + 1

    g.z = g.z + 1

    h.z = h.z + 1

    i.z = i.z + 1

    j.z = j.z + 1

    k.z = k.z + 1

    l.z = l.z + 1

    m.z = m.z + 1

    n.z = n.z + 1

    o.z = o.z + 1

    p.z = p.z + 1

    q.z = q.z + 1

    r.z = r.z + 1

    s.z = s.z + 1

    t.z = t.z + 1

    u.z = u.z + 1

    v.z = v.z + 1

    w.z = w.z + 1

    x.z = x.z + 1

    y.z = y.z + 1

    z.z = z.z + 1

    aia.z = aia.z + 1

    bib.z = bib.z + 1

    cic.z = cic.z + 1

    did.z = did.z + 1

    eie.z = eie.z + 1
4

1 回答 1

2

我明白了,在 VPython 中有一个称为自动缩放的自动缩放功能,为了关闭它,代码是 scene.autoscale = False,你所做的就是将它放在 while 循环之前。它会阻止相机缩小以将所有对象保留在框架中。

于 2012-08-22T18:58:51.233 回答