Giter Site home page Giter Site logo

Comments (3)

sebcrozet avatar sebcrozet commented on June 10, 2024

Hi!

Perhaps explaining how the projection is setup will help understand how look_at works.

If you have a zoom factor equal to 1, the coordinate system of the 2D projection matrix is such that:

  • The point (0, 0) is at the center of the window.
  • The point (W/2, H/2) is at the top-right corner of the window. In other words, you will see objects in the physics world with their position equal to (W/2, H/2) at the top-right corner of the screen.
  • The point (-W/2, -H/2) is at the bottom-left of corner the window. In other words, you will see objects in the physics world with their position equal to (-W/2, -H/2) at the bottom-left corner of the screen.

where W and H are the width and height of the window.
So if you have a zoom factor equal to 20 as in your example, simply divide those values by 20, e.g., the point (W/40, H/40) will be at the top-right corner of the window.

In any case, no matter the zoom factor, if you want to position the camera such that objects at the coordinate (0, 0) lie in the center of the window, then you should simply look_at the point (0, 0).

from nphysics.

MJohnson459 avatar MJohnson459 commented on June 10, 2024

Thanks for the explanation, I wasn't really sure what the zoom factor was. I think my problem is still a potential bug though as in the example I set the look_at position to be positive (30, 20) which I would expect to make the window center on that position instead of (0,0). However it seems to be doing something different (perhaps centering on (-30, -20)?).

The image isn't very clear but that line in the top half is a visible x-axis and there are balls spawned at (30,20) which should be visible.

    let center = Point2::new(WIDTH / 2.0, HEIGHT / 2.0);
    println!("Center = {}", center);
    testbed.look_at(center, 20.0);

from nphysics.

MJohnson459 avatar MJohnson459 commented on June 10, 2024

This should be fixed in nphysics as of 0.14.0 as it updates kiss3d to 0.23.0 which contains the fix.

from nphysics.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.