/// <summary> /// Animate camera so that focusPoint moves to center of camera /// Camera target is also set to focusPoint /// </summary> public void AnimatePanFocus(Vector3f focusPoint, CoordSpace eSpace, float duration) { if (duration > 0 && ShowTargetDuringAnimations) { UseCamera.SetTargetVisible(true); } Vector3f focusPointS = (eSpace == CoordSpace.WorldCoords) ? UseScene.ToSceneP(focusPoint) : focusPoint; Vector3f startFocusS = UseScene.ToSceneP(UseCamera.GetTarget()); Action <float> tweenF = (t) => { Vector3f newTargetS = Vector3f.Lerp(startFocusS, focusPointS, t); UseCamera.Manipulator().PanFocusOnScenePoint(UseScene, UseCamera, newTargetS); }; if (duration > 0) { TweenAnimator anim = new TweenAnimator(tweenF, duration) { OnCompletedF = () => { UseCamera.SetTargetVisible(false); } }; UseScene.ObjectAnimator.Register(anim); } else { tweenF(1.0f); } }
public TransformSOChange(SceneObject target, Frame3f before, Frame3f after, CoordSpace coords) { this.so = target; this.before = before; this.after = after; this.space = coords; }
public TransformSOChange(SceneObject target, Frame3f newFrame, CoordSpace coords) { this.so = target; this.before = target.GetLocalFrame(coords); this.after = newFrame; this.space = coords; }
/// <summary> /// Assuming pointIn is in space eFrom of fromSO, transform to eTo /// </summary> public static Vector3f TransformTo(Vector3f pointIn, TransformableSO fromSO, CoordSpace eFrom, CoordSpace eTo) { // this is not the most efficient but we can optimize later! Frame3f tmp = new Frame3f(pointIn); return(TransformTo(tmp, fromSO, eFrom, eTo).Origin); }
public static void TranslateInFrame(TransformableSO so, Vector3f translate, CoordSpace eSpace = CoordSpace.ObjectCoords) { Frame3f f = so.GetLocalFrame(eSpace); f.Origin += translate; so.SetLocalFrame(f, eSpace); }
/// <summary> /// Animate camera so that focusPoint moves to center of camera, at distance distanceW along cam.Forward /// Camera target is also set to focusPoint /// </summary> public void AnimatePanZoomFocus(Vector3f focusPoint, CoordSpace eSpace, float distanceW, float duration) { if (duration > 0 && ShowTargetDuringAnimations) { UseCamera.SetTargetVisible(true); } Vector3f focusPointS = (eSpace == CoordSpace.WorldCoords) ? UseScene.ToSceneP(focusPoint) : focusPoint; Vector3f startFocusS = UseScene.ToSceneP(UseCamera.GetTarget()); float startDistW = UseCamera.GetPosition().Distance(UseCamera.GetTarget()); Action <float> tweenF = (t) => { float smooth_t = MathUtil.WyvillRise01(t); Vector3f newTargetS = Vector3f.Lerp(startFocusS, focusPointS, smooth_t); UseCamera.Manipulator().PanFocusOnScenePoint(UseScene, UseCamera, newTargetS); float curDist = UseCamera.GetPosition().Distance(UseCamera.GetTarget()); float toDist = MathUtil.Lerp(startDistW, distanceW, smooth_t); float dolly = toDist - curDist; UseCamera.Manipulator().SceneZoom(UseScene, UseCamera, -dolly); }; if (duration > 0) { TweenAnimator anim = new TweenAnimator(tweenF, duration) { OnCompletedF = () => { UseCamera.SetTargetVisible(false); } }; UseScene.ObjectAnimator.Register(anim); } else { tweenF(1.0f); } }
public static Frame3f GetSOLocalFrame(SceneObject so, CoordSpace eSpace) { if (eSpace == CoordSpace.SceneCoords) { // new code maps object frame up to scene // [TODO] this is not the most efficient approach! can at least get the object // frame directly, and avoid first local-to-obj xform Frame3f objF = Frame3f.Identity; Frame3f result = SceneTransforms.ObjectToScene(so, objF); // [RMS] old code that mapped up to world, and then down to scene // Problem with this code is that it is unstable - if scene-to-world xform changes, // then scene frame will numerically change. Which is a problem. //Frame3f sceneW = UnityUtil.GetGameObjectFrame(so.GetScene().RootGameObject, CoordSpace.WorldCoords); //Frame3f objW = UnityUtil.GetGameObjectFrame(so.RootGameObject, CoordSpace.WorldCoords); //Frame3f result = sceneW.ToFrame(objW); //// world coords have scene scale applied, we don't want that in scene coords //if (so.GetScene().GetSceneScale() != 1.0f) // result = result.Scaled(1.0f / so.GetScene().GetSceneScale()); return(result); } else { return(UnityUtil.GetGameObjectFrame(so.RootGameObject, eSpace)); } }
// same as above but does not post OnPointUpdated protected bool SetPointPosition_Internal(int id, Frame3f frameS, CoordSpace space) { if (space == CoordSpace.WorldCoords) { frameS = SceneTransforms.WorldToScene(this.Scene, frameS); } else if (space == CoordSpace.ObjectCoords) { frameS = SceneTransforms.ObjectToScene(TargetSO, frameS); } ControlPoint pt; if (GizmoPoints.TryGetValue(id, out pt) == false) { throw new Exception("MultiSurfacePointTool.SetPointPosition_Internal: point with id " + id + " does not exist!"); } // ignore tiny movements if (pt.currentFrameS.Origin.EpsilonEqual(frameS.Origin, 0.0001f)) { return(false); } pt.currentFrameS = frameS; if (pt.initialized == false) { initialize_point(pt); } return(true); }
/// <summary> /// Assuming pointIn is in space eFrom of fromSO, transform to eTo /// </summary> public static Vector3f TransformTo(Vector3f pointIn, SceneObject fromSO, CoordSpace eFrom, CoordSpace eTo) { // this is not the most efficient but we can optimize later! Frame3f f = new Frame3f(pointIn); Frame3f fTo = TransformTo(f, fromSO, eFrom, eTo); return(fTo.Origin); }
// same as LocalFrame, but LocalFrame may be tilted up/down, which we want to undo public virtual Frame3f GetLevelViewFrame(CoordSpace eSpace) { // otherwise we can't just set y to 0... Debug.Assert(eSpace == CoordSpace.WorldCoords); Frame3f viewF = UnityUtil.GetGameObjectFrame(ActiveCamera.GameObject(), eSpace); float fAngle = VRUtil.PlaneAngleSigned(Vector3f.AxisZ, viewF.Z, 1); return(new Frame3f(viewF.Origin, Quaternionf.AxisAngleD(Vector3f.AxisY, fAngle))); }
public TransformSOChange(SceneObject target, Frame3f before, Frame3f after, CoordSpace coords) { this.so = target; this.before = before; this.after = after; this.space = coords; this.scaleBefore = target.GetLocalScale(); this.scaleAfter = this.scaleBefore; }
public TransformSOChange(SceneObject target, Frame3f before, Frame3f after, CoordSpace coords, Vector3f scaleBefore, Vector3f scaleAfter) { this.so = target; this.before = before; this.after = after; this.space = coords; this.scaleBefore = scaleBefore; this.scaleAfter = scaleAfter; }
public TransformSOChange(SceneObject target, Vector3f newScale) { this.so = target; this.before = target.GetLocalFrame(CoordSpace.ObjectCoords); this.after = before; this.space = CoordSpace.ObjectCoords; this.scaleBefore = target.GetLocalScale(); this.scaleAfter = newScale; }
virtual public void SetLocalFrame(Frame3f newFrame, CoordSpace eSpace) { SceneUtil.SetSOLocalFrame(this, eSpace, newFrame); increment_timestamp(); if (OnTransformModified != null) { OnTransformModified(this); } }
public void SetLocalFrame(Frame3 newFrame, CoordSpace eSpace) { Debug.Assert(eSpace == CoordSpace.ObjectCoords); Frame3 updateFrame = objectFrame; curRotation = newFrame.Rotation; updateFrame.Rotation = curRotation * objectFrame.Rotation; updateFrame.Origin = newFrame.Origin; target.SetLocalFrame(updateFrame, eSpace); }
// // TransformableSceneObject impl // public Frame3 GetLocalFrame(CoordSpace eSpace) { if (eSpace == CoordSpace.SceneCoords) { return(parentScene.WorldToSceneF(new Frame3(RootGameObject.transform, false))); } else { return(MathUtil.GetGameObjectFrame(RootGameObject, eSpace)); } }
override public void SetLocalFrame(Frame3f newFrame, CoordSpace eSpace) { Util.gDevAssert(eSpace == CoordSpace.ObjectCoords); Frame3f updateFrame = objectFrame; curRotation = newFrame.Rotation; updateFrame.Rotation = curRotation * objectFrame.Rotation; updateFrame.Origin = newFrame.Origin; target.SetLocalFrame(updateFrame, eSpace); }
/// <summary> /// Animate camera so that centerPt moves to center of camera, and height is visible. /// Camera target is also set to centerPt /// </summary> public void AnimateFitHeightToView(Vector3f centerPt, float height, CoordSpace eSpace, float duration) { if (eSpace != CoordSpace.WorldCoords) { height = UseScene.ToWorldDimension(height); } float fFitDistW = UseCamera.Manipulator().GetFitHeightCameraDistance(height); Vector3f focusPointW = (eSpace == CoordSpace.WorldCoords) ? centerPt : UseScene.ToWorldP(centerPt); AnimatePanZoomFocus(focusPointW, CoordSpace.WorldCoords, fFitDistW, duration); }
public override void AddIndicator(Indicator i) { base.AddIndicator(i); CoordSpace eSpace = i.InSpace; if (eSpace == CoordSpace.ObjectCoords || eSpace == CoordSpace.WorldCoords) { throw new Exception("SOSceneIndicatorSet.AddIndicator: only scene-space indicators not supported!"); } UnityUtil.AddChild(sceneParentGO, i.RootGameObject, false); }
public void UpdateSection(Frame3f frame, CoordSpace space) { if (space != CoordSpace.ObjectCoords) { frameL = SceneTransforms.TransformTo(frame, SO, space, CoordSpace.ObjectCoords); } else { frameL = frame; } update(); }
private static float[] Convert(float[] quat, CoordSpace coordSpace) { float[] res = new float[2]; if (coordSpace == CoordSpace.World) { quat = QuatUtils.Inverse(quat); } float[] forward = QuatUtils.TransformVecLH(quat, new float[] { 0f, 0f, 1f }); float lXZ = (float)Math.Sqrt(forward[0] * forward[0] + forward[2] * forward[2]); //Azimuth if (lXZ < 0.00001f) { res[0] = (float)Math.Sign(forward[0]) * (float)Math.PI; } else { res[0] = (float)Math.Asin((double)forward[0] / (double)lXZ); } if (forward[2] < 0) { res[0] = (float)Math.Sign(res[0]) * (float)Math.PI - res[0]; } //Elevation if (lXZ < 0.00001f) { res[0] = (float)(Math.PI * Math.Sign(forward[1])); } else { res[1] = (float)Math.Atan(forward[1] / lXZ); } if (coordSpace == CoordSpace.World) { res[0] = -res[0]; res[0] = -res[1]; } //Convert radians to degrees res[0] *= Mathf.Rad2Deg; res[1] *= Mathf.Rad2Deg; return(res); }
public static Frame3f GetGameObjectFrame(GameObject go, CoordSpace eSpace) { if (eSpace == CoordSpace.WorldCoords) { return(new Frame3f(go.transform.position, go.transform.rotation)); } else if (eSpace == CoordSpace.ObjectCoords) { return(new Frame3f(go.transform.localPosition, go.transform.localRotation)); } else { throw new ArgumentException("not possible without refernce to scene!"); } }
public static Frame3 GetGameObjectFrame(GameObject go, CoordSpace eSpace) { if (eSpace == CoordSpace.WorldCoords) { return(new Frame3(go.transform, false)); } else if (eSpace == CoordSpace.ObjectCoords) { return(new Frame3(go.transform, true)); } else { throw new ArgumentException("not possible without refernce to scene!"); } }
public RepositionPivotChangeOp(Frame3f toPivot, DMeshSO target, CoordSpace space = CoordSpace.ObjectCoords) { Util.gDevAssert(space != CoordSpace.WorldCoords); // not supported for now Target = target; toFrame = toPivot; this.space = space; if (space == CoordSpace.ObjectCoords) { initialFrame = Target.GetLocalFrame(CoordSpace.ObjectCoords); } else { initialFrame = Target.GetLocalFrame(CoordSpace.SceneCoords); } }
// should not use this anymore... public void PanFocus(Vector3f focusPoint, CoordSpace eSpace = CoordSpace.WorldCoords, float duration = 0.5f) { Vector3f focusPointW = (eSpace == CoordSpace.WorldCoords) ? focusPoint : UseScene.ToWorldP(focusPoint); // figure out the pan that we would apply to camera, then apply the delta to the scene Vector3f curPos = UseCamera.GetPosition(); Vector3f curDir = UseCamera.GetWorldFrame().Z; float fDist = Vector3.Dot((focusPointW - curPos), curDir); Vector3f newPos = focusPointW - fDist * curDir; Vector3f delta = curPos - newPos; StartCoroutine( SmoothTranslate(UseScene.RootGameObject.GetPosition() + delta, duration)); StartCoroutine( SmoothMoveTarget(focusPointW + delta, duration / 10.0f)); }
private static float[] Convert(float[] quat, CoordSpace coordSpace) { float[] res = new float[2]; if (coordSpace == CoordSpace.World) { quat = QuatUtils.Inverse(quat); } float[] forward = QuatUtils.TransformVecLH(quat, new float[] { 0f, 0f, 1f }); float[] right = QuatUtils.TransformVecLH(quat, new float[] { 1f, 0f, 0f }); float lf_XZ = (float)Math.Sqrt(forward[0] * forward[0] + forward[2] * forward[2]); float lr_XZ = (float)Math.Sqrt(right[0] * right[0] + right[2] * right[2]); //Tilt if (lr_XZ < 0.00001f) { res[0] = -(float)(Math.PI * Math.Sign(right[1])); } else { res[0] = -(float)Math.Atan(right[1] / lr_XZ); } //Elevation if (lf_XZ < 0.00001f) { res[0] = (float)(Math.PI * Math.Sign(forward[1])); } else { res[1] = (float)Math.Atan(forward[1] / lf_XZ); } if (coordSpace == CoordSpace.World) { res[0] = -res[0]; res[0] = -res[1]; } //Convert radians to degrees res[0] *= Mathf.Rad2Deg; res[1] *= Mathf.Rad2Deg; return(res); }
public void UpdateMeasurePoint(Vector3d point, CoordSpace eSpace, int nPointNum, bool isFixedPoint = true) { if (eSpace == CoordSpace.ObjectCoords) { throw new NotSupportedException("TwoPointMeasureTool.UpdateMeasurePoint"); } Vector3d pointS = (eSpace == CoordSpace.SceneCoords) ? point : scene.ToSceneP(point); int i = MathUtil.Clamp(nPointNum, 0, 1); setPointsS[i] = pointS; snappedPointsS[i] = setPointsS[i]; point_initialized[i] = true; if (isFixedPoint) { return; } // snap List <SceneObject> targets = (SpecificTargets != null) ? SpecificTargets : new List <SceneObject>(scene.SceneObjects); float fAvgSnapDist = 0; int avgcount = 0; foreach (var so in targets) { fAvgSnapDist += VRUtil.GetVRRadiusForVisualAngle(so.GetLocalFrame(CoordSpace.WorldCoords).Origin, scene.ActiveCamera.GetPosition(), snapThresholdAngle); avgcount++; } if (avgcount == 0) { return; } fAvgSnapDist /= avgcount; SORayHit nearestW; Vector3d pointW = (eSpace == CoordSpace.WorldCoords) ? point : scene.ToWorldP(point); if (SceneUtil.FindNearestPoint(targets, pointW, fAvgSnapDist, out nearestW, CoordSpace.WorldCoords)) { snappedPointsS[i] = scene.ToSceneP(nearestW.hitPos); } }
public Frame3 GetLocalFrame(CoordSpace eSpace) { Frame3 targetFrame = target.GetLocalFrame(eSpace); if (eSpace == CoordSpace.WorldCoords) { return(new Frame3(targetFrame.Origin, parentScene.RootGameObject.transform.rotation)); } else if (eSpace == CoordSpace.SceneCoords) { return(new Frame3(targetFrame.Origin, parentScene.RootGameObject.transform.localRotation)); } else { return(new Frame3(targetFrame.Origin, curRotation * Quaternion.identity)); } }
public static Frame3f GetGameObjectFrame(this MMDModel go, CoordSpace eSpace) { if (eSpace == CoordSpace.WorldCoords) { return(new Frame3f(go.Position, go.Rotation)); } else if (eSpace == CoordSpace.ObjectCoords) { //return new Frame3f(go.transform.localPosition, go.transform.localRotation); //Util.DebugWrite("ObjectCoords" + go.Rotation.ToString( ) ); return(new Frame3f(go.Position, go.Rotation)); } else { throw new ArgumentException("not possible without refernce to scene!"); } }
override public Frame3f GetLocalFrame(CoordSpace eSpace) { Frame3f targetFrame = target.GetLocalFrame(eSpace); if (eSpace == CoordSpace.WorldCoords) { return(new Frame3f(targetFrame.Origin, parentScene.RootGameObject.GetRotation())); } else if (eSpace == CoordSpace.SceneCoords) { return(new Frame3f(targetFrame.Origin, parentScene.RootGameObject.GetLocalRotation())); } else { return(new Frame3f(targetFrame.Origin, curRotation * Quaternionf.Identity)); } }
private static float[] Convert(float[] quat, CoordSpace coordSpace) { float[] res = new float[2]; if (coordSpace == CoordSpace.World) quat = QuatUtils.Inverse(quat); float[] forward = QuatUtils.TransformVecLH(quat, new float[] { 0f, 0f, 1f }); float lXZ = (float)Math.Sqrt(forward[0] * forward[0] + forward[2] * forward[2]); //Azimuth if (lXZ < 0.00001f) res[0] = (float)Math.Sign(forward[0]) * (float)Math.PI; else res[0] = (float)Math.Asin((double)forward[0] / (double)lXZ); if (forward[2] < 0) res[0] = (float)Math.Sign(res[0]) * (float)Math.PI - res[0]; //Elevation if (lXZ < 0.00001f) res[0] = (float)(Math.PI * Math.Sign(forward[1])); else res[1] = (float)Math.Atan(forward[1] / lXZ); if (coordSpace == CoordSpace.World) { res[0] = -res[0]; res[0] = -res[1]; } return res; }
/// <summary> /// Converts the rotation quaternion to tilt-elevation representation /// </summary> /// <returns>The tilt-elevation representation of the quaternion, {tilt, elevation}</returns> /// <param name="quat">The quaternion to convert</param> /// <param name="coordSpace">Use <c>CoordSpace.Body</c> to convert regarding to Device axes or /// <c>CoordSpace.World</c> to convert regarding to world axes</param> public static Vector2 Convert(Quaternion quat, CoordSpace coordspace = CoordSpace.Body) { float[] te = Convert(new float[] { quat.w, quat.x, quat.y, quat.z }, coordspace); return new Vector2(te[0], te[1]); }
private static float[] Convert(float[] quat, CoordSpace coordSpace) { float[] res = new float[2]; if (coordSpace == CoordSpace.World) quat = QuatUtils.Inverse(quat); float[] forward = QuatUtils.TransformVecLH(quat, new float[] { 0f, 0f, 1f }); float[] right = QuatUtils.TransformVecLH(quat, new float[] { 1f, 0f, 0f }); float lf_XZ = (float)Math.Sqrt(forward[0] * forward[0] + forward[2] * forward[2]); float lr_XZ = (float)Math.Sqrt(right[0] * right[0] + right[2] * right[2]); //Tilt if (lr_XZ < 0.00001f) res[0] = -(float)(Math.PI * Math.Sign(right[1])); else res[0] = -(float)Math.Atan(right[1] / lr_XZ); //Elevation if (lf_XZ < 0.00001f) res[0] = (float)(Math.PI * Math.Sign(forward[1])); else res[1] = (float)Math.Atan(forward[1] / lf_XZ); if (coordSpace == CoordSpace.World) { res[0] = -res[0]; res[0] = -res[1]; } return res; }