コード例 #1
0
        /*
         * 更新雷达中的可见区域贴图
         *
         *
         * 分为以下几个步骤:
         *
         * <1>获得可能在雷达范围中的所有遮挡物
         *
         * <2>将遮挡物的边界点坐标转换到雷达空间中,并在已经栅格化的雷达空间中填充边界点的深度信息,获得深度图。
         *
         * <3>用显卡计算出可见区域贴图
         *
         * */
        private void CalRaderMap(Rader rader, IEnumerable <IShelterObj>[] shelterObjGroup)
        {
            // 获得可能在雷达范围中的所有遮挡物。
            List <IShelterObj> sheltersInRader = new List <IShelterObj>(16);

            foreach (IEnumerable <IShelterObj> group in shelterObjGroup)
            {
                foreach (IShelterObj shelter in group)
                {
                    if (shelter.BoundingBox.Intersects(rader.BoundBox))
                    {
                        sheltersInRader.Add(shelter);
                    }
                }
            }

            // 将遮挡物的边界点坐标转换到雷达空间中,并在已经栅格化的雷达空间中填充边界点的深度信息,获得深度图。
            rader.depthMap.ClearMap(1);

            foreach (IShelterObj shelter in sheltersInRader)
            {
                rader.depthMap.ApplyShelterObj(rader, shelter);
            }

            // 用显卡计算出可见区域贴图
            raderDrawer.DrawRader(rader);

            // 更新各项数据
            rader.UpdateTexture();
        }
コード例 #2
0
        public void ApplyShelterObj(Rader rader, IShelterObj obj)
        {
            Matrix worldMatrix = obj.WorldTrans;

            CircleList <BorderPoint>     border = obj.BorderData;
            CircleListNode <BorderPoint> lastB  = border.First.pre;
            Vector2 pInRader  = rader.TranslateToRaderSpace(Vector2.Transform(ConvertHelper.PointToVector2(lastB.value.p), worldMatrix));
            int     lastIndex = IndexOf(pInRader.X);
            float   lastDepth = pInRader.Y;

            CircleListNode <BorderPoint> cur = border.First;

            for (int i = 0; i < border.Length; i++)
            {
                pInRader = rader.TranslateToRaderSpace(Vector2.Transform(ConvertHelper.PointToVector2(cur.value.p), worldMatrix));
                int   curIndex = IndexOf(pInRader.X);
                float curDepth = pInRader.Y;
                if (pInRader.X >= -1.1f && pInRader.X <= 1.3f)
                {
                    //this[pInRader.X] = Math.Min( this[pInRader.X], pInRader.Y );
                    SetValueAtIndex(curIndex, pInRader.Y, obj, i, cur.value.p);

                    if (curIndex - lastIndex > 1)
                    {
                        int overIndex = lastIndex + 1;
                        while (overIndex != curIndex)
                        {
                            float lerp = MathHelper.Lerp(lastDepth, curDepth, (curIndex - overIndex) / (curIndex - lastIndex));
                            SetValueAtIndex(overIndex, lerp, obj, i, cur.value.p);
                            overIndex++;
                        }
                    }
                    else if (curIndex - lastIndex < -1)
                    {
                        int overIndex = lastIndex - 1;
                        while (overIndex != curIndex)
                        {
                            float lerp = MathHelper.Lerp(lastDepth, curDepth, (curIndex - overIndex) / (curIndex - lastIndex));
                            SetValueAtIndex(overIndex, lerp, obj, i, cur.value.p);
                            overIndex--;
                        }
                    }
                }
                lastIndex = curIndex;
                lastDepth = curDepth;

                cur = cur.next;
            }
        }
