antimatter15 / splat

WebGL 3D Gaussian Splat Viewer
https://antimatter15.com/splat/
MIT License
2.04k stars 211 forks source link

Orbiting camera? #19

Open krawek opened 1 year ago

krawek commented 1 year ago

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

jkl3848 commented 1 year ago

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 commented 1 year ago

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

bolopenguin commented 1 year ago

Yes it would be a great feature to have

0xb00lean commented 1 year ago

Has anyone already done it ? Thanks .

chaotree commented 1 year ago

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.