Skip to content
Snippets Groups Projects
Commit 2d2c4e1c authored by Martin Štourač's avatar Martin Štourač
Browse files

added object rotation around world y-axis

parent 9a35d6b1
No related branches found
No related tags found
No related merge requests found
......@@ -29,6 +29,7 @@ public:
// virtual void setUpVec();
void setStep(float dt);
float getSpeed() const { return speed; }
void setSpeed(float new_speed);
void teleport(glm::vec3 new_position) { bound_frame->setPosVec(new_position); }
......
......@@ -11,10 +11,13 @@
#include <unordered_set>
#include <string>
#include <osi/mouse.hpp>
class ObjectController : public Controller
{
public:
using Controller::Controller;
void mouse_rotate(const osi::Mouse &mouse);
};
......
#include <gfx/obj_control.hpp>
void ObjectController::mouse_rotate(const osi::Mouse &mouse)
{
// check for start at object
if (!mouse.down().contains("MouseLeft"))
return;
glm::i32vec2 offset = mouse.pos_delta();
float xoffset = static_cast<float>(offset.x);
auto inv_rotation = glm::inverse(bound_frame->getRotationMat());
glm::vec3 inv_rot_y = glm::column(inv_rotation, 1);
bound_frame->rotateRotationQuat(glm::angleAxis(xoffset * step, inv_rot_y));
}
\ No newline at end of file
......@@ -63,6 +63,7 @@ struct Simulator : public osi::Simulator
void manage_selection(node_ptr nearest_node); // Not node tree compatible
void select_object();
void rotate_object();
void process_mouse();
private:
......
......@@ -134,7 +134,8 @@ Simulator::Simulator()
/* ROTATE FIRST OBJECT */
obj_controls[object_ctrl_type]->setFrame(scene[0]->getFrame());
obj_controls[object_ctrl_type]->rotate(glm::vec3(0.0f, 50.0f, 0.0f));
obj_controls[object_ctrl_type]->rotate(glm::vec3(0.0f, 50.0f, 0.0f));
obj_controls[object_ctrl_type]->rotate(glm::vec3(45.0f, 0.0f, 0.0f));
/* SET ACTIVE CAMERA AND CONTROLLER TYPE
* ADD ACTIVE CAMERAS HERE. */
......@@ -476,6 +477,16 @@ void Simulator::select_object()
manage_selection(nearest_node);
}
void Simulator::rotate_object()
{
if (!selection)
return;
auto controller = obj_controls[object_ctrl_type];
controller->setFrame(selection->getFrame());
controller->setStep(timer().dt());
controller->mouse_rotate(mouse());
}
void Simulator::process_mouse()
{
cam_controls[active_camera_type]->process_mouse(mouse(), window(), editor_running);
......@@ -488,7 +499,7 @@ void Simulator::process_mouse()
// happens in obj controller
break;
case state::rotate:
// happens in obj controller
rotate_object();
break;
default:
break;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment