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

Function GetScale

Source/Editors/map_editor.cpp:3132–3230  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3130}
3131
3132static vec3 GetScale(const LineSegment& mouseray, vec3* trans, bool snapping_enabled, const vec3& cam_moved,
3133 const ControlEditorInfo* control_editor_info, Tool* tool_, Object* object_, const Box& box_) {
3134 static const float SCALE_SNAP_INCR = 1.50f; // incr whenever new size = 1.25 * old size
3135 if (trans) {
3136 *trans = vec3(0.0f);
3137 }
3138 vec3 new_clicked_point;
3139 vec3 old_clicked_point;
3140 vec3 original_click_dir = normalize(control_editor_info->start_mouseray_.end - control_editor_info->start_mouseray_.start);
3141 if (tool_->mode == SCALE_NORMAL) {
3142 vec3 mouseray_dir = normalize(mouseray.end - mouseray.start);
3143 RayLineClosestPoint(mouseray.start, mouseray_dir, tool_->center, -control_editor_info->basis_.facing, &new_clicked_point);
3144 RayLineClosestPoint(control_editor_info->start_cam_pos, original_click_dir, tool_->center, -control_editor_info->basis_.facing, &old_clicked_point);
3145 } else if (tool_->mode == SCALE_PLANE) {
3146 vec3 mouseray_dir = normalize(mouseray.end - mouseray.start);
3147 float to_dist = RayPlaneIntersection(mouseray.start, mouseray_dir, tool_->center, -control_editor_info->basis_.facing);
3148 if (to_dist > 0.0f) {
3149 new_clicked_point = mouseray.start + to_dist * mouseray_dir;
3150 } else {
3151 LOG_ASSERT(false);
3152 return vec3(1.0f);
3153 }
3154 to_dist = RayPlaneIntersection(control_editor_info->start_cam_pos, original_click_dir, tool_->center, -control_editor_info->basis_.facing);
3155 if (to_dist > 0.0f) {
3156 old_clicked_point = control_editor_info->start_cam_pos + to_dist * original_click_dir;
3157 } else {
3158 LOG_ASSERT(false);
3159 return vec3(1.0f);
3160 }
3161 }
3162
3163 vec3 initial_rel_point;
3164 vec3 scale;
3165 if (tool_->mode == SCALE_WHOLE) {
3166 Camera* cam = ActiveCameras::Get();
3167 vec3 cam_facing = cam->GetFacing();
3168 vec3 center = tool_->center;
3169 vec3 mouseray_dir = normalize(mouseray.end - mouseray.start);
3170 float t = RayPlaneIntersection(mouseray.start, mouseray_dir, center, cam_facing);
3171 vec3 curr_mouse_on_plane = mouseray.start + mouseray_dir * t;
3172 float t3 = RayPlaneIntersection(control_editor_info->start_cam_pos, original_click_dir, center, cam_facing);
3173 vec3 orig_mouse_on_plane = control_editor_info->start_cam_pos + original_click_dir * t3;
3174 float length_real_old = length(orig_mouse_on_plane - center);
3175 float length_new = length(curr_mouse_on_plane - center);
3176
3177 vec3 cam_up = cam->GetUpVector();
3178 vec3 cam_right = cross(cam_facing, cam_up);
3179 mat4 old_scale;
3180 old_scale.SetUniformScale(length_real_old);
3181 mat4 new_scale;
3182 new_scale.SetUniformScale(length_new);
3183 mat4 circle_transform;
3184 circle_transform.SetColumn(0, cam_right);
3185 circle_transform.SetColumn(1, cam_up);
3186 circle_transform.SetColumn(2, cam_facing);
3187 circle_transform.SetTranslationPart(center + cam_moved);
3188 DebugDraw::Instance()->AddCircle(circle_transform * old_scale, vec4(0.0f, 0.0f, 0.0f, 0.5f), _delete_on_update, _DD_XRAY);
3189 DebugDraw::Instance()->AddCircle(circle_transform * new_scale, vec4(1.0f, 1.0f, 1.0f, 0.5f), _delete_on_update, _DD_XRAY);

Callers 12

StartMouseTransformationFunction · 0.85
GetMouseTransformationFunction · 0.85
GetDescMethod · 0.85
UpdateDetailScaleMethod · 0.85
CreatePhysicsShapeMethod · 0.85
LoadModelMethod · 0.85
GetDescMethod · 0.85
DrawMethod · 0.85
DrawEditorLabelMethod · 0.85
UpdateCollisionShapeMethod · 0.85
DrawMethod · 0.85

Calls 15

RayLineClosestPointFunction · 0.85
RayPlaneIntersectionFunction · 0.85
GetFacingMethod · 0.80
SetUniformScaleMethod · 0.80
SetTranslationPartMethod · 0.80
GetRotationMethod · 0.80
vec3Class · 0.50
normalizeFunction · 0.50
GetFunction · 0.50
lengthFunction · 0.50
crossFunction · 0.50
vec4Class · 0.50

Tested by

no test coverage detected