/// 継承メソッド
///---------------------------------------------------------------------------

        /// 初期化
        public override bool DoInit()
        {
            shapeColl = new ShapeTriangles();

            useMdlHdl = new Common.ModelHandle();
            useMdlHdl.Init();
            return(true);
        }
        /// 継承メソッド
        ///---------------------------------------------------------------------------
        /// 初期化
        public override bool DoInit()
        {
            shapeColl = new ShapeTriangles();

            useMdlHdl = new Common.ModelHandle();
            useMdlHdl.Init();
            return true;
        }
        /// public メソッド
        ///---------------------------------------------------------------------------
        /// カプセルと三角形との衝突
        public bool Check( DemoGame.GeometryCapsule moveCap, ShapeTriangles trgShape )
        {
            Vector3 collPos = StaticDataList.getVectorZero();
            calMovePos = moveCap.EndPos;
            calBestDis = -1.0f;
            calBestId  = -1;

            float checDis = moveCap.Line.Length + moveCap.R + collCheckDis;

            if( AppDebug.CollLightFlg == false ){
            for( int i=0; i<trgShape.EntryNum; i++ ){

                float a = (calMovePos.Dot( trgShape.Triangle[i].Plane.Nor ) + trgShape.Triangle[i].Plane.D);
                if( a >= checDis || a <= -checDis ){
                    continue;
                }

                if( DemoGame.CommonCollision.CheckSphereAndTriangle( moveCap, trgShape.Triangle[i], ref collPos ) == true ){
                    float dis = Common.VectorUtil.Distance( collPos, moveCap.StartPos );
                    if( dis < calBestDis || calBestId < 0 ){
                        calMovePos        = collPos;
                        calBestDis        = dis;
                        calBestId        = i;
                    }
                }
                AppDebug.CollCnt ++;
            }
            }
            else{
            for( int i=0; i<trgShape.EntryNum; i++ ){

                float a = (calMovePos.Dot( trgShape.Triangle[i].Plane.Nor ) + trgShape.Triangle[i].Plane.D);
                if( a >= checDis || a <= -checDis ){
                    continue;
                }

                if( DemoGame.CommonCollision.CheckLineAndTriangle( moveCap.Line, trgShape.Triangle[i], ref collPos ) == true ){
                    float dis = Common.VectorUtil.Distance( collPos, moveCap.StartPos );
                    if( dis < calBestDis || calBestId < 0 ){
                        calMovePos        = collPos;
                        calBestDis        = dis;
                        calBestId        = i;
                    }
                }
                AppDebug.CollCnt ++;
            }
            }

            if( calBestId >= 0 ){
            return true;
            }
            return false;
        }
 /// 破棄
 public override void DoTerm()
 {
     if (shapeColl != null)
     {
         shapeColl.Term();
     }
     if (useMdlHdl != null)
     {
         useMdlHdl.Term();
     }
     shapeColl = null;
     useMdlHdl = null;
 }
Exemple #5
0
/// private メソッド
///---------------------------------------------------------------------------

        /// 衝突形状の作成
        private void makeShapeColl(int id, float[] posList)
        {
            shapeColl[id] = new ShapeTriangles();
            shapeColl[id].Init(posList.Length / 9);

            for (int i = 0; i < posList.Length / 9; i++)
            {
                Vector3 pos1 = new Vector3(posList[i * 9 + 0], posList[i * 9 + 1], posList[i * 9 + 2]);
                Vector3 pos2 = new Vector3(posList[i * 9 + 3], posList[i * 9 + 4], posList[i * 9 + 5]);
                Vector3 pos3 = new Vector3(posList[i * 9 + 6], posList[i * 9 + 7], posList[i * 9 + 8]);
                shapeColl[id].SetType(0);
                shapeColl[id].AddLight(pos1, pos2, pos3);
            }
        }
        /// カプセルと三角形との衝突
        public bool Check(DemoGame.GeometryLine moveLine, ShapeTriangles trgShape)
        {
            Vector3 collPos = StaticDataList.getVectorZero();

            calMovePos = moveLine.EndPos;
            calBestDis = -1.0f;
            calBestId  = -1;

            float checDis = moveLine.Length + collCheckDis;

            for (int i = 0; i < trgShape.EntryNum; i++)
            {
                float a = (calMovePos.Dot(trgShape.Triangle[i].Plane.Nor) + trgShape.Triangle[i].Plane.D);
                if (a >= checDis || a <= -checDis)
                {
                    continue;
                }

                if (DemoGame.CommonCollision.CheckLineAndTriangle(moveLine, trgShape.Triangle[i], ref collPos) == true)
                {
                    float dis = Common.VectorUtil.Distance(collPos, moveLine.StartPos);
                    if (dis < calBestDis || calBestId < 0)
                    {
                        calMovePos = collPos;
                        calBestDis = dis;
                        calBestId  = i;
                    }
                }
                AppDebug.CollCnt++;
            }

            if (calBestId >= 0)
            {
                return(true);
            }
            return(false);
        }
