Exemple #1
0
        private void Timer_Tick()
        {
            double angle     = (0.05f * frame) * Math.PI / 180;
            var    xAxis     = new Vector3(1, 0, 0);
            var    zAxis     = new Vector3(0, 0, 1);
            var    yAxis     = new Vector3(0, 1, 0);
            var    rotation  = Matrix.RotationAxis(xAxis, 0);
            double angleEach = 0;
            int    counter   = 0;

            for (int i = 0; i < NumSegments && i < numBonesInModel; ++i, counter += numSegmentPerBone)
            {
                if (i == 0)
                {
                    boneInternal[0] = rotation;
                }
                else
                {
                    var vp = Vector3.Transform(path[counter - numSegmentPerBone], Matrix.RotationAxis(xAxis, (float)angleEach)).ToVector3();
                    angleEach += angle;
                    var v   = Vector3.Transform(path[counter], Matrix.RotationAxis(xAxis, (float)angleEach)).ToVector3();
                    var rad = Math.Acos(Vector3.Dot(yAxis, (v - vp).Normalized()));
                    if (angleEach < 0)
                    {
                        rad = -rad;
                    }
                    var rot   = Matrix.RotationAxis(xAxis, (float)rad);
                    var trans = Matrix.Translation(v);
                    boneInternal[i] = rot * trans;
                }
            }
            var newBone = new BoneMatricesStruct()
            {
                Bones = boneInternal.ToArray()
            };

            context.Post((o) =>
            {
                Bones = newBone;
            }, null);

            if (frame > 40 || frame < -40)
            {
                direction = !direction;
            }
            if (direction)
            {
                ++frame;
            }
            else
            {
                --frame;
            }
        }
        /// <summary>
        /// Finds the intersection with a plane.
        /// </summary>
        /// <param name="position">The position.</param>
        /// <param name="normal">The normal.</param>
        /// <param name="ray"></param>
        /// <returns>The intersection point.</returns>
        public static Vector3?PlaneIntersection(this Ray ray, Vector3 position, Vector3 normal)
        {
            // http://paulbourke.net/geometry/planeline/
            var dn = Vector3.Dot(normal, ray.Direction);

            if (dn == 0)
            {
                return(null);
            }

            var u = Vector3.Dot(normal, position - ray.Position) / dn;

            return(ray.Position + u * ray.Direction);
        }
Exemple #3
0
        /// <summary>
        /// Determines whether this polygon is planar.
        /// </summary>
        /// <returns>
        /// The is planar.
        /// </returns>
        public bool IsPlanar()
        {
            Vector3D v1     = this.Points[1] - this.Points[0];
            var      normal = new Vector3D();

            for (int i = 2; i < this.Points.Count; i++)
            {
                var n = Vector3D.Cross(v1, this.Points[i] - this.Points[0]);
                n.Normalize();
                if (i == 2)
                {
                    normal = n;
                }
                else if (Math.Abs(Vector3D.Dot(n, normal) - 1) > 1e-8)
                {
                    return(false);
                }
            }

            return(true);
        }
Exemple #4
0
        /// <summary>
        /// Occurs when the position is changed during a manipulation.
        /// </summary>
        /// <param name="e">The <see cref="Point"/> instance containing the event data.</param>
        public override void Delta(Point e)
        {
            base.Delta(e);
            var thisPoint3D = this.UnProject(e, this.panPoint3D, this.Camera.CameraInternal.LookDirection);

            if (Camera.CameraInternal.LookDirection.LengthSquared() < 1f && MouseDownNearestPoint3D.HasValue)
            {
                var look = Camera.CameraInternal.LookDirection.Normalized();
                var v    = MouseDownNearestPoint3D.Value - Camera.CameraInternal.Position;
                Camera.CameraInternal.LookDirection = look * Math.Max(1, Vector3.Dot(v, look));
            }
            if (this.LastPoint3D == null || thisPoint3D == null)
            {
                return;
            }

            var delta3D = this.LastPoint3D.Value - thisPoint3D.Value;

            this.Pan(delta3D);

            this.LastPoint   = e;
            this.LastPoint3D = this.UnProject(e, this.panPoint3D, this.Camera.CameraInternal.LookDirection);
        }