расчет вращения объекта

0

Мне нужна помощь с поворотом obb:

Во-первых, я проверяю каждую вершину 3d-модели и получаю минимальные и максимальные значения для нахождения точек obb min/max.

void obb::checkVertex(vector3f& vertex)
{
    vLowerLeftFront.x = min(vLowerLeftFront.x, vertex.x);
    vLowerLeftFront.y = min(vLowerLeftFront.y, vertex.y);
    vLowerLeftFront.z = max(vLowerLeftFront.z, vertex.z);
    // Update upper-right-back corner of BB
    vUpperRightBack.x = max(vUpperRightBack.x, vertex.x);
    vUpperRightBack.y = max(vUpperRightBack.y, vertex.y);
    vUpperRightBack.z = min(vUpperRightBack.z, vertex.z);
}

Затем для каждого кадра обновляем obb (восемь углов), умножая на матрицу modelViewProjection.

void obb::update()
{
    //vector3f is a struct whit 3 floats (x,y,z);
    vector3f tmpV = vector3f(0.0f,0.0f,0.0f);
    float *floatMatrix = glm::value_ptr(matrix::getInstance()->getModelViewProjectionMatrix());


    tmpV.x = (floatMatrix[0] * vLowerLeftFront.x) +
               (floatMatrix[4] * vLowerLeftFront.y) +
               (floatMatrix[8] * vLowerLeftFront.z) +
               floatMatrix[12];
    tmpV.y = (floatMatrix[1] * vLowerLeftFront.x) +
               (floatMatrix[5] * vLowerLeftFront.y) +
               (floatMatrix[9] * vLowerLeftFront.z) +
               floatMatrix[13];
    tmpV.z = (floatMatrix[2] * vLowerLeftFront.x) +
               (floatMatrix[6] * vLowerLeftFront.y) +
               (floatMatrix[10] * vLowerLeftFront.z) +
               floatMatrix[14];

    vLowerLeftFront = tmpV;


    tmpV.x = (floatMatrix[0] * vUpperRightBack.x) +
               (floatMatrix[4] * vUpperRightBack.y) +
               (floatMatrix[8] * vUpperRightBack.z) +
               floatMatrix[12];
    tmpV.y = (floatMatrix[1] * vUpperRightBack.x) +
               (floatMatrix[5] * vUpperRightBack.y) +
               (floatMatrix[9] * vUpperRightBack.z) +
               floatMatrix[13];
    tmpV.z = (floatMatrix[2] * vUpperRightBack.x) +
               (floatMatrix[6] * vUpperRightBack.y) +
               (floatMatrix[10] * vUpperRightBack.z) +
               floatMatrix[14];

    vUpperRightBack = tmpV;


    tmpV.x = (floatMatrix[0] * vLowerRightFront.x) +
               (floatMatrix[4] * vLowerRightFront.y) +
               (floatMatrix[8] * vLowerRightFront.z) +
               floatMatrix[12];
    tmpV.y = (floatMatrix[1] * vLowerRightFront.x) +
               (floatMatrix[5] * vLowerRightFront.y) +
               (floatMatrix[9] * vLowerRightFront.z) +
               floatMatrix[13];
    tmpV.z = (floatMatrix[2] * vLowerRightFront.x) +
               (floatMatrix[6] * vLowerRightFront.y) +
               (floatMatrix[10] * vLowerRightFront.z) +
               floatMatrix[14];

    vLowerRightFront = tmpV;

    tmpV.x = (floatMatrix[0] * vLowerRightBack.x) +
               (floatMatrix[4] * vLowerRightBack.y) +
               (floatMatrix[8] * vLowerRightBack.z) +
               floatMatrix[12];
    tmpV.y = (floatMatrix[1] * vLowerRightBack.x) +
               (floatMatrix[5] * vLowerRightBack.y) +
               (floatMatrix[9] * vLowerRightBack.z) +
               floatMatrix[13];
    tmpV.z = (floatMatrix[2] * vLowerRightBack.x) +
               (floatMatrix[6] * vLowerRightBack.y) +
               (floatMatrix[10] * vLowerRightBack.z) +
               floatMatrix[14];

    vLowerRightBack = tmpV;

    tmpV.x = (floatMatrix[0] * vLowerLeftBack.x) +
               (floatMatrix[4] * vLowerLeftBack.y) +
               (floatMatrix[8] * vLowerLeftBack.z) +
               floatMatrix[12];
    tmpV.y = (floatMatrix[1] * vLowerLeftBack.x) +
               (floatMatrix[5] * vLowerLeftBack.y) +
               (floatMatrix[9] * vLowerLeftBack.z) +
               floatMatrix[13];
    tmpV.z = (floatMatrix[2] * vLowerLeftBack.x) +
               (floatMatrix[6] * vLowerLeftBack.y) +
               (floatMatrix[10] * vLowerLeftBack.z) +
               floatMatrix[14];

    vLowerLeftBack = tmpV;


    tmpV.x = (floatMatrix[0] * vUpperRightFront.x) +
               (floatMatrix[4] * vUpperRightFront.y) +
               (floatMatrix[8] * vUpperRightFront.z) +
               floatMatrix[12];
    tmpV.y = (floatMatrix[1] * vUpperRightFront.x) +
               (floatMatrix[5] * vUpperRightFront.y) +
               (floatMatrix[9] * vUpperRightFront.z) +
               floatMatrix[13];
    tmpV.z = (floatMatrix[2] * vUpperRightFront.x) +
               (floatMatrix[6] * vUpperRightFront.y) +
               (floatMatrix[10] * vUpperRightFront.z) +
               floatMatrix[14];

    vUpperRightFront = tmpV;


    tmpV.x = (floatMatrix[0] * vUpperLeftBack.x) +
               (floatMatrix[4] * vUpperLeftBack.y) +
               (floatMatrix[8] * vUpperLeftBack.z) +
               floatMatrix[12];
    tmpV.y = (floatMatrix[1] * vUpperLeftBack.x) +
               (floatMatrix[5] * vUpperLeftBack.y) +
               (floatMatrix[9] * vUpperLeftBack.z) +
               floatMatrix[13];
    tmpV.z = (floatMatrix[2] * vUpperLeftBack.x) +
               (floatMatrix[6] * vUpperLeftBack.y) +
               (floatMatrix[10] * vUpperLeftBack.z) +
               floatMatrix[14];

    vUpperLeftBack = tmpV;



    tmpV.x = (floatMatrix[0] * vUpperLeftFront.x) +
               (floatMatrix[4] * vUpperLeftFront.y) +
               (floatMatrix[8] * vUpperLeftFront.z) +
               floatMatrix[12];
    tmpV.y = (floatMatrix[1] * vUpperLeftFront.x) +
               (floatMatrix[5] * vUpperLeftFront.y) +
               (floatMatrix[9] * vUpperLeftFront.z) +
               floatMatrix[13];
    tmpV.z = (floatMatrix[2] * vUpperLeftFront.x) +
               (floatMatrix[6] * vUpperLeftFront.y) +
               (floatMatrix[10] * vUpperLeftFront.z) +
               floatMatrix[14];

    vUpperLeftFront = tmpV;

}