コード例 #3
0
ファイル: TankSinTur.cs プロジェクト: ingex0/smarttank
 public TankSinTur(string name, GameObjInfo objInfo, string texPath, GameObjData skinData,
     float raderLength, float raderAng, Color raderColor, float raderAzi,
     float maxForwardSpeed, float maxBackwardSpeed, float maxRotaSpeed,
     float maxTurretRotaSpeed, float maxRaderRotaSpeed, float fireCDTime,
     Vector2 pos, float baseRota, float turretRota)
 {
     this.name = name;
     this.objInfo = objInfo;
     this.skin = new TankSkinSinTur(new TankSkinSinTurData(texPath, skinData));
     skin.Initial(pos, baseRota, turretRota);
     controller = new TankContrSinTur(objInfo, new Sprite[] { skin.Sprites[0] } , pos, baseRota, maxForwardSpeed, maxBackwardSpeed, maxRotaSpeed, maxTurretRotaSpeed, maxRaderRotaSpeed, Math.Max(0, fireCDTime));
     colChecker = controller;
     phisicalUpdater = controller;
     controller.onShoot += new EventHandler(controller_onShoot);
     controller.OnCollied += new OnCollidedEventHandler(controller_OnCollied);
     controller.OnOverlap += new OnCollidedEventHandler(controller_OnOverlap);
     controller.posAziChanged += new SmartTank.PhiCol.NonInertiasPhiUpdater.PosAziChangedEventHandler(controller_OnPosAziChanged);
     rader = new Rader(raderAng, raderLength, pos, raderAzi + baseRota, raderColor);
 }
コード例 #4
0
ファイル: RaderDrawer.cs プロジェクト: ingex0/smarttank
            public void DrawRader( Rader rader )
            {
                try
                {
                    BaseGame.Device.RenderState.DepthBufferEnable = false;
                    BaseGame.Device.RenderState.DepthBufferWriteEnable = false;
                    BaseGame.Device.RenderState.AlphaBlendEnable = false;

                    Texture2D depthMapTex = rader.depthMap.GetMapTexture();
                    depthMapPara.SetValue( depthMapTex );

                    raderAngPara.SetValue( rader.Ang );
                    raderColorPara.SetValue( ColorHelper.ToFloat4( rader.RaderColor ) );
                    raderRotaMatrixPara.SetValue( rader.RotaMatrix );
                    renderRaderEffect.CommitChanges();

                    DepthStencilBuffer old = BaseGame.Device.DepthStencilBuffer;

                    BaseGame.Device.SetRenderTarget( 0, rader.target );
                    BaseGame.Device.DepthStencilBuffer = depthBuffer;

                    BaseGame.Device.Clear( Color.TransparentBlack );

                    renderRaderEffect.CurrentTechnique = renderRaderEffect.Techniques[0];
                    renderRaderEffect.Begin();
                    renderRaderEffect.CurrentTechnique.Passes[0].Begin();

                    BaseGame.Device.VertexDeclaration = del;
                    BaseGame.Device.Vertices[0].SetSource( sectorBuffer, 0, del.GetVertexStrideSize( 0 ) );
                    BaseGame.Device.DrawPrimitives( PrimitiveType.TriangleFan, 0, partSum );

                    renderRaderEffect.CurrentTechnique.Passes[0].End();
                    renderRaderEffect.End();

                    BaseGame.Device.SetRenderTarget( 0, rader.targetSmall );
                    BaseGame.Device.DepthStencilBuffer = depthBufferSmall;

                    BaseGame.Device.Clear( Color.TransparentBlack );

                    renderRaderEffect.CurrentTechnique = renderRaderEffect.Techniques[0];
                    renderRaderEffect.Begin();
                    renderRaderEffect.CurrentTechnique.Passes[0].Begin();

                    BaseGame.Device.VertexDeclaration = del;
                    BaseGame.Device.Vertices[0].SetSource( sectorBuffer, 0, del.GetVertexStrideSize( 0 ) );
                    BaseGame.Device.DrawPrimitives( PrimitiveType.TriangleFan, 0, partSum );

                    renderRaderEffect.CurrentTechnique.Passes[0].End();
                    renderRaderEffect.End();
                    BaseGame.Device.SetRenderTarget( 0, null );

                    BaseGame.Device.DepthStencilBuffer = old;

                    BaseGame.Device.RenderState.DepthBufferEnable = true;
                    BaseGame.Device.RenderState.DepthBufferWriteEnable = true;
                }
                catch (Exception ex)
                {
                    Log.Write( ex.Message );
                }
            }
