Skip to content

Commit

Permalink
feat(focus): now distance not affected by scale
Browse files Browse the repository at this point in the history
  • Loading branch information
yyc-git authored and AmyOrz committed Feb 23, 2019
1 parent f9e3511 commit c476be3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 27 deletions.
1 change: 1 addition & 0 deletions .cz-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module.exports = {
],

scopes: [
{ name: "focus" },
{ name: "scene-view" },
{ name: "scene-tree" },
{ name: "left-header" },
Expand Down
28 changes: 4 additions & 24 deletions src/core/utils/engine/job/init/initHotKeysJob/FocusUtils.re
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
let _setArcballCameraControllerFocusRelatedAttribute =
(arcballCameraController, (distance, target), engineState) => {
Js.log(distance);

(arcballCameraController, (distance, target), engineState) =>
engineState
|> ArcballCameraEngineService.setArcballCameraControllerTarget(
arcballCameraController,
Expand All @@ -11,14 +9,6 @@ let _setArcballCameraControllerFocusRelatedAttribute =
distance,
arcballCameraController,
);
};

let _getTargetGameObjectMaxScale = (targetGameObjectTransform, engineState) => {
let (scaleX, scaleY, scaleZ) =
engineState |> TransformEngineService.getScale(targetGameObjectTransform);

Js.Math.max_float(scaleX, scaleY) |> Js.Math.max_float(scaleZ);
};

let _buildAllPointsAndLocalToWolrdMatrices = (targetGameObject, engineState) =>
engineState
Expand Down Expand Up @@ -50,16 +40,13 @@ let _calcGeometrySphereCenterAndRadius = (targetGameObject, engineState) => {
AABBShapeUtils.setFromAllPointsAndLocalToWolrdMatrices(
_buildAllPointsAndLocalToWolrdMatrices(targetGameObject, engineState),
);

let center = AABBShapeUtils.getCenter(aabb);

(center, AABBShapeUtils.calcRadiusOfAABB(aabb, center));
};

let _calcArcballCameraControllerDistance =
(distance, targetGameObjectTransform, engineState) =>
_getTargetGameObjectMaxScale(targetGameObjectTransform, engineState)
*. distance
*. 2.5;
let _calcArcballCameraControllerDistance = distance => distance *. 2.5;

let setEditorCameraFocusTargetGameObject =
(editCamera, targetGameObject, editorState, engineState) => {
Expand Down Expand Up @@ -103,14 +90,7 @@ let setEditorCameraFocusTargetGameObject =

_setArcballCameraControllerFocusRelatedAttribute(
editorCameraArcballControllerComponent,
(
engineState
|> _calcArcballCameraControllerDistance(
radius,
targetGameObjectTransform,
),
center,
),
(_calcArcballCameraControllerDistance(radius), center),
engineState,
);
};
6 changes: 3 additions & 3 deletions test/integration/job/initHotKeysJob_test.re
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ let _ =
{|
calc currentSceneTreeNode's all children and its self->aabb;
use aabb's center as arcball camera controller target;
use aabb's radius * max scale of target gameObject * factor as arcball camera controller distance;
use aabb's radius * factor as arcball camera controller distance;
|},
() => {
let _getDistance = ((editorState, engineState)) =>
Expand Down Expand Up @@ -218,7 +218,7 @@ let _ =
_getDistance |> StateLogicService.getStateToGetData,
_getTarget |> StateLogicService.getStateToGetData,
)
|> expect == (67.708, ((-1.5), 0., 0.));
|> expect == (22.569, ((-1.5), 0., 0.));
});

test("test the currentSceneTreeNode is scene children", () => {
Expand Down Expand Up @@ -254,7 +254,7 @@ let _ =
_getDistance |> StateLogicService.getStateToGetData,
_getTarget |> StateLogicService.getStateToGetData,
)
|> expect == (12.437, (2., 0., 0.));
|> expect == (4.146, (2., 0., 0.));
});
},
)
Expand Down

0 comments on commit c476be3

Please sign in to comment.