Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing scene/camera sync with browser view after web page-mouse interaction. #85

Open
nastasi opened this issue Feb 27, 2020 · 4 comments

Comments

@nastasi
Copy link

nastasi commented Feb 27, 2020

If you change the point of view dragging with mouse in the browser window the camera and scene data are not updated.
It could be CPU intensive/inefficient so could be possible to add at least an explicit sync method to be able to retrieve correct parameters just before perform some action like camera movement after key pressure detection or just before an action is made on scene or camera ?

@BruceSherwood
Copy link
Member

BruceSherwood commented Feb 27, 2020

I don't understand. Run the following code and you will see scene.forward and scene.camera.axis changing as you use the mouse to rotate:

box()
forward = label(pos=vec(0,.2,0), text='')
axis = label(pos=vec(0,-.2,0), text='')
while True:
    rate(50)
    forward.text = scene.forward
    axis.text = scene.camera.axis

@nastasi
Copy link
Author

nastasi commented Feb 27, 2020

Correct, instead scene.up remains to <0,1,0>, is it correct ?

box()
forward = label(pos=vec(0,.2,0), text='')
axis = label(pos=vec(0,-.2,0), text='')
up = label(pos=vec(0,-.4,0), text='')
while True:
    rate(50)
    forward.text = scene.forward
    axis.text = scene.camera.axis
    up.text = scene.up

@BruceSherwood
Copy link
Member

That is how it currently works, though it could use some critical thought. I'm not entirely comfortable with this corner of the vpython world.

@nastasi
Copy link
Author

nastasi commented Feb 28, 2020

Using the test below things became a little more clear.
I didn't yet understand how it works exactly but seems that up is a sort of gamma in the polar coordinates (alpha, beta , gamma).
If you try to do a 360° using "right" button it return to <0,1,0> BUT if you move the scene with the mouse and try again to do 360° up components change differently than before.
@BruceSherwood ideas ?
(BTW: when you change the scene with the mouse just canvas and forward items are in the event list)

from math import pi as PI
from vpython import (box, label, vec, rate, scene)

box()
forward = label(pos=vec(0, .2, 0), text='')
axis = label(pos=vec(0, -.2, 0), text='')
up = label(pos=vec(0, -.4, 0), text='')


def keydown(ev):
    if ev.key == 'right':
        print('rotate')
        scene.camera.rotate(PI / 8, axis=scene.camera.axis)
    if ev.key == 'left':
        print('rotate')
        scene.camera.rotate(-PI / 8, axis=scene.camera.axis)


scene.bind('keydown', keydown)

while True:
    rate(50)
    forward.text = "F: %.3f, %.3f, %.3f" % (scene.forward.x, scene.forward.y, scene.forward.z)
    axis.text = "A: %.3f, %.3f, %.3f" % (scene.camera.axis.x, scene.camera.axis.y, scene.camera.axis.z)
    up.text = "U: %.3f, %.3f, %.3f" % (scene.up.x, scene.up.y, scene.up.z)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants