
Every Object3D has associated Martix4
Cameras have three additional Matrix4s:
const Component = ({
bufferGeometry,
material,
}) => {
const mesh = useRef<THREE.Mesh>()
useEffect(() => {
if (mesh.current) {
const RASToLPS = new THREE.Matrix4()
RASToLPS.set(-1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
mesh.current.applyMatrix4(RASToLPS)
}
}, [mesh])
return (
<mesh
****geometry = {bufferGeometry}
material = {material}
ref={mesh}
>
</mesh>
)
}
https://github.com/pmndrs/react-three-fiber/discussions/1419
https://www.appsloveworld.com/typescript/146/how-to-use-applymatrix4-in-react-three-fiber#google_vignette (추가적인 링크인데 참고하면 좋을듯 ⇒ matrix에 대한 상세한 정보를 설명하고 있다) - decompose와 관련된 내용들을 담고 있다.




three.js는 matrices를 사용해 3D 변형 변환 (위치), 회전, 확대 인코딩 등 정보를 담고 있다. 모든 인스턴스는 matrix를 가지고 있고, object 위치, 회전, 확대 등의 정보를 가지고 있다.
postion, quaternion(4원 산법), scale 속성을 조절한다. ⇒ 그리고 three.js가 object의 행렬을 맞추기 위해 재 계산을 진행하게 된다.
object.position.copy( start_position );
object.quaternion.copy( quaternion );
object.updateMatrix();오브젝트의 행렬을 직접 수정합니다. Matrix4 클래스에는 행렬 수정을 위한 여러 메서드가 있습니다.
object.matrix.setRotationFromQuaternion( quaternion );
object.matrix.setPosition( start_position );
object.matrixAutoUpdate = false;
Object의 Matrix는 object의 변형과 관련된 object의 parent에 저장을 한다. Object의 변형 정보를 world 좌표에서 가져오려면, object3D.matrixWorld에 접근해야 한다. ⇒ 부모 or 자식 object에 변형이 생기면 ⇒ 자식 Object의 Matrixworld을 Update MatrixWorld을 호출해 업데이트 하면 된다.
Three.js는 3D 회전을 두 가지 방법으로 나타냅니다:
이전까지 3D vertices을 (x,y,z)로만 이해를 함 ⇒ We will now have (x,y,z,w) vectors

3D graphics에서는 주로 4x4 matrix을 사용할 것이다 ⇒ allow us to transform (x,y,z,w) vertices (vertex 곱하기 matrix을 하면 된다)

glm::vec4 transformedVector = myMatrix * myVector //위 작업을 수행하는 c++ 코드


//위 과정을 코드로 표현하면 아래와 같다.
#include <glm/gtx/transform.hpp> // after <glm/glm.hpp>
glm::mat4 myMatrix = glm::translate(glm::mat4(), glm::vec3(10.0f, 0.0f, 0.0f));
glm::vec4 myVector(10.0f, 10.0f, 10.0f, 0.0f);
glm::vec4 transformedVector = myMatrix * myVector; // guess the result


동일한 기능을 수행하지만, model, view, projection matrices을 활용하면 보다 명료하고, 간단하게 위에서 한 과정들을 수행할 수 있다 (conventional method).

만약 object을 움직인다고 했을 때 ⇒”translation*rotation*scale”을 수행하면 된다 (You apply this matrix to all your vertices at each frame) ⇒ something doesn’t move will be at the center of the world (움직이지 않는 것은 world의 중심에 있다?)




Model Matrix는 좌측에 있는 것을 말하고 있는 것인가?
The engines don’t move the ship at all. The ship stays where it is and the engines move the universe around it.
Model 좌표: 특정 3D 모델 또는 object에 국한된 좌표 시스템을 의미한다. 기준점은 모델 자체 내에서 정의된다.
World 좌표: 전체 3D 장면이나, 환경에서 object들의 위치를 정의하는 데 사용되는 좌표 시스템이다.

glm::mat4 ViewMatrix = glm::translate(glm::mat4(), glm::vec3(-3.0f, 0.0f ,0.0f));


camera space에서 ⇒ “a vertex that happens to have x==0 and y==0 should be rendered at the center of the screen” (화면이 중앙점)



위 그림을 보면, (projection 이전 단계) ⇒ 파란색은 물체이고, 빨간색은 카메라 절두체(실제로 화면에 보이는 영역?을 의미한다)

projection matrix을 곱하면 위와 같은 형태를 띤다.
카메라 절두체 (빨간색)의 변화를 보면 projection matrix을 곱하니, cube의 형태를 띠게 되는 것을 확인할 수 있다. ⇒ (between 1 ~ -1), 반면 파란 물체의 경우 첫 번째 사진의 빨간색처럼 변형돼 있다. 원근이 적용된 형태? ⇒ cube안에 있는 것은 작아 보이고, 외부에 있는 것(우리가 볼 수 없는 것은 실제로 크게?)
