當前位置: 首頁>>代碼示例>>C#>>正文


C# BoxCollider.Intersects方法代碼示例

本文整理匯總了C#中BoxCollider.Intersects方法的典型用法代碼示例。如果您正苦於以下問題:C# BoxCollider.Intersects方法的具體用法?C# BoxCollider.Intersects怎麽用?C# BoxCollider.Intersects使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在BoxCollider的用法示例。


在下文中一共展示了BoxCollider.Intersects方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Update

        protected override void Update(TimeSpan gameTime)
        {
            touchPanelState = WaveServices.Input.TouchPanelState;
            bestValue = float.MaxValue;
            if (touchPanelState.IsConnected && touchPanelState.Count > 0)
            {
                // Calculate the ray
                CalculateRay();

                // Look for all entities in the game...
                for (int i = 0; i < EntityManager.Count; i++)
                {
                    currentEntity = EntityManager.EntityGraph.ElementAt(i); ;

                    entityCollider = currentEntity.FindComponent<BoxCollider>();
                    // ... but only a collidable entities ( entities which have a boxCollider component)
                    if (entityCollider != null)
                    {
                        // Intersect our calculated ray with the entity's boxCollider
                        collisionResult = entityCollider.Intersects(ref ray);
                        // If any collision
                        if (collisionResult.HasValue)
                        {
                            // Check the distance. We want to have the closer to the screen entity, so we want to get the low collisionResult value
                            if (collisionResult.Value < bestValue)
                            {
                                // Send to the scene the new entity picked name
                                (WaveServices.ScreenContextManager.CurrentContext[0] as MyScene).ShowPickedEntity(currentEntity.Name);
                                bestValue = collisionResult.Value;
                            }
                        }
                    }
                }
            }
            else
            {
                (WaveServices.ScreenContextManager.CurrentContext[0] as MyScene).ShowPickedEntity("None");
            }
        }
開發者ID:123asd123A,項目名稱:Samples,代碼行數:39,代碼來源:PickingBehavior.cs

示例2: Update

        protected override void Update(TimeSpan gameTime)
        {
            touchPanelState = WaveServices.Input.TouchPanelState;

            if (touchPanelState.IsConnected && touchPanelState.Count > 0)
            {
                // Calculate the ray
                CalculateRay();

                // Look for all entities in the game...
                Entity auxEntity = currentEntity = null;
                bestValue = float.MaxValue;
                for (int i = 0; i < EntityManager.Count; i++)
                {
                    auxEntity = EntityManager.EntityGraph.ElementAt(i);
                    entityCollider = auxEntity.FindComponent<BoxCollider>();
                    // ... but only a collidable entities ( entities which have a boxCollider component)
                    if (entityCollider != null && ( auxEntity.Name.Contains("box") ||
                                                  auxEntity.Name.Contains("anchor") ||
                                                  auxEntity.Name.Contains("BigBall")) )
                    {
                        // Intersect our calculated ray with the entity's boxCollider
                        collisionResult = entityCollider.Intersects(ref ray);
                        // If any collision
                        if (collisionResult.HasValue && collisionResult.Value > 0.001f)
                        {
                            //Labels.Add("CollisionResult", collisionResult.ToString());
                            //Labels.Add("CollisionValue", collisionResult.Value.ToString());
                            // Check the distance. We want to have the closer to the screen entity, so we want to get the low collisionResult value
                            if (collisionResult.Value < bestValue)
                            {
                                this.currentEntity = auxEntity;
                                bestValue = collisionResult.Value;
                            }
                        }
                    }
                }

                if (this.currentEntity != null)
                {
                    Vector3 entityPosition = this.currentEntity.FindComponent<Transform3D>().Position;
                    Vector3 impulse = entityPosition - this.Camera.Position;
                    this.currentEntity.FindComponent<RigidBody3D>().ApplyLinearImpulse(impulse*FORCE);

                    this.line.StartPoint = ray.Position;
                    this.line.EndPoint = entityPosition;

                    Labels.Add("Entity", this.currentEntity.Name);
                    //Labels.Add("Impulse", impulse.ToString());
                    //Labels.Add("IsActive", this.currentEntity.FindComponent<RigidBody3D>().IsActive.ToString());
                }
                else
                {
                    Labels.Add("Entity", "None");
                    //Labels.Add("Impulse", "0,0,0");
                }
            }

            //RenderManager.LineBatch3D.DrawLine(ref line);
            //RenderManager.LineBatch3D.DrawLine(ref line2);
        }
開發者ID:123asd123A,項目名稱:Samples,代碼行數:61,代碼來源:PickingBehavior.cs


注:本文中的BoxCollider.Intersects方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。