We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.

Inaccurate raycast on camera rotation?

Home Forums Programming Inaccurate raycast on camera rotation?

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #40568
    elie520
    Participant

    Hello,

    Context:
    I wrote some javascript to have the following behaviour on my blender scene:
    -when a user clicks on an object, it places a dot at the clicking point, and
    -when the view changes, the dot moves in order to follow the clicked point in the scene.

    I do this in two steps:
    1- On click, I retrieve the click location in the 3D scene using (clientX, clientY) from the click event, and verge’s raycasting method.
    2- On camera movement, I compute the position of the 3D location on the screen and move the point accordingly.

    My problem:

    I attached the results I get on two examples.

    On both parts of the clip, I start by translating the camera and then I rotate it. You can clearly see that the translating part works very smoothly, and the rotating part kind of flickers.

    Do you have any idea to help me? Thanks!

    Attachments:
    You must be logged in to view attached files.
    #40581

    Hi,

    This kind of “lagging” usually happens when the code that uses the position/rotation of a camera (or any other object) is executed before those transforms are automatically updated on the current frame. As a result it uses the old values and therefore has 1 frame lag.

    It’s difficult to say without the actual code, but if you use the camera transforms in your calculations then updating the camera’s world matrix just before obtaining its position/rotation may help:

    
    camera.updateMatrixWorld();
    

    Co-founder and lead developer at Soft8Soft.

    #40670
    elie520
    Participant

    Thank you for your answer!
    As soon as I have some time I’ll look into your idea, and eventually share the cleaned code if I still need help. In any case, I’ll get back to you.

    Cheers

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.