コード例 #5
0
ファイル: ShelterMgr.cs プロジェクト: ingex0/smarttank
        /* 
         * 更新雷达中的可见区域贴图
         * 
         * 
         * 分为以下几个步骤:
         * 
         * <1>获得可能在雷达范围中的所有遮挡物
         * 
         * <2>将遮挡物的边界点坐标转换到雷达空间中,并在已经栅格化的雷达空间中填充边界点的深度信息,获得深度图。
         * 
         * <3>用显卡计算出可见区域贴图
         * 
         * */
        private void CalRaderMap( Rader rader, IEnumerable<IShelterObj>[] shelterObjGroup )
        {
            // 获得可能在雷达范围中的所有遮挡物。
            List<IShelterObj> sheltersInRader = new List<IShelterObj>( 16 );

            foreach (IEnumerable<IShelterObj> group in shelterObjGroup)
            {
                foreach (IShelterObj shelter in group)
                {
                    if (shelter.BoundingBox.Intersects( rader.BoundBox ))
                        sheltersInRader.Add( shelter );
                }
            }

            // 将遮挡物的边界点坐标转换到雷达空间中,并在已经栅格化的雷达空间中填充边界点的深度信息,获得深度图。
            rader.depthMap.ClearMap( 1 );

            foreach (IShelterObj shelter in sheltersInRader)
            {
                rader.depthMap.ApplyShelterObj( rader, shelter );
            }

            // 用显卡计算出可见区域贴图
            raderDrawer.DrawRader( rader );

            // 更新各项数据
            rader.UpdateTexture();
        }
コード例 #6
0
ファイル: VisionMgr.cs プロジェクト: ingex0/smarttank
 private static ObjVisiBorder CalNonShelterVisiBorder( IHasBorderObj obj, Rader rader )
 {
     CircleListNode<BorderPoint> curNode = obj.BorderData.First;
     CircleList<BordPoint> points = new CircleList<BordPoint>();
     for (int i = 0; i < obj.BorderData.Length; i++)
     {
         if (rader.PointInRader( Vector2.Transform( ConvertHelper.PointToVector2( curNode.value.p ), obj.WorldTrans ) ))
         {
             points.AddLast( new BordPoint( i, curNode.value.p ) );
         }
         curNode = curNode.next;
     }
     if (points.Length != 0)
         return new ObjVisiBorder( obj, points );
     else
         return null;
 }
コード例 #7
0
ファイル: RaderDepthMap.cs プロジェクト: ingex0/smarttank
        public void ApplyShelterObj( Rader rader, IShelterObj obj )
        {
            Matrix worldMatrix = obj.WorldTrans;

            CircleList<BorderPoint> border = obj.BorderData;
            CircleListNode<BorderPoint> lastB = border.First.pre;
            Vector2 pInRader = rader.TranslateToRaderSpace( Vector2.Transform( ConvertHelper.PointToVector2( lastB.value.p ), worldMatrix ) );
            int lastIndex = IndexOf( pInRader.X );
            float lastDepth = pInRader.Y;

            CircleListNode<BorderPoint> cur = border.First;
            for (int i = 0; i < border.Length; i++)
            {
                pInRader = rader.TranslateToRaderSpace( Vector2.Transform( ConvertHelper.PointToVector2( cur.value.p ), worldMatrix ) );
                int curIndex = IndexOf( pInRader.X );
                float curDepth = pInRader.Y;
                if (pInRader.X >= -1.1f && pInRader.X <= 1.3f)
                {
                    //this[pInRader.X] = Math.Min( this[pInRader.X], pInRader.Y );
                    SetValueAtIndex( curIndex, pInRader.Y, obj, i, cur.value.p );

                    if (curIndex - lastIndex > 1)
                    {
                        int overIndex = lastIndex + 1;
                        while (overIndex != curIndex)
                        {
                            float lerp = MathHelper.Lerp( lastDepth, curDepth, (curIndex - overIndex) / (curIndex - lastIndex) );
                            SetValueAtIndex( overIndex, lerp, obj, i, cur.value.p );
                            overIndex++;
                        }
                    }
                    else if (curIndex - lastIndex < -1)
                    {
                        int overIndex = lastIndex - 1;
                        while (overIndex != curIndex)
                        {
                            float lerp = MathHelper.Lerp( lastDepth, curDepth, (curIndex - overIndex) / (curIndex - lastIndex) );
                            SetValueAtIndex( overIndex, lerp, obj, i, cur.value.p );
                            overIndex--;
                        }
                    }
                }
                lastIndex = curIndex;
                lastDepth = curDepth;

                cur = cur.next;
            }
        }