Exemple #7
0
        /// private メソッド
        ///---------------------------------------------------------------------------
        /// 衝突形状の作成
        private void makeShapeColl( int id, float[] posList )
        {
            shapeColl[id] = new ShapeTriangles();
            shapeColl[id].Init( posList.Length/9 );

            for( int i=0; i<posList.Length/9; i++ ){
            Vector3 pos1 = new Vector3( posList[i*9+0], posList[i*9+1], posList[i*9+2] );
            Vector3 pos2 = new Vector3( posList[i*9+3], posList[i*9+4], posList[i*9+5] );
            Vector3 pos3 = new Vector3( posList[i*9+6], posList[i*9+7], posList[i*9+8] );
            shapeColl[id].SetType( 0 );
            shapeColl[id].AddLight( pos1, pos2, pos3 );
            }
        }
        /// 衝突後の移動座標をセット(三角形との衝突)
        private void setScrapedMovePosTriangle( GameActorCollManager collMgr, Vector3 movePos, ShapeTriangles shapeTri )
        {
            ShapeSphere      moveSph    = (ShapeSphere)collMgr.MoveShape;
            int              primId     = collMgr.TrgContainer.GetEntryPrimId( 0 );

            Vector3          collPos = StaticDataList.getVectorZero();
            float            scrapedPow = (moveSph.Sphre.R+0.001f);

            /// 点と面上の最近接点を求める
            DemoGame.CommonCollision.GetClosestPtPosPlane( movePos, shapeTri.Triangle[primId].Plane, ref collPos );

            /// 移動候補座標更新
            nextPos.X = collPos.X + ( scrapedPow * (shapeTri.Triangle[primId].Plane.Nor.X) );
            nextPos.Y = collPos.Y + ( scrapedPow * (shapeTri.Triangle[primId].Plane.Nor.Y) );
            nextPos.Z = collPos.Z + ( scrapedPow * (shapeTri.Triangle[primId].Plane.Nor.Z) );
        }
Exemple #9
0
        /// 衝突後の移動座標をセット(三角形との衝突)
        private void setScrapedMovePosTriangle(GameActorCollManager collMgr, DemoGame.GeometryLine moveLine, ShapeTriangles shapeTri)
        {
            int primId = collMgr.TrgContainer.GetEntryPrimId(0);

            /// 衝突点を求める
            DemoGame.CommonCollision.CheckLineAndTriangle(moveLine, shapeTri.Triangle[primId], ref nextPos);
        }
Exemple #10
0
 /// 破棄
 public override void DoTerm()
 {
     if( shapeColl != null ){
     shapeColl.Term();
     }
     if( useMdlHdl != null ){
     useMdlHdl.Term();
     }
     shapeColl = null;
     useMdlHdl = null;
 }
        /// 衝突後の移動座標をセット(三角形との衝突)
        private void setScrapedMovePosTriangle( GameActorCollManager collMgr, DemoGame.GeometryLine moveLine, ShapeTriangles shapeTri )
        {
            int              primId     = collMgr.TrgContainer.GetEntryPrimId( 0 );

            /// 衝突点を求める
            DemoGame.CommonCollision.CheckLineAndTriangle( moveLine, shapeTri.Triangle[primId], ref nextPos );
        }
        /// 衝突後の移動座標をセット(三角形との衝突)
        private void setScrapedMovePosTriangle(GameActorCollManager collMgr, Vector3 movePos, ShapeTriangles shapeTri)
        {
            ShapeSphere moveSph = (ShapeSphere)collMgr.MoveShape;
            int         primId  = collMgr.TrgContainer.GetEntryPrimId(0);

            Vector3 collPos    = StaticDataList.getVectorZero();
            float   scrapedPow = (moveSph.Sphre.R + 0.001f);

            /// 点と面上の最近接点を求める
            DemoGame.CommonCollision.GetClosestPtPosPlane(movePos, shapeTri.Triangle[primId].Plane, ref collPos);

            /// 移動候補座標更新
            nextPos.X = collPos.X + (scrapedPow * (shapeTri.Triangle[primId].Plane.Nor.X));
            nextPos.Y = collPos.Y + (scrapedPow * (shapeTri.Triangle[primId].Plane.Nor.Y));
            nextPos.Z = collPos.Z + (scrapedPow * (shapeTri.Triangle[primId].Plane.Nor.Z));
        }
Exemple #13
0
        /// 衝突後の移動座標をセット(三角形との衝突)
        public void setScrapedMovePosTriangle(GameActorCollManager collMgr, Vector3 movePos, ShapeTriangles shapeTri)
        {
            ShapeSphere moveSph = (ShapeSphere)collMgr.MoveShape;
            int         primId  = collMgr.TrgContainer.GetEntryPrimId(0);

            Vector3 collPos    = StaticDataList.getVectorZero();
            float   scrapedPow = (moveSph.Sphre.R + 0.001f);

            /// 弾く力の算出
            moveMoveCap.Set(moveSph.Sphre.Pos, movePos, moveSph.Sphre.R);
            DemoGame.CommonCollision.CheckSphereAndTriangle(moveMoveCap, shapeTri.Triangle[primId], ref collPos);

            /// 移動候補座標更新
            nextPos.X = moveSph.Sphre.Pos.X;
            nextPos.Y = collPos.Y + (scrapedPow * (shapeTri.Triangle[primId].Plane.Nor.Y));
            nextPos.Z = moveSph.Sphre.Pos.Z;

            touchGroundType = shapeTri.CollisionType;
            touchGroundFlg  = true;

            treadVec = shapeTri.Triangle[primId].Plane.Nor;
        }
        /// ラインと三角形との衝突
        public bool CheckTriangle( DemoGame.GeometryLine moveLine, ShapeTriangles trgShape )
        {
            Vector3 collPos = new Vector3(0,0,0);

            calMovePos = moveLine.EndPos;
            calBestDis = -1.0f;
            calBestId  = -1;

            float checDis = moveLine.Length + collCheckDis;

            for( int i=0; i<trgShape.EntryNum; i++ ){

            float a = (calMovePos.Dot( trgShape.Triangle[i].Plane.Nor ) + trgShape.Triangle[i].Plane.D);
            if( a >= checDis || a <= -checDis ){
                continue;
            }

            if( DemoGame.CommonCollision.CheckLineAndTriangle( moveLine, trgShape.Triangle[i], ref collPos ) == true ){
                float dis = Common.VectorUtil.Distance( collPos, moveLine.StartPos );
                if( dis < calBestDis || calBestId < 0 ){
                    calMovePos        = collPos;
                    calBestDis        = dis;
                    calBestId        = i;
                }
            }
            }

            if( calBestId >= 0 ){
            return true;
            }
            return false;
        }
        /// 衝突後の移動座標をセット(三角形との衝突)
        public void setScrapedMovePosTriangle( GameActorCollManager collMgr, Vector3 movePos, ShapeTriangles shapeTri )
        {
            ShapeSphere        moveSph    = (ShapeSphere)collMgr.MoveShape;
            int                primId     = collMgr.TrgContainer.GetEntryPrimId( 0 );

            Vector3            collPos = StaticDataList.getVectorZero();
            float              scrapedPow = (moveSph.Sphre.R+0.001f);

            /// 弾く力の算出
            moveMoveCap.Set( moveSph.Sphre.Pos, movePos, moveSph.Sphre.R );
            DemoGame.CommonCollision.CheckSphereAndTriangle( moveMoveCap, shapeTri.Triangle[primId], ref collPos );

            /// 移動候補座標更新
            nextPos.X = moveSph.Sphre.Pos.X;
            nextPos.Y = collPos.Y + ( scrapedPow * (shapeTri.Triangle[primId].Plane.Nor.Y) );
            nextPos.Z = moveSph.Sphre.Pos.Z;

            touchGroundType   = shapeTri.CollisionType;
            touchGroundFlg    = true;

            treadVec = shapeTri.Triangle[primId].Plane.Nor;
        }