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

How can I use quaternions? #9

Open
cx20 opened this issue May 4, 2018 · 4 comments
Open

How can I use quaternions? #9

cx20 opened this issue May 4, 2018 · 4 comments

Comments

@cx20
Copy link

cx20 commented May 4, 2018

Below is an example of using quaternion in Three.js.
http://jsdo.it/cx20/qqSi

    // rotate
    mesh1.rotation.x += Math.PI / 180;
    mesh1.rotation.y += Math.PI / 180;
    mesh1.rotation.z += Math.PI / 180;
    
    // quaternion
    var axis = new THREE.Vector3(1,1,1).normalize();
    angle += Math.PI / 180;
    var q = new THREE.Quaternion();
    q.setFromAxisAngle(axis,angle);
    mesh2.quaternion.copy(q);

How do I write the code in CZPG.js to do the same thing as above?

@PrincessGod
Copy link
Owner

@cx20 Hi.

I am not implement many quaternion functions right now, but you can set quaternion for Model and Node, like

model.quaternion = [0,0,0,1];
sceneNode.quaternion = [0,0,0,1];

So maybe you have to compute target quaternion by yourself right now...

I will mention you after implement quaternion functions :)

@cx20
Copy link
Author

cx20 commented May 5, 2018

@PrincessGod I tried using model.quaternion as a trial. However, it seems to be an infinite loop.
http://jsdo.it/cx20/MZ4J

    model.quaternion = [q.x, q.y, q.z, q.w];
czpg.js:1 
Uncaught RangeError: Maximum call stack size exceeded
    at Model.setQuaternion (VM261 czpg.js:1)
    at Model.setQuaternion (VM261 czpg.js:4416)
    at Model.setQuaternion (VM261 czpg.js:4416)
    at Model.setQuaternion (VM261 czpg.js:4416)
    at Model.setQuaternion (VM261 czpg.js:4416)
    at Model.setQuaternion (VM261 czpg.js:4416)
    at Model.setQuaternion (VM261 czpg.js:4416)
    at Model.setQuaternion (VM261 czpg.js:4416)
    at Model.setQuaternion (VM261 czpg.js:4416)
    at Model.setQuaternion (VM261 czpg.js:4416)
    setQuaternion( ...args ) {

        if ( args[ 0 ] instanceof Transform )
            return this.setQuaternion( ...( args[ 0 ].quaternion.getArray() ) );

        this.setQuaternion( ...args ); // infinite loop?
        return this;

    },

@PrincessGod
Copy link
Owner

@cx20 ha! Another bug!

fixed 0917462

@cx20
Copy link
Author

cx20 commented May 5, 2018

@PrincessGod Thanks! I confirmed that it will function properly.
http://jsdo.it/cx20/MZ4J
image

Also, I added the sample of this CZPG.js to the following physical operation sample list.
https://qiita.com/cx20/items/3ebed669fb9c9e797935

I think that I will transplant other samples in the future.

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

2 participants