Проблема в том, что вращение не рассчитано правильно.. я не знаю, почему..

Мне нужна помощь, чтобы решить эту проблему и правильно вычислить вращение obb.

Пример содержимого переменных:

floatMatrix[0] = -7.91465e-008
floatMatrix[1] = -0.847687 
floatMatrix[2] = -0.936392 
floatMatrix[3] = -0.936329 
floatMatrix[4] = 1.81066 
floatMatrix[5] = -3.70536e-008 
floatMatrix[6] = -4.0931e-008 
floatMatrix[7] = -4.09282e-008
floatMatrix[8] = 0 
floatMatrix[9] = 2.2605
floatMatrix[10] = -0.351147
floatMatrix[11] = -0.351123
floatMatrix[12] = 1.0864
floatMatrix[13] = -7.68569
floatMatrix[14] = 45.4257
floatMatrix[15] = 45.6226

vLowerLeftFront: (-727.46, 84.64, 273.49)
vUpperRightBack: (-459.98, -19.68, 19.6)
Теги:
glm-math

1 ответ

1
Лучший ответ

Затем для каждого кадра обновляем obb (восемь углов), умножая на матрицу modelViewProjection.

Эта комбинация матриц преобразует вершины из пространства модели, в мировое пространство (это, вероятно, то, что вы хотите), затем в пространство камеры, а затем, наконец, для клипа, что совсем не очень полезно.

Умножать модельную матрицу только для преобразования координат модели в мировые координаты.

  • 0
    Спасибо! в цель! проблема решить.

Ещё вопросы

Сообщество Overcoder
Наверх
Меню