当前位置: 首页>>代码示例>>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;未经允许,请勿转载。