Как получить мировое положение вершиныC++

Программы на C++. Форум разработчиков
Ответить
Anonymous
 Как получить мировое положение вершины

Сообщение Anonymous »

Я пытаюсь получить мировую позицию моей ограничивающей рамки вершины.

Код: Выделить всё

void Container::GetTransformedBoundingBoxDimensions2WithProjection(float* minimum_x, float* minimum_y, float* minimum_z, float* maximum_x, float* maximum_y, float* maximum_z, glm::mat4 projectionMatrix)
{
std::vector childContainers;
std::vector vertices;

glm::mat4 transformationMatrixRoot = this->GetTransformationMatrixPointer();
glm::mat4 combinedMatrix = projectionMatrix * wavefrontAccess->GetViewMatrix() * transformationMatrixRoot;

GLfloat min_x = 999999, max_x = -999999;
GLfloat min_y = 999999, max_y = -999999;
GLfloat min_z = 999999, max_z = -999999;

// Process vertices of the current container
if (Geom != nullptr)
{
vertices = Geom->GetVertices();
for (const auto& vertex : vertices)
{
glm::vec4 transformedVertex = combinedMatrix * glm::vec4(vertex.x, vertex.y, vertex.z, 1.0f);

min_x = std::min(min_x, transformedVertex.x);
max_x = std::max(max_x, transformedVertex.x);
min_y = std::min(min_y, transformedVertex.y);
max_y = std::max(max_y, transformedVertex.y);
min_z = std::min(min_z, transformedVertex.z);
max_z = std::max(max_z, transformedVertex.z);
}
}

// Retrieve active child containers
if (this->GetChildContainerCount() > 0)
{
childContainers = GetAllChildSubContainersActiveOnly();
}

// Process vertices of each active child container
for (Container* child : childContainers)
{
if (child->GetActive())
{
glm::mat4 transformationMatrixChild = child->GetTransformationMatrix();
glm::mat4 combinedMatrixChild = projectionMatrix * wavefrontAccess->GetViewMatrix() * transformationMatrixChild;

if (child->Geom != nullptr)
{
std::vector childVertices = child->Geom->GetVertices();
for (const auto& vertex : childVertices)
{
glm::vec4 transformedVertex = combinedMatrixChild * glm::vec4(vertex.x, vertex.y, vertex.z, 1.0f);
min_x = std::min(min_x, transformedVertex.x);
max_x = std::max(max_x, transformedVertex.x);
min_y = std::min(min_y, transformedVertex.y);
max_y = std::max(max_y, transformedVertex.y);
min_z = std::min(min_z, transformedVertex.z);
max_z = std::max(max_z, transformedVertex.z);
}
}
}
}

// Set the calculated bounding box dimensions
*minimum_x = min_x;
*minimum_y = min_y;
*minimum_z = min_z;
*maximum_x = max_x;
*maximum_y = max_y;
*maximum_z = max_z;
}
Мои окончательные положения вершин неверны.


Подробнее здесь: https://stackoverflow.com/questions/791 ... -of-vertex
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C++»