コード例 #8
0
            public void DrawRader(Rader rader)
            {
                try
                {
                    BaseGame.Device.RenderState.DepthBufferEnable      = false;
                    BaseGame.Device.RenderState.DepthBufferWriteEnable = false;
                    BaseGame.Device.RenderState.AlphaBlendEnable       = false;

                    Texture2D depthMapTex = rader.depthMap.GetMapTexture();
                    depthMapPara.SetValue(depthMapTex);

                    raderAngPara.SetValue(rader.Ang);
                    raderColorPara.SetValue(ColorHelper.ToFloat4(rader.RaderColor));
                    raderRotaMatrixPara.SetValue(rader.RotaMatrix);
                    renderRaderEffect.CommitChanges();

                    DepthStencilBuffer old = BaseGame.Device.DepthStencilBuffer;

                    BaseGame.Device.SetRenderTarget(0, rader.target);
                    BaseGame.Device.DepthStencilBuffer = depthBuffer;

                    BaseGame.Device.Clear(Color.TransparentBlack);

                    renderRaderEffect.CurrentTechnique = renderRaderEffect.Techniques[0];
                    renderRaderEffect.Begin();
                    renderRaderEffect.CurrentTechnique.Passes[0].Begin();

                    BaseGame.Device.VertexDeclaration = del;
                    BaseGame.Device.Vertices[0].SetSource(sectorBuffer, 0, del.GetVertexStrideSize(0));
                    BaseGame.Device.DrawPrimitives(PrimitiveType.TriangleFan, 0, partSum);

                    renderRaderEffect.CurrentTechnique.Passes[0].End();
                    renderRaderEffect.End();

                    BaseGame.Device.SetRenderTarget(0, rader.targetSmall);
                    BaseGame.Device.DepthStencilBuffer = depthBufferSmall;

                    BaseGame.Device.Clear(Color.TransparentBlack);

                    renderRaderEffect.CurrentTechnique = renderRaderEffect.Techniques[0];
                    renderRaderEffect.Begin();
                    renderRaderEffect.CurrentTechnique.Passes[0].Begin();

                    BaseGame.Device.VertexDeclaration = del;
                    BaseGame.Device.Vertices[0].SetSource(sectorBuffer, 0, del.GetVertexStrideSize(0));
                    BaseGame.Device.DrawPrimitives(PrimitiveType.TriangleFan, 0, partSum);

                    renderRaderEffect.CurrentTechnique.Passes[0].End();
                    renderRaderEffect.End();
                    BaseGame.Device.SetRenderTarget(0, null);

                    BaseGame.Device.DepthStencilBuffer = old;

                    BaseGame.Device.RenderState.DepthBufferEnable      = true;
                    BaseGame.Device.RenderState.DepthBufferWriteEnable = true;
                }
                catch (Exception ex)
                {
                    Log.Write(ex.Message);
                }
            }