mirror of
https://github.com/Linloir/SceneEditor.git
synced 2025-12-18 16:08:11 +08:00
[CORE][FIX] Surface sticking fixed
This commit is contained in:
parent
1e92f8922d
commit
281c424b87
@ -567,21 +567,20 @@ void SceneViewer::moveOperatingObject(const Ray& ray) {
|
|||||||
// Move the object so that the bottom center of the object is at the hit point
|
// Move the object so that the bottom center of the object is at the hit point
|
||||||
else if (_stickToSurface) {
|
else if (_stickToSurface) {
|
||||||
// Set the bottom center of the model at local origin
|
// Set the bottom center of the model at local origin
|
||||||
glm::vec3 bottomCenter = _operatingObject->boundary().bottomCenterPoint();
|
glm::vec3 bottomCenter = _operatingObject->modelMatrix() * glm::vec4(_operatingObject->model()->boundBox().bottomCenterPoint(), 1.0f);
|
||||||
glm::vec3 modelCenter = _operatingObject->modelMatrix() * glm::vec4(glm::vec3(0.0f), 1.0f); // model center in world space
|
glm::vec3 modelCenter = _operatingObject->modelMatrix() * glm::vec4(glm::vec3(0.0f), 1.0f); // model center in world space
|
||||||
|
|
||||||
// Rotate the model to align with the surface normal
|
// Rotate the model to align with the surface normal
|
||||||
glm::vec3 normal = _hitRecord.normal();
|
glm::vec3 normal = _hitRecord.normal();
|
||||||
glm::vec3 up = glm::vec3(0.0f, 1.0f, 0.0f);
|
glm::vec3 up = glm::vec3(0.0f, 1.0f, 0.0f);
|
||||||
glm::vec3 axis = glm::cross(up, normal);
|
glm::vec3 axis = glm::normalize(glm::cross(up, normal));
|
||||||
float angle = glm::acos(glm::dot(up, normal));
|
float deg = glm::degrees(glm::acos(glm::dot(up, normal)));
|
||||||
_operatingObject->setRotation(axis, angle);
|
_operatingObject->setRotation(axis, deg);
|
||||||
|
|
||||||
// Move the model to the hit point
|
// Move the model to the hit point
|
||||||
glm::vec3 hitPoint = _hitRecord.position();
|
glm::vec3 target = _hitRecord.position();
|
||||||
glm::vec3 newCenter = hitPoint + normal * (modelCenter.y - bottomCenter.y);
|
|
||||||
|
|
||||||
// Move the model to the new center
|
glm::vec3 newCenter = target + modelCenter - bottomCenter;
|
||||||
_operatingObject->setPosition(newCenter);
|
_operatingObject->setPosition(newCenter);
|
||||||
|
|
||||||
// Update the boundary
|
// Update the boundary
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user