Skip to content

Commit

Permalink
feat(scene-view): "rotation gizmo": now xz, yz circle can work
Browse files Browse the repository at this point in the history
  • Loading branch information
yyc-git committed Feb 7, 2019
1 parent cdbe203 commit a12c77b
Show file tree
Hide file tree
Showing 4 changed files with 276 additions and 119 deletions.
Original file line number Diff line number Diff line change
@@ -1,39 +1,45 @@
/* open ShapeType; */
/*
let _computeTotalAngle = (dragStartPoint, intersectXYPlanePoint, centerPoint) =>
(
Vector3Service.dot(
Wonderjs.Vector3Service.sub(
Wonderjs.Vector3Type.Float,
dragStartPoint,
centerPoint,
)
|> Wonderjs.Vector3Service.normalize,
Wonderjs.Vector3Service.sub(
Wonderjs.Vector3Type.Float,
intersectXYPlanePoint,
centerPoint,
)
|> Wonderjs.Vector3Service.normalize,
)
|> Js.Math.acos
)
*. AngleService.getRadToDeg(); */

let _computeTotalAngle =
let _computeXYPlaneTotalAngle =
(
(localDragStartPointX, localDragStartPointY, _),
(localIntersectXYPlanePointX, localIntersectXYPlanePointY, _),
(localIntersectPlanePointX, localIntersectPlanePointY, _),
) =>
Js.Math.atan2(
~x=localIntersectXYPlanePointX,
~y=localIntersectXYPlanePointY,
~x=localIntersectPlanePointX,
~y=localIntersectPlanePointY,
(),
)
*. AngleService.getRadToDeg()
-. Js.Math.atan2(~x=localDragStartPointX, ~y=localDragStartPointY, ())
*. AngleService.getRadToDeg();

let _computeXZPlaneTotalAngle =
(
(localDragStartPointX, _, localDragStartPointZ),
(localIntersectPlanePointX, _, localIntersectPlanePointZ),
) =>
Js.Math.atan2(
~x=localIntersectPlanePointZ,
~y=localIntersectPlanePointX,
(),
)
*. AngleService.getRadToDeg()
-. Js.Math.atan2(~x=localDragStartPointZ, ~y=localDragStartPointX, ())
*. AngleService.getRadToDeg();

let _computeYZPlaneTotalAngle =
(
(_, localDragStartPointY, localDragStartPointZ),
(_, localIntersectPlanePointY, localIntersectPlanePointZ),
) =>
Js.Math.atan2(
~x=localIntersectPlanePointY,
~y=localIntersectPlanePointZ,
(),
)
*. AngleService.getRadToDeg()
-. Js.Math.atan2(~x=localDragStartPointY, ~y=localDragStartPointZ, ())
*. AngleService.getRadToDeg();

let _computeNeedRotateAngle = (totalAngle, editorState) =>
totalAngle
-. (
Expand Down Expand Up @@ -142,6 +148,74 @@ let _rotateCurrentSceneTreeNodeAndWholeRotationGizmo =
(angle, axis, center, position),
); */

let _affectGizmo =
(
ray,
(plane, planeLocalAxis),
computeTotalAngleFunc,
editorState,
engineState,
) => {
let (totalAngle, needRotateAngle) =
switch (RayUtils.checkIntersectPlane(plane, ray)) {
| None =>
/* TODO test */
WonderLog.Log.print("not find intersected point!!! 00000000") |> ignore;

(
AngleRotationGizmoSceneViewEditorService.getLastTotalAngle(
editorState,
),
0.,
);
| Some(intersectPlanePoint) =>
let localToWorldMatrixTypeArray =
TransformGameObjectEngineService.getLocalToWorldMatrixTypeArray(
SceneTreeEditorService.unsafeGetCurrentSceneTreeNode(editorState),
engineState,
);

let dragStartPoint =
AngleRotationGizmoSceneViewEditorService.unsafeGetDragStartPoint(
editorState,
);

let totalAngle =
computeTotalAngleFunc(
CoordinateUtils.convertPosFromWorldToLocalCoordSystem(
dragStartPoint,
localToWorldMatrixTypeArray,
engineState,
),
CoordinateUtils.convertPosFromWorldToLocalCoordSystem(
intersectPlanePoint,
localToWorldMatrixTypeArray,
engineState,
),
);

(Some(totalAngle), _computeNeedRotateAngle(totalAngle, editorState));
};

WonderLog.Log.printJson((
"(totalAngle, needRotateAngle): ",
(totalAngle, needRotateAngle),
))
|> ignore;

let editorState =
editorState
|> AngleRotationGizmoSceneViewEditorService.setLastTotalAngle(totalAngle);

_rotateCurrentSceneTreeNodeAndWholeRotationGizmo(
(needRotateAngle, planeLocalAxis),
editorState,
engineState,
);

(editorState, engineState);
};

