コード例 #1
0
ファイル: GizmoBase.cs プロジェクト: mksbamford/Moonfxsh
        protected void SelectAxis(Axis axis, SceneMouseEventArgs args = null)
        {
            selectedAxis = axis;
            if (args != null)
            {
                _registrationScreenspace = args.ScreenCoordinates;
            }

            var colours = GetColours();

            using (_batch.Begin())
            {
                _batch.BindBuffer(BufferTarget.ArrayBuffer, _batch.BufferIdents[1]);
                _batch.BufferVertexAttributeData(colours, BufferUsageHint.StaticDraw);
            }
        }
コード例 #2
0
        protected override void Transform(SceneMouseEventArgs args)
        {
            if (selectedAxis == Axis.None)
            {
                return;
            }
            var camera = args.Camera;

            var originScreenspace       = camera.Project(position);
            var axisNormal              = GetAxisNormal(selectedAxis);
            var translation_screenspace = CalculateScreenspaceTranslation(originScreenspace,
                                                                          camera.Project(position + axisNormal), args.ScreenCoordinates);

            var near = camera.UnProject(originScreenspace + translation_screenspace);
            var far  = camera.UnProject(originScreenspace + translation_screenspace, -0.01f);

            var mouseRay = new Ray(near, far);

            // Setup and select the collision plane
            var normal = FindPlaneNormal(mouseRay.Direction, axisNormal);
            // Produce the plane-distance from origin from this objects position vector
            var planeOffset = Vector3.Dot(normal, position);
            // We use negetive offset here
            var translationPlane = new Plane(normal, -planeOffset);

            float?distance;

            if (!translationPlane.Intersects(mouseRay, out distance))
            {
                return;
            }

            var mouseVector                 = mouseRay.Origin + mouseRay.Direction * distance.GetValueOrDefault();
            var mouseProjectionLength       = Vector3.Dot(axisNormal, mouseVector);
            var positionProjectionLength    = Vector3.Dot(axisNormal, position);
            var translationProjectionLength = (mouseProjectionLength - positionProjectionLength);

            var vector = (translationProjectionLength * axisNormal);

            if (!(vector.Length > 0))
            {
                return;
            }
            SetTranslation(vector);
        }
コード例 #3
0
        protected override void Transform(SceneMouseEventArgs args)
        {
            if (selectedAxis == Axis.None)
            {
                return;
            }
            var camera = args.Camera;

            var originScreenspace = camera.Project(position);
            var axisNormal        = GetAxisNormal(selectedAxis);

            var normalScreenspace = camera.Project(position + axisNormal).Normalized();

            var translation = CalculateScreenspaceTranslation(originScreenspace,
                                                              camera.Project(position + axisNormal), args.ScreenCoordinates);

            SetTransform(Vector2.Dot(translation, normalScreenspace));
        }
コード例 #4
0
 public void OnMouseCaptureChanged(object sender, SceneMouseEventArgs e)
 {
     MouseCaptureChanged?.Invoke(sender, e);
 }
コード例 #5
0
 public void OnMouseClick(object sender, SceneMouseEventArgs e)
 {
     MouseClick?.Invoke(sender, e);
 }
コード例 #6
0
 public void OnMouseDown(object sender, SceneMouseEventArgs e)
 {
     MouseDown?.Invoke(sender, e);
 }
コード例 #7
0
        protected override void Transform(SceneMouseEventArgs args)
        {
            if (selectedAxis == Axis.None)
            {
                return;
            }

            var camera                  = args.Camera;
            var originScreenspace       = camera.Project(_pivot);
            var axisNormal              = GetAxisNormal(selectedAxis);
            var translation_screenspace = CalculateScreenspaceTranslation(originScreenspace,
                                                                          camera.Project(position + axisNormal), args.ScreenCoordinates);

            var near = camera.UnProject(args.ScreenCoordinates);
            var far  = camera.UnProject(args.ScreenCoordinates, -0.01f);

            var mouseRay = new Ray(near, far);

            // Setup and select the collision plane
            var normal = Vector3.UnitZ; // FindPlaneNormal(mouseRay.Direction, axisNormal);
            // Produce the plane-distance from origin from this objects position vector
            var planeOffset = Vector3.Dot(normal, position);
            // We use negetive offset here
            var translationPlane = new Plane(normal, -planeOffset);

            float?distance;

            if (!translationPlane.Intersects(mouseRay, out distance))
            {
                return;
            }

            var mouseVector                 = mouseRay.Origin + mouseRay.Direction * distance.GetValueOrDefault();
            var mouseProjectionLength       = Vector3.Dot(axisNormal, mouseVector);
            var positionProjectionLength    = Vector3.Dot(axisNormal, position);
            var translationProjectionLength = (mouseProjectionLength - positionProjectionLength);

            var positionVector    = WorldMatrix.ExtractTranslation();
            var translationVector = mouseVector - _pivot;
            var vector            = (mouseProjectionLength * axisNormal);
            var length            = (position - _pivot).Length;
            var t = (mouseVector - _pivot).Normalized() * length;
            var normalizedPositionVector  = positionVector.Normalized();
            var normalizedTransformVector = (_pivot + t).Normalized();

            CosTheta = Vector3.Dot(normalizedPositionVector, normalizedTransformVector);
            SinTheta = Vector3.Cross(normalizedPositionVector, normalizedTransformVector).Length;

            var atanPosition  = Math.Atan2(normalizedPositionVector.Y, normalizedPositionVector.X);
            var atanTransform = Math.Atan2(normalizedTransformVector.Y, normalizedTransformVector.X);


            var angle = atanTransform - atanPosition;

            var transform = Quaternion.FromAxisAngle(normal, (float)translationProjectionLength).Normalized();

            // (positionVector, translationVector);

            FromQuaternion = Matrix4.CreateFromQuaternion(transform);


#if DEBUG
#endif

            SetTransform(transform);
        }
コード例 #8
0
ファイル: GizmoBase.cs プロジェクト: mksbamford/Moonfxsh
 protected abstract void Transform(SceneMouseEventArgs args);