THREE.js: Can you force a different order of operations for three.js?

谁都会走 提交于 2019-12-25 04:34:22

问题


See this question: Threejs Transform Matrix ordering

I'm drawing the orbits of the planets and having problem with changing inertial reference frames (I chose to align the three.js world coordinates with the viewed planet's inertial reference frame). But I need to force three.js to apply operations in the order shown below so the orbit is properly displayed (presently the orbit stays at world (0,0,0) and spins crazily).

The normal (physics) way to do this is to do the following in order: 1. zero position and rotation of the ellipse.

ellipse.position.set(0,0,0);
ellipse.rotation.set(0,0,0);

2. Apply Direction Cosine Matrix (matrix which changes reference frame).

ellipse.applyMatrix(DCM);

3. Translate orbit to be centered on orbiting body, where r is the radius vector of the planet.

ellipse.translateX(r.x);
ellipse.translateY(r.y);
ellipse.translateZ(r.z);

4. Rotate the ellipse.

ellipse.rotateZ(RAAN); // RAAN : right angle of ascending node
ellipse.rotateX(inc);  // inc  : orbit inclination
ellipse.rotateZ(ArgP); // ArgP : Argument of Periapsis.

5. Adjust for difference between center and focal point.

ellipse.translateX(-c);

6. Profit.

So I'm not sure if there's some kind of command flow in three.js that I'm not familiar with, or if node.js is causing asynchronous problems.


回答1:


Okay. I just posted this, but found the solution for anyone who has the same problem in the future. If you want to apply things in a different order of operations than three.js wants you to (as seen in this post: Threejs Transform Matrix ordering). Then you must use the applyMatrix function between each operation that you wish to do in a specific order.

Using the above as an example:

ellipse.position.set(0,0,0);
ellipse.rotation.set(0,0,0);
ellipse.updateMatrix();

ellipse.applyMatrix(DCM);
ellipse.updateMatrix();

ellipse.translateX(r.x);
ellipse.translateY(r.y);
ellipse.translateZ(r.z);
ellipse.updateMatrix();

ellipse.rotateZ(RAAN); // RAAN : right angle of ascending node
ellipse.rotateX(inc);  // inc  : orbit inclination
ellipse.rotateZ(ArgP); // ArgP : Argument of Periapsis.
ellipse.updateMatrix();

ellipse.translateX(-c);
ellipse.updateMatrix();


来源:https://stackoverflow.com/questions/40133431/three-js-can-you-force-a-different-order-of-operations-for-three-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!