vengi
vengi copied to clipboard
VOXEDIT: animation mode guizmo behaves weird after translating the node
if the node is not at 0,0,0 the bounding box is not rendered correctly and rotations are broken.
This is assembling the vertices
First perform the rotation in local mode - then apply the OBB translation.
glm::vec3 vecs[8] = {
glm::vec3(-1.0f, 1.0f, 1.0f), glm::vec3(-1.0f, -1.0f, 1.0f),
glm::vec3( 1.0f, 1.0f, 1.0f), glm::vec3( 1.0f, -1.0f, 1.0f),
glm::vec3(-1.0f, 1.0f, -1.0f), glm::vec3(-1.0f, -1.0f, -1.0f),
glm::vec3( 1.0f, 1.0f, -1.0f), glm::vec3( 1.0f, -1.0f, -1.0f)
};
const glm::vec3& halfWidth = obb.extents();
const glm::vec3& center = obb.origin();
for (size_t i = 0; i < lengthof(vecs); ++i) {
addVertex(glm::vec3(obb.rotation() * glm::vec4(vecs[i] * halfWidth, 1.0f)) + center);
}
This is how I create the OBB
const glm::vec3 &extents = glm::vec3(region.getDimensionsInVoxels()) / 2.0f;
const glm::vec3 ¢er = transform.translation() + extents;
const glm::mat4 &matrix = transform.matrix();
return math::OBB<float>(center, extents, matrix);
the OBB constructor just takes the rotation part of the transform matrix:
/**
* @brief Construct a new OBB object
*
* @param origin The position
* @param extents The half size
* @param rotation The rotation of the object (the translation is already part of the position)
*/
OBB(const Vec &origin, const Vec &extents, const glm::mat3x3 &rotation)
: _extents(extents), _origin(origin), _rotation(rotation) {
_inv = glm::inverse(_rotation);
}
Should modify the local transform and update the global transform afterwards.
should be fixed now.