마우스 Press 함수

1
2
3
4
5
6
7
8
9
10
11
12
13
POINT curCursorPos;
GetCursorPos(&curCursorPos);
float dx = math::ConvertToRadians(static_cast<float>(curCursorPos.x - m_pPlayer->preCursorPos.x));
float dy = math::ConvertToRadians(static_cast<float>(curCursorPos.y - m_pPlayer->preCursorPos.y));
math::Vec3 left = m_pPlayer->m_pComponent_Transform->Left; // { -1, 0, 0 }
m_pPlayer->m_pComponent_Transform->Rotate(left, dy);
math::Vec3 down = m_pPlayer->m_pComponent_Transform->Down; // { 0, -1, 0 }
m_pPlayer->m_pComponent_Transform->Rotate(down, dx);
m_pPlayer->preCursorPos = curCursorPos;
cs

질문 쓰다가 나도 뭐라고 써야할지 몰라서 좆같다...
내가 이걸 왜 하고있지.


수정)

Rotate함수인데, Rotate 함수 자체에는 문제 없어보임?? Rotation은 쿼터니언임. 축, 각 입력받아서 쿼터니언 만들고, 현재 값에 만들어진 쿼터니언 더해주는거임.

위 코드에서 Rotate하는 함수가 2개인데, 하나 주석처리하면 문제 안생기는 것 같아서...

뭔가 x랑 y를 둘 다 처리하니까 이상하게 움직이는 것 같음...

그래서 일단 내가 사용하고있는 Rotate가 논리적으로 문제가 있는지 알고싶음.


1
2
3
4
5
    void Rotate(const math::Vec3& axis, const float& radian) {
        math::Quaternion addQuat = math::QuaternionAngleAxis(axis, radian);
        Rotation = addQuat * Rotation;
    }
 
cs


1
2
3
4
5
6
7
8
9
10
11
12
math::Quaternion math::QuaternionAngleAxis(const math::Vec3& axis, const float& angle) {
    math::Quaternion quat;
 
    const float s = std::sin(angle * 0.5f);
    quat.w = std::cos(angle * 0.5f);
    quat.x = axis.x * s;
    quat.y = axis.y * s;
    quat.z = axis.z * s;
 
    return quat;
}
 
cs


이건 worldViewProj 구하는 부분인데 혹시 곱셈 순서 맞는지 봐줄 수 있음?

1
2
3
4
5
6
7
8
    math::Matrix world = math::MatrixIdentity();
    math::Matrix translation = math::Translation(*m_Context.Translation);
    math::Matrix rotation = math::MatrixFromQuaternion(*m_Context.Rotation);
    math::Matrix scale = math::Scale(*m_Context.Scale);
    world = scale * rotation * translation;
    
    math::Matrix worldViewProj = world * viewMatrix * projMatrix;
    worldViewProj = math::Transpose(worldViewProj);
cs