示例#1
0
            //=====================================================================================

            /* bool IntersectSegmentPlane(float3 a, float3 b, float3 p, float3 pn, out float3 opos)
             * {
             *  var ab = b - a;
             *  float pd = math.dot(pn, p);
             *  float t = (pd - math.dot(pn, a)) / math.dot(pn, ab);
             *  if (t >= 0.0f && t <= 1.0f)
             *  {
             *      opos = a + t * ab;
             *      return true;
             *  }
             *
             *  opos = 0;
             *  return false;
             * }*/

            void SphereColliderDetection(ref float3 nextpos, float3 oldpos, float radius, int cindex)
            {
                var cpos    = nextPosList[cindex];
                var cradius = radiusList[cindex];

                // スケール
                var tindex = transformIndexList[cindex];
                var cscl   = boneSclList[tindex];

                cradius *= cscl.x; // X軸のみを見る

                // 移動前のパーティクル位置から押し出し平面を求める
                var v   = oldpos - cpos;
                var len = math.length(v);
                var n   = math.normalize(v);

                //var c = cpos + n * (cradius + radius);
                len  = math.min(len, cradius.x + radius);
                len *= 0.999f;
                var c = cpos + n * len;

                // 平面衝突判定
                float3 opos;

                if (MathUtility.IntersectSegmentPlane(oldpos, nextpos, c, n, out opos))
                {
                    nextpos = opos;
                }


                // c = 平面位置
                // n = 平面方向
                // 平面衝突判定と押し出し
                //MathUtility.IntersectPointPlaneDist(c, n, nextpos, out nextpos);
            }
示例#2
0
            void CapsuleColliderDetection(ref float3 nextpos, float3 oldpos, float radius, int cindex, float3 dir)
            {
                var cpos = nextPosList[cindex];
                var crot = nextRotList[cindex];

                // x = 長さ(片側)
                // y = 始点半径
                // z = 終点半径
                //var lpos = localPosList[cindex];
                var cradius = radiusList[cindex];

                // スケール
                var   tindex = transformIndexList[cindex];
                var   cscl   = boneSclList[tindex];
                float scl    = math.dot(cscl, dir); // dirの軸のスケールを使用する

                cradius *= scl;

                // カプセル始点と終点
                float3 l    = math.mul(crot, dir * cradius.x);
                float3 spos = cpos - l;
                float3 epos = cpos + l;
                float  sr   = cradius.y;
                float  er   = cradius.z;

                // 移動前のパーティクル位置から押し出し平面を求める
                //float3 c = 0, n = 0;
                float  t   = MathUtility.ClosestPtPointSegmentRatio(oldpos, spos, epos);
                float  r   = math.lerp(sr, er, t);
                float3 d   = math.lerp(spos, epos, t);
                float3 v   = oldpos - d;
                var    len = math.length(v);
                float3 n   = math.normalize(v);

                len  = math.min(len, r + radius);
                len *= 0.999f;
                //float3 c = d + n * (r + radius);
                float3 c = d + n * len;

                // 平面衝突判定
                float3 opos;

                if (MathUtility.IntersectSegmentPlane(oldpos, nextpos, c, n, out opos))
                {
                    nextpos = opos;
                }


                // c = 平面位置
                // n = 平面方向
                // 平面衝突判定と押し出し
                //return MathUtility.IntersectPointPlaneDist(c, n, nextpos, out nextpos);
            }