Пример #1
0
        public void AssignUnion(AABB box)
        {
            Min.x = VMath.Min(Min.x, box.Min.x);
            Min.y = VMath.Min(Min.y, box.Min.y);
            Min.z = VMath.Min(Min.z, box.Min.z);

            Max.x = VMath.Max(Max.x, box.Max.x);
            Max.y = VMath.Max(Max.y, box.Max.y);
            Max.z = VMath.Max(Max.z, box.Max.z);
        }
Пример #2
0
        public void AssignUnion(Vector3D pt)
        {
            Min.x = VMath.Min(Min.x, pt.x);
            Min.y = VMath.Min(Min.y, pt.y);
            Min.z = VMath.Min(Min.z, pt.z);

            Max.x = VMath.Max(Max.x, pt.x);
            Max.y = VMath.Max(Max.y, pt.y);
            Max.z = VMath.Max(Max.z, pt.z);
        }
Пример #3
0
        public Mesh(Polygon[] polygons)
        {
            Vector3 min = polygons[0].V1.pos;
            Vector3 max = polygons[0].V1.pos;

            foreach (var poly in polygons)
            {
                foreach (var v in poly.vertices)
                {
                    min = VMath.Min(min, v.pos);
                    max = VMath.Max(max, v.pos);
                }
            }
            AABB = new AABoundingBox(min, max);

            OctagonalNode = new OctagonalNode(AABB);
            OctagonalNode.Polygons.AddRange(polygons);
            OctagonalNode.InitPolygons(0, 9, 10000);
        }
Пример #4
0
        private void UpdateAABB()
        {
            Vector3 min = new Vector3(1, 1, 1) * 1E+6F;
            Vector3 max = new Vector3(1, 1, 1) * -1E+6F;

            foreach (var poly in Polygons)
            {
                foreach (var v in poly.vertices)
                {
                    min = VMath.Min(min, v.pos);
                    max = VMath.Max(max, v.pos);
                }
            }

            foreach (var child in Childs)
            {
                min = VMath.Min(min, child.AABB.PosMin);
                max = VMath.Max(max, child.AABB.PosMax);
            }

            AABB = new AABoundingBox(min, max);
        }
Пример #5
0
        private IJoint getNearestBone(Vector3D pos, IJoint currJoint, out double nearestDistance)
        {
            double    distBone = 0.0;
            Vector3D  origin   = new Vector3D(0);
            Matrix4x4 t        = currJoint.CombinedTransform;
            Vector3D  p1       = t * origin;

            distBone = VMath.Dist(pos, p1);

            for (int i = 0; i < currJoint.Children.Count; i++)
            {
                bool outside = false;
                t = currJoint.Children[i].CombinedTransform;
                Vector3D p2 = t * origin;

                Vector3D v     = p2 - p1;
                Vector3D w     = pos - p1;
                double   angle = (v.x * w.x + v.y * w.y + v.z * w.z) / (Math.Sqrt(v.x * v.x + v.y * v.y + v.z * v.z) * Math.Sqrt(w.x * w.x + w.y * w.y + w.z * w.z));
                angle = Math.Acos(angle);
                if (Math.Abs(angle) > 3.14 / 2)
                {
                    distBone = VMath.Min(distBone, VMath.Dist(pos, p1));
                    outside  = true;
                }

                Vector3D v_ = p1 - p2;
                Vector3D w_ = pos - p2;
                angle = (v_.x * w_.x + v_.y * w_.y + v_.z * w_.z) / (Math.Sqrt(v_.x * v_.x + v_.y * v_.y + v_.z * v_.z) * Math.Sqrt(w_.x * w_.x + w_.y * w_.y + w_.z * w_.z));
                angle = Math.Acos(angle);
                if (Math.Abs(angle) > 3.14 / 2)
                {
                    distBone = VMath.Min(distBone, VMath.Dist(pos, p2));
                    outside  = true;
                }

                if (!outside)
                {
                    Vector3D vxw = new Vector3D();
                    vxw.x    = v.y * w.z - v.z * w.y;
                    vxw.y    = v.z * w.x - v.x * w.z;
                    vxw.z    = v.x * w.y - v.y * w.x;
                    distBone = VMath.Min(distBone, System.Math.Sqrt(vxw.x * vxw.x + vxw.y * vxw.y + vxw.z * vxw.z) / System.Math.Sqrt(v.x * v.x + v.y * v.y + v.z * v.z));
                }
            }

            nearestDistance = 1000000;
            IJoint nearestChild = currJoint;

            for (int i = 0; i < currJoint.Children.Count; i++)
            {
                double childDistance;
                IJoint candidate = getNearestBone(pos, (IJoint)currJoint.Children[i], out childDistance);
                if (childDistance < nearestDistance)
                {
                    nearestChild    = candidate;
                    nearestDistance = childDistance;
                }
            }

            if (nearestDistance <= distBone)
            {
                return(nearestChild);
            }
            else
            {
                nearestDistance = distBone;
                return(currJoint);
            }
        }
Пример #6
0
            void UpdateHairTrigger()
            {
                hairTriggerPrevState = hairTriggerState;
                var value = state.rAxis1.x; // trigger

                hairTriggerValue = value;
                if (hairTriggerState)
                {
                    if (value < hairTriggerLimit - hairTriggerDelta || value <= 0.0f)
                    {
                        hairTriggerState = false;
                    }
                }
                else
                {
                    if (value > hairTriggerLimit + hairTriggerDelta || value >= 1.0f)
                    {
                        hairTriggerState = true;
                    }
                }
                hairTriggerLimit = hairTriggerState ? (float)VMath.Max(hairTriggerLimit, value) : (float)VMath.Min(hairTriggerLimit, value);
            }
Пример #7
0
 public AABoundingBox(Vector3 pos1, Vector3 pos2)
 {
     PosMin = VMath.Min(pos1, pos2);
     PosMax = VMath.Max(pos1, pos2);
 }