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

Orbiting camera? #19

Open
krawek opened this issue Oct 10, 2023 · 5 comments
Open

Orbiting camera? #19

krawek opened this issue Oct 10, 2023 · 5 comments

Comments

@krawek
Copy link

krawek commented Oct 10, 2023

Anyone figured out how to make the camera orbit the object without tilting the camera?

@jkl3848
Copy link

jkl3848 commented Oct 10, 2023

I've also noticed into this issue. It's on my personal to-do list but I haven't had time to work on it yet.

@Elvis33LE
Copy link

Any Update on this? Everything works really smooth but the model is laying on the side :(

@bolopenguin
Copy link

Yes it would be a great feature to have

@0xb00lean
Copy link

Has anyone already done it ? Thanks .

@chaotree
Copy link

A potential simple way to do is to making the camera rotate about it's up axis while performing yaw rotation. Here is an example to modify the code in mousemove event:

// Modify the left mouse button down event

if (down == 1) {

    let inv = invert4(viewMatrix);
    let dx = (5 * (e.clientX - startX)) / innerWidth;
    let dy = (5 * (e.clientY - startY)) / innerHeight;
    let d = 4;

    //Extract the third column of the viewMatrix, which is the up axis of the camera
    let up_x = viewMatrix[4];
    let up_y = viewMatrix[5];
    let up_z = viewMatrix[6];

    let len = Math.hypot(up_x,up_y,up_z);
    up_x /= len;
    up_y /= len;
    up_z /= len;

    inv = translate4(inv, 0, 0, d);
    // inv = rotate4(inv, dx, 0, 1, 0);
    //Rotate around the camera's up axis
    inv = rotate4(inv, dx, up_x, up_y, up_z);
    inv = rotate4(inv, -dy, 1, 0, 0);
    inv = translate4(inv, 0, 0, -d);

    viewMatrix = invert4(inv);

    startX = e.clientX;
    startY = e.clientY;
}

It works nearly fine but still have some problem when rotating. You can do further work if you like and hope for your sharing.

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

6 participants