コード例 #1
0
        public void TrackballTrack(double trackX, double trackY)
        {
            if (!IsTrackBallMode)
            {
                return;
            }

            var xDegrees = trackX * TRACKBALL_SPEED;
            var yDegrees = trackY * TRACKBALL_SPEED;

            var tempRightDirection = Vector3D.CrossProduct(LookDirection, UpDirection).Normalized();
            var tempUpDirection    = UpDirection;
            var tempPosition       = (Vector3D)Position;

            // perform rotation of xDegrees around "up" axis
            tempPosition       = RotationHelper.RotateVector(tempPosition, tempUpDirection, xDegrees);
            tempRightDirection = RotationHelper.RotateVector(tempRightDirection, tempUpDirection, xDegrees);

            // perform rotation of yDegrees around left/right axis
            tempPosition    = RotationHelper.RotateVector(tempPosition, tempRightDirection, yDegrees);
            tempUpDirection = RotationHelper.RotateVector(tempUpDirection, tempRightDirection, yDegrees);

            UpDirection   = tempUpDirection;
            Position      = (Point3D)tempPosition;
            LookDirection = -tempPosition.Normalized();
        }
コード例 #2
0
        protected Vector3D TrackballRotate(Vector3D toRotate, Vector dragVector2d)
        {
            const double TRACKBALL_ROTATE_SPEED = 0.5;

            var horzDegrees = -dragVector2d.X * TRACKBALL_ROTATE_SPEED;
            var vertDegrees = -dragVector2d.Y * TRACKBALL_ROTATE_SPEED;

            var horzAxis = SketchPlane.Normal;
            var vertAxis = SketchPlane.XAxis;

            toRotate = RotationHelper.RotateVector(toRotate, horzAxis, horzDegrees);
            toRotate = RotationHelper.RotateVector(toRotate, vertAxis, vertDegrees);
            return toRotate;
        }
コード例 #3
0
        private void OnTestCase(object ignore)
        {
            // data from which the cylinder and its curve representations will be created
            var axis       = RotationHelper.RotateVector(MathUtils3D.UnitY, MathUtils3D.UnitX, -20);
            var center     = MathUtils3D.Origin;
            var radius     = 0.2;
            var halfLength = 0.3;

            // basis vectors for the cylinder top/bottom planes
            var xBase = MathUtils3D.NormalVector(axis);
            var yBase = Vector3D.CrossProduct(xBase, axis);

            // generators for the top/bottom circles.
            var topGenerator    = new PolarPointsGenerator(center + halfLength * axis, xBase, yBase);
            var bottomGenerator = new PolarPointsGenerator(center - halfLength * axis, xBase, yBase);

            // angles to use for circles generation.
            const int COUNT  = 50;
            var       angles =
                from i in Enumerable.Range(0, COUNT)
                select 2 * Math.PI * i / COUNT;

            // generate top/bottom circles in 3D
            var topCircle3d =
                from angle in angles
                select topGenerator.GetPoint(angle, radius);

            var bottomCircle3d =
                from angle in angles
                select bottomGenerator.GetPoint(angle, radius);

            // generate the left line from top to bottom
            var leftLine3d =
                from i in Enumerable.Range(0, COUNT)
                let top = topGenerator.GetPoint(0, radius)
                          let bottom = bottomGenerator.GetPoint(0, radius)
                                       let fraction = i / (double)(COUNT - 1)
                                                      select MathUtils3D.Lerp(top, bottom, fraction);

            // generate right line from top to bottom
            var rightLine3d =
                from i in Enumerable.Range(0, COUNT)
                let top = topGenerator.GetPoint(Math.PI, radius)
                          let bottom = bottomGenerator.GetPoint(Math.PI, radius)
                                       let fraction = i / (double)(COUNT - 1)
                                                      select MathUtils3D.Lerp(top, bottom, fraction);

            // project all lines to 2D
            var topCircle2d    = Project(topCircle3d);
            var bottomCircle2d = Project(bottomCircle3d);
            var leftLine2d     = Project(leftLine3d);
            var rightLine2d    = Project(rightLine3d);

            // generate curve data
            var topCurve = new Polygon {
                CurveCategory = CurveCategories.Feature, Points = topCircle2d.ToArray()
            };
            var bottomCurve = new Polygon {
                CurveCategory = CurveCategories.Feature, Points = bottomCircle2d.ToArray()
            };
            var leftCurve = new Polyline {
                CurveCategory = CurveCategories.Silhouette, Points = leftLine2d.ToArray()
            };
            var rightCurve = new Polyline {
                CurveCategory = CurveCategories.Silhouette, Points = rightLine2d.ToArray()
            };

            // generate new primitive that exactly matches the curves
            var newcylinder = new NewCylinder();

            newcylinder.Axis.Value     = axis;
            newcylinder.Center.Value   = center;
            newcylinder.Length.Value   = halfLength * 2;
            newcylinder.Diameter.Value = radius * 2;

            // reset session data
            var sketchData =
                new SketchData
            {
                NewPrimitives     = new NewPrimitive[] { newcylinder },
                Curves            = new PointsSequence[] { topCurve, bottomCurve, leftCurve, rightCurve },
                SnappedPrimitives = new SnappedPrimitive[0],
                Annotations       = new Annotation[0],
            };

            sessionData.SketchData = sketchData;
            sessionData.Annotations.Clear();
            sessionData.Annotations.AddRange(sketchData.Annotations);
            sessionData.NewPrimitives.Clear();
            sessionData.NewPrimitives.AddRange(sketchData.NewPrimitives);
            sessionData.SketchObjects = sketchData.Curves.ToArray();
            sessionData.SnappedPrimitives.Clear();
            sessionData.SnappedPrimitives.AddRange(sessionData.SnappedPrimitives);
        }