MCPcopy Create free account
hub / github.com/WolfireGames/overgrowth / GetRotation

Function GetRotation

Source/Editors/map_editor.cpp:3232–3338  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3230}
3231
3232static quaternion GetRotation(const LineSegment& mouseray, bool snapping_enabled, const vec3& cam_moved, const ControlEditorInfo* control_editor_info, Tool* tool_, Object* object_, const Box& box_, GameCursor* cursor) {
3233 static const float ANGLE_SNAP_INCR = 30;
3234
3235 vec3 around = tool_->around;
3236 float angle = 0.0f;
3237
3238 vec3 dir = normalize(mouseray.end - mouseray.start);
3239
3240 vec3 a, b, p, n;
3241 vec3 new_point;
3242
3243 quaternion rotation;
3244
3245 if (tool_->mode == ROTATE_SPHERE) {
3246 int* mouse_pos = Input::Instance()->getMouse().pos_;
3247 Camera* cam = ActiveCameras::Get();
3248
3249 float sensitivity = 0.1f;
3250 vec3 temp_radius = box_.dims * 0.5f;
3251 temp_radius *= object_->GetScale();
3252 sensitivity *= distance(tool_->center, cam->GetPos()) / length(temp_radius);
3253
3254 angle = (float)(mouse_pos[0] - tool_->old_mousex);
3255 angle *= sensitivity;
3256 tool_->old_mousex = mouse_pos[0];
3257 vec4 x_rot(cam->GetUpVector(), angle / 180.0f * PI_f);
3258 mat4 mat;
3259 quaternion x_rot_quat(x_rot);
3260
3261 angle = (float)(mouse_pos[1] - tool_->old_mousey);
3262 angle *= sensitivity;
3263 angle *= -1.0f;
3264 tool_->old_mousey = mouse_pos[1];
3265 vec4 y_rot(cross(cam->GetUpVector(), cam->GetFacing()), angle / 180.0f * PI_f);
3266 quaternion y_rot_quat(y_rot);
3267 tool_->trackball_accumulate = x_rot_quat * y_rot_quat * tool_->trackball_accumulate;
3268 rotation = tool_->trackball_accumulate;
3269 }
3270 if (tool_->mode == ROTATE_CIRCLE) {
3271 n = -control_editor_info->basis_.facing;
3272 p = tool_->center;
3273
3274 float to_dist = RayPlaneIntersection(mouseray.start, dir, p, n);
3275 if (to_dist < 0) {
3276 return quaternion();
3277 }
3278 new_point = mouseray.start + to_dist * dir;
3279
3280 to_dist = RayPlaneIntersection(control_editor_info->start_mouseray_.start, normalize(control_editor_info->start_mouseray_.end - control_editor_info->start_mouseray_.start), p, n);
3281 if (to_dist < 0) {
3282 return quaternion();
3283 }
3284 vec3 old_point = control_editor_info->start_mouseray_.start + to_dist * normalize(control_editor_info->start_mouseray_.end - control_editor_info->start_mouseray_.start);
3285
3286 a = normalize(new_point - p);
3287 b = normalize(old_point - p);
3288
3289 float a_dot_b = dot(a, b);

Callers 15

StartMouseTransformationFunction · 0.85
GetMouseTransformationFunction · 0.85
MakeBulletObjectMethod · 0.85
MovedMethod · 0.85
GetDescMethod · 0.85
CreatePhysicsShapeMethod · 0.85
lineCheckMethod · 0.85
UpdateCollisionShapeMethod · 0.85
InitRelMatsMethod · 0.85

Calls 15

RayPlaneIntersectionFunction · 0.85
GetSignFunction · 0.85
GetFacingMethod · 0.80
ProjectPointMethod · 0.80
normalizeFunction · 0.50
GetFunction · 0.50
distanceFunction · 0.50
lengthFunction · 0.50
crossFunction · 0.50
quaternionClass · 0.50
dotFunction · 0.50
atan2fFunction · 0.50

Tested by

no test coverage detected