let affectRotationGizmo = (event, (editorState, engineState)) => {
let cameraGameObject =
SceneViewEditorService.unsafeGetEditCamera(editorState);
Expand All @@ -156,88 +230,41 @@ let affectRotationGizmo = (event, (editorState, engineState)) => {
SelectRotationGizmoSceneViewEditorService.isXYCircleGizmoSelected(
editorState,
) ?
{
let plane =
CircleRotationGizmosUtils.buildXYPlane(editorState, engineState);

let (totalAngle, needRotateAngle) =
switch (RayUtils.checkIntersectPlane(plane, ray)) {
| None =>
/* TODO test */
WonderLog.Log.print("not find intersected point!!! 00000000")
|> ignore;

(
AngleRotationGizmoSceneViewEditorService.getLastTotalAngle(
editorState,
),
0.,
);
| Some(intersectXYPlanePoint) =>
let localToWorldMatrixTypeArray =
TransformGameObjectEngineService.getLocalToWorldMatrixTypeArray(
SceneTreeEditorService.unsafeGetCurrentSceneTreeNode(
editorState,
),
engineState,
);

let dragStartPoint =
AngleRotationGizmoSceneViewEditorService.unsafeGetDragStartPoint(
editorState,
);

/* let centerPoint =
CircleRotationGizmosUtils.getCenterPoint(
editorState,
engineState,
); */

let totalAngle =
_computeTotalAngle(
CoordinateUtils.convertPosFromWorldToLocalCoordSystem(
dragStartPoint,
localToWorldMatrixTypeArray,
engineState,
),
CoordinateUtils.convertPosFromWorldToLocalCoordSystem(
intersectXYPlanePoint,
localToWorldMatrixTypeArray,
engineState,
),
/* centerPoint, */
);

(
Some(totalAngle),
_computeNeedRotateAngle(totalAngle, editorState),
);
};

WonderLog.Log.printJson((
"(totalAngle, needRotateAngle): ",
(totalAngle, needRotateAngle),
))
|> ignore;

let editorState =
editorState
|> AngleRotationGizmoSceneViewEditorService.setLastTotalAngle(
totalAngle,
);

_rotateCurrentSceneTreeNodeAndWholeRotationGizmo(
_affectGizmo(
ray,
(
CircleRotationGizmosUtils.buildXYPlane(editorState, engineState),
CircleRotationGizmosUtils.getXYPlaneLocalAxis(),
),
_computeXYPlaneTotalAngle,
editorState,
engineState,
) :
SelectRotationGizmoSceneViewEditorService.isXZCircleGizmoSelected(
editorState,
) ?
_affectGizmo(
ray,
(
needRotateAngle,
/* plane.normal, */
CircleRotationGizmosUtils.getXYPlaneLocalAxis(),
/* CircleRotationGizmosUtils.getCenterPoint(editorState, engineState), */
CircleRotationGizmosUtils.buildXZPlane(editorState, engineState),
CircleRotationGizmosUtils.getXZPlaneLocalAxis(),
),
_computeXZPlaneTotalAngle,
editorState,
engineState,
);

(editorState, engineState);
} :
(editorState, engineState);
) :
SelectRotationGizmoSceneViewEditorService.isYZCircleGizmoSelected(
editorState,
) ?
_affectGizmo(
ray,
(
CircleRotationGizmosUtils.buildYZPlane(editorState, engineState),
CircleRotationGizmosUtils.getYZPlaneLocalAxis(),
),
_computeYZPlaneTotalAngle,
editorState,
engineState,
) :
(editorState, engineState);
};
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ let _buildPlane = (axisOfPlane, centerPoint, editorState, engineState) => {

let getXYPlaneLocalAxis = () => (0., 0., 1.);

let getXZPlaneLocalAxis = () => (0., 1., 0.);

let getYZPlaneLocalAxis = () => (1., 0., 0.);


let getXAxisOfPlane = (editorState, engineState) => {
let (xAxis, _, _) =
TransformGameObjectEngineService.getLocalToWorldMatrixTypeArray(
Expand Down Expand Up @@ -82,4 +87,20 @@ let buildXYPlane = (editorState, engineState) =>
getCenterPoint(editorState, engineState),
editorState,
engineState,
);

let buildXZPlane = (editorState, engineState) =>
_buildPlane(
getYAxisOfPlane(editorState, engineState),
getCenterPoint(editorState, engineState),
editorState,
engineState,
);

let buildYZPlane = (editorState, engineState) =>
_buildPlane(
getXAxisOfPlane(editorState, engineState),
getCenterPoint(editorState, engineState),
editorState,
engineState,
);
Loading

0 comments on commit a12c77b

Please sign in to comment.