Difficulty getting my camera view correct?

48 views
Skip to first unread message

Doug Wegscheid

unread,
Oct 21, 2024, 12:00:44 PM10/21/24
to VPython-users
If I do this (letting autoscale work):

from vpython import *
import json


class MyEncoder(json.JSONEncoder):
   def default(self, o):
     if isinstance(o, vector):
       return [o.x, o.y, o.z]


scene.width=200
scene.height=200

boxy = box(size=vector(1, 1, 1), color=vector(1, 0.0, 0.0), emissive=True)
boxy_light = local_light(pos=boxy.pos, color=boxy.color)

while True:
  rate(30)

  c = {
    "p": scene.camera.pos,
    "fov": scene.fov,
    "range": scene.range,
  }
  scene.caption = json.dumps(c, cls=MyEncoder)

I get this:

auto.jpg




If I try to manually set the camera up with the same parameters to get the same result:

from vpython import *
import json


class MyEncoder(json.JSONEncoder):
  def default(self, o):
    if isinstance(o, vector):
      return [o.x, o.y, o.z]


scene.width=200
scene.height=200

scene.autoscale = False

scene.fov = 1.04
scene.camera.pos = vector(0, 0, 1.732)
scene.forward = -1 * scene.camera.pos

boxy = box(size=vector(1, 1, 1), color=vector(1, 0.0, 0.0), emissive=True)
boxy_light = local_light(pos=boxy.pos, color=boxy.color)

while True:
  rate(30)

  c = {
    "p": scene.camera.pos,
    "fov": scene.fov,
    "range": scene.range,
  }
  scene.caption = json.dumps(c, cls=MyEncoder)

I don't get the same results:

manual.jpg

What am I doing incorrectly?

Bruce Sherwood

unread,
Oct 21, 2024, 3:21:07 PM10/21/24
to vpytho...@googlegroups.com
The following sequence does what you expect. The issue is that you need to place "scene.autoscale" after creating the objects.

from vpython import *
import json


class MyEncoder(json.JSONEncoder):
  def default(self, o):
    if isinstance(o, vector):
      return [o.x, o.y, o.z]


scene.width=200
scene.height=200

boxy = box(size=vector(1, 1, 1), color=vector(1, 0.0, 0.0), emissive=True)
boxy_light = local_light(pos=boxy.pos, color=boxy.color)

scene.autoscale = False

scene.fov = 1.04
scene.camera.pos = vector(0, 0, 1.732)
scene.forward = -1 * scene.camera.pos

Bruce Sherwood

unread,
Oct 21, 2024, 3:23:08 PM10/21/24
to VPython-users
You need to click the ... to see the whole program.

Bruce

Doug Wegscheid

unread,
Oct 22, 2024, 4:28:51 PM10/22/24
to VPython-users
Thank you! That's perfect.
Reply all
Reply to author
Forward
0 new messages