vengi icon indicating copy to clipboard operation
vengi copied to clipboard

VOXEDIT: animation mode guizmo behaves weird after translating the node

Open mgerhardy opened this issue 1 year ago • 1 comments

if the node is not at 0,0,0 the bounding box is not rendered correctly and rotations are broken. Bildschirmfoto vom 2022-08-09 17-40-45 Bildschirmfoto vom 2022-08-09 17-40-31 Bildschirmfoto vom 2022-08-09 17-40-25

mgerhardy avatar Aug 09 '22 15:08 mgerhardy

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 &center = 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);
	}

mgerhardy avatar Aug 09 '22 16:08 mgerhardy

Should modify the local transform and update the global transform afterwards.

mgerhardy avatar Sep 01 '22 09:09 mgerhardy

should be fixed now.

mgerhardy avatar Sep 11 '22 10:09 mgerhardy