Sunday, August 28, 2022
HomeGame Development3d - Strolling round a sphere (planet)

3d – Strolling round a sphere (planet)


I’m utilizing THREE.js.
I can stroll across the sphere, however on some angles, the route converges on to the south pole… I’ve made a codepen, the place you possibly can play with it –
https://codepen.io/LeQwasd/pen/RwMmrmg (Controls: WASD for motion, QE for jaw)

The difficulty I’m having – is (apparently) – furry ball drawback. I discovered this: How do I repair my planet-facing digicam? – I’ve studied it, however I’m unable to decipher the given reply… I’m not positive, easy methods to apply it inside THREE.js. I’ve discovered the “poleDirection” vector.. (pink arrow within the codepen)..

I Have additionally seemed into this reply – Strolling on a sphere

This behaves properly, however this answer is just not what I would like..

The related code, I’ve seems to be like this:

    replace(delta: quantity): void {
        // Collect inputs
        const route = new Vector3();
        if (this.okay.isPressed("w")) {
        route.z -= 2;
        }
        if (this.okay.isPressed("s")) {
        route.z += 2;
        }
        if (this.okay.isPressed("a")) {
        route.x -= 2;
        }
        if (this.okay.isPressed("d")) {
        route.x += 2;
        }
        // Collect rotation
        if (this.okay.isPressed("q")) {
        this.angle += Math.PI / 180;
        }
        if (this.okay.isPressed("e")) {
        this.angle -= Math.PI / 180;
        }

        const orientation = new Quaternion()
        // Get the rotation so the item aligns with native up
        .setFromUnitVectors(this.up, this.$UP)
        // And apply jaw
        .multiply(new Quaternion().setFromAxisAngle(this.up, this.angle));

        // Level enter velocity within the route
        route.applyQuaternion(orientation);
        // calculate new place
        const newPosition = route.add(this.place);

        // Set place
        this.place.copy(newPosition);
        // Set orientation
        this.quaternion.copy(orientation);

        this._up.setDirection(this.$UP);
        this._right.setDirection(this.$RIGHT);

        // get native up
        this.$UP.copy(this.place).normalize();
        this.$RIGHT.set(1, 0, 0).applyQuaternion(this.quaternion);

        updateChildren(this, delta);
    }

Are you able to clarify what a part of the planet-facing digicam reply you need assistance deciphering?

I am going to communicate right here within the newbie, human language.

To start with – the code that was offered within the query (answered by OP) was written in C++/GLM. I’m not so positive – easy methods to switch it to JS/THREE.js, particularly – the matrix. Additionally – what do I do with it later..

Additionally – is not C++ approach of doing issues in 3D extra in regards to the matrix transformation, whereas THREE.js – about reworking trnanslation/rotation/scale parts individually, like I did up there? (At the very least for newbies?) At the very least – after I take a look at that matrix, all I see is – plug this, this this and that into matrix and 💥 and also you get the reply. However I’ve no understanding why that is this, and that’s that… Additionally – within the OP code – so far as I may perceive, the code included solely rotation for the yaw (no?), and did not embody something about translating precise positions (no?)

Additionally –

// Assemble a change matrix to go from our reference area
// so far on the sphere.
// (may equivalently be completed with a quaternion and translation vector)

I want to see the answer with quaternions and translations.

Additionally –
I noticed there like 3 or 4 approach’s of calculating the “poleDirection”.
If my UP is (0,1,0), I may simply as nicely make my RIGHT (1,0,0) and simply rotate it like I rotate my UP, and it will likely be to the fitting on a regular basis, appropriate? So this mine answer is simply jet one other one, appropriate?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments