当前位置: 首页>>代码示例>>C#>>正文


C# BoundingSphere.Contains方法代码示例

本文整理汇总了C#中BoundingSphere.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# BoundingSphere.Contains方法的具体用法?C# BoundingSphere.Contains怎么用?C# BoundingSphere.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BoundingSphere的用法示例。


在下文中一共展示了BoundingSphere.Contains方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Contains

        internal override ContainmentType Contains(ref BoundingBox queryAabb, ref BoundingSphere querySphere, float lodVoxelSize)
        {
            ContainmentType outerContainment, innerContainment;

            BoundingSphere sphere = new BoundingSphere(
                m_translation,
                m_radius + lodVoxelSize);

            sphere.Contains(ref queryAabb, out outerContainment);
            if (outerContainment == ContainmentType.Disjoint)
                return ContainmentType.Disjoint;

            sphere.Radius = m_radius - lodVoxelSize;
            sphere.Contains(ref queryAabb, out innerContainment);
            if (innerContainment == ContainmentType.Contains)
                return ContainmentType.Contains;

            return ContainmentType.Intersects;
        }
开发者ID:leandro1129,项目名称:SpaceEngineers,代码行数:19,代码来源:MyCsgSimpleSphere.cs

示例2: outsideOctree

    /// <summary>
    /// List the GameObjects outside this octree leaf.
    /// </summary>
    /// <param name="gameObjects">A list of GameObjects.</param>
    /// <returns>A list of objects from the list that are outside this leaf.</returns>
    public List<GameObject> outsideOctree(List<GameObject> gameObjects)
    {
        List<GameObject> outsideObjects = new List<GameObject>();
        foreach (GameObject obj in gameObjects)
        {
            BoundingSphere objSphere = new BoundingSphere(obj.position.pos(), obj.size);
            if(containerBox.Contains(objSphere) == ContainmentType.Disjoint && objSphere.Contains(containerBox) == ContainmentType.Disjoint)
            {
                //outsideObjects.Add(obj);
            }
        }

        return outsideObjects;
    }
开发者ID:jreese,项目名称:gammadraconis,代码行数:19,代码来源:OctreeLeaf.cs

示例3: Collision

        public bool Collision(BoundingSphere primarySphere, BoundingSphere secondarySphere)
        {
            //example of what a circle code should look like
            //primarySphere = new BoundingSphere(new Vector3(center, 0), center.Length());

            ContainmentType contains = primarySphere.Contains(secondarySphere);

            if (primarySphere.Intersects(secondarySphere) || contains == ContainmentType.Intersects)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
开发者ID:Harmonickey,项目名称:AlexCSPortfolio,代码行数:16,代码来源:GameObject.cs

示例4: Intersects

        public bool Intersects(ref BoundingSphere sphere, ref Vector3[] triangle, out bool onEdge)
        {
            Ray ray = new Ray();
            onEdge = true;
            float? length;
            Vector3 A = triangle[0], B = triangle[1], C = triangle[2];
            Vector3 side = B - A;
            ray = new Ray(A, Vector3.Normalize(side));
            float distSq = 0;
            length = null;
            sphere.Intersects(ref ray, out length);
            if (length != null)
            {
                distSq = (float)length * (float)length;
                if (length > 0 && distSq < side.LengthSquared())
                {
                    return true;
                }
            }

            side = C - A;
            ray.Direction = Vector3.Normalize(side);
            length = null;
            sphere.Intersects(ref ray, out length);
            if (length != null)
            {
                distSq = (float)length * (float)length;
                if (length > 0 && distSq < side.LengthSquared())
                {
                    return true;
                }
            }

            side = C - B;
            ray.Position = B;
            ray.Direction = Vector3.Normalize(side);
            length = null;
            sphere.Intersects(ref ray, out length);
            if (length != null)
            {
                distSq = (float)length * (float)length;
                if (length > 0 && distSq < side.LengthSquared())
                {
                    return true;
                }
            }
            if (sphere.Contains(A) != ContainmentType.Disjoint ||
                sphere.Contains(B) != ContainmentType.Disjoint ||
                sphere.Contains(C) != ContainmentType.Disjoint)
            {
                return true;
            }

            onEdge = false;
            ray.Position = sphere.Center;

            ray.Direction = -getNormalToTriangle(ref triangle);

            Intersects(ref ray, ref triangle, out length);
            if (length != null && length > 0 && length < sphere.Radius)
            {
                return true;
            }

            return false;
        }
开发者ID:pavluntiy,项目名称:superProject,代码行数:66,代码来源:Gaming.cs

示例5: PointsInsideSphere

        /// <summary>
        /// Returns a list of the extremities of the triangle that 
        /// are fully within the sphere.
        /// This is sufficient for collission testing but is not
        /// intended to be an accurate cross section.
        /// Triangles larger than the sphere return points that touch
        /// the edges of the bounding sphere where the triangle sides
        /// penetrates the sphere or if all three points are outside  
        /// tey return the nearest point on the sphere which is sufficient 
        /// to get an approximate section of the sphere.
        /// Returns an empty list if the triangle does not intersect the sphere.
        /// This is an expensive test.  Use at design time only.
        /// </summary>
        public List<Vector3> PointsInsideSphere(BoundingSphere sphere)
        {
            List<Vector3> result = new List<Vector3>();

            // Test which if any points are inside the sphere
            for (int p = 0; p < Vertex.Length; p++)
            {
                if (sphere.Contains(Vertex[p]) != ContainmentType.Disjoint)
                {
                    // == Inside the sphere
                    result.Add(Vertex[p]);
                }
                else
                {
                    // == Outside the sphere
                    // Test both side eminating from the point to see where they
                    // intersect the sphere, if at all.
                    int other = GetAnyOtherIndex(p);
                    Vector3 side = Vertex[other] - Vertex[p];
                    // Important:  The direction of the ray MUST
                    // be normalised otherwise the resulting length
                    // of any intersect is wrong!
                    Ray ray = new Ray(Vertex[p], Vector3.Normalize(side));
                    float distSq = 0;
                    float? length = null;
                    sphere.Intersects(ref ray, out length);
                    if (length != null)
                    {
                        distSq = (float)length * (float)length;
                        if (length > 0 && distSq < side.LengthSquared())
                        {
                            // The side of the triangle hits the edge of the sphere
                            // so save the point of impact.
                            result.Add(ray.Position + (ray.Direction * (float)length));
                        }
                    }
                    else
                    {
                        // Side is fully outside the sphere
                        Vector3? impact = IntersectNearestOnPlane(sphere, p);
                        if (impact != null)
                        {
                            result.Add((Vector3)impact);
                        }
                    }
                    // Get the other corner
                    other = GetOtherIndex(other, p);
                    // Same point but the other edge
                    side = Vertex[other] - Vertex[p];
                    ray.Direction = Vector3.Normalize(side);
                    length = null;
                    sphere.Intersects(ref ray, out length);
                    if (length != null)
                    {
                        distSq = (float)length * (float)length;
                        if (length > 0 && distSq < side.LengthSquared())
                        {
                            // The side of the triangle hits the edge of the sphere
                            // so save the point of impact.
                            result.Add(ray.Position + (ray.Direction * (float)length));
                        }
                    }
                    else
                    {
                        // Side is fully outside the sphere
                        Vector3? impact = IntersectNearestOnPlane(sphere, p);
                        if (impact != null)
                        {
                            result.Add((Vector3)impact);
                        }
                    }
                }
            }
            return result;
        }
开发者ID:gcode-mirror,项目名称:3d-model-prep,代码行数:88,代码来源:Triangle.cs

示例6: IsTouchingButton

 private bool IsTouchingButton(ref float x, ref float y, ref BoundingSphere buttonBounds)
 {
     Vector3 point = new Vector3(x, y, 0);
     buttonBounds.Contains(ref point, out t);
     return (t == ContainmentType.Contains);
 }
开发者ID:igorkiss,项目名称:MonoSnake,代码行数:6,代码来源:ScreenPad.cs

示例7: IntersectBoundingBox

        public ContainmentType IntersectBoundingBox(ref BoundingBox box, float lodLevel)
        {
            box.Inflate(1f);

            bool intersects;
            BoundingSphere sphere = new BoundingSphere(
                    Vector3.Zero,
                    OuterRadius + lodLevel);

            sphere.Intersects(ref box, out intersects);
            if (!intersects)
            {
                return ContainmentType.Disjoint;
            }

            sphere.Radius = InnerRadius - lodLevel;

            ContainmentType ct;
            sphere.Contains(ref box, out ct);
            if (ct == ContainmentType.Contains)
            {
                return ContainmentType.Contains;
            }

            return IntersectBoundingBoxInternal(ref box, lodLevel);
        }
开发者ID:stanhebben,项目名称:SpaceEngineers,代码行数:26,代码来源:MyPlanetShapeProvider.cs

示例8: GetIntersection

 public bool GetIntersection(ref BoundingSphere sphere, ref Vector3 velocityNormal, int polyIndex, out OCTreeIntersection intersection)
 {
     var flag = false;
     intersection = new OCTreeIntersection();
     var plane = Planes[polyIndex];
     if (plane.DotNormal(velocityNormal) < 0f)
     {
         if (plane.DotCoordinate(sphere.Center) < 0f)
         {
             return false;
         }
         if (plane.Intersects(sphere) != PlaneIntersectionType.Intersecting)
         {
             return false;
         }
         var a = Vertices[Indices[polyIndex * 3]];
         var b = Vertices[Indices[(polyIndex * 3) + 1]];
         var c = Vertices[Indices[(polyIndex * 3) + 2]];
         var p = Intersection.ClosestPointOnPlane(sphere.Center, plane);
         if (Intersection.PointInTriangle(p, a, b, c))
         {
             intersection.IntersectionPoint = p;
             intersection.IntersectionNormal = plane.Normal;
             intersection.IntersectionDepth = sphere.Radius - Vector3.Distance(p, sphere.Center);
             intersection.Node = this;
             intersection.PolygonIndex = polyIndex;
             intersection.IntersectType = OCTreeIntersectionType.Inside;
             flag = true;
         }
         else
         {
             float num;
             Vector3 vector5;
             if (sphere.Contains(a) != ContainmentType.Disjoint)
             {
                 intersection.IntersectionPoint = a;
                 intersection.IntersectionNormal = Vector3.Normalize(sphere.Center - a);
                 intersection.IntersectionDepth = sphere.Radius - Vector3.Distance(a, sphere.Center);
                 intersection.Node = this;
                 intersection.PolygonIndex = polyIndex;
                 intersection.IntersectType = OCTreeIntersectionType.Point;
                 return true;
             }
             if (sphere.Contains(b) != ContainmentType.Disjoint)
             {
                 intersection.IntersectionPoint = b;
                 intersection.IntersectionNormal = Vector3.Normalize(sphere.Center - b);
                 intersection.IntersectionDepth = sphere.Radius - Vector3.Distance(b, sphere.Center);
                 intersection.Node = this;
                 intersection.PolygonIndex = polyIndex;
                 intersection.IntersectType = OCTreeIntersectionType.Point;
                 return true;
             }
             if (sphere.Contains(c) != ContainmentType.Disjoint)
             {
                 intersection.IntersectionPoint = c;
                 intersection.IntersectionNormal = Vector3.Normalize(sphere.Center - c);
                 intersection.IntersectionDepth = sphere.Radius - Vector3.Distance(c, sphere.Center);
                 intersection.Node = this;
                 intersection.PolygonIndex = polyIndex;
                 intersection.IntersectType = OCTreeIntersectionType.Point;
                 return true;
             }
             Intersection.ClosestPointOnSegment(sphere.Center, a, b, out num, out vector5);
             if (sphere.Contains(vector5) != ContainmentType.Disjoint)
             {
                 intersection.IntersectionPoint = vector5;
                 intersection.IntersectionNormal = Vector3.Normalize(sphere.Center - vector5);
                 intersection.IntersectionDepth = sphere.Radius - Vector3.Distance(vector5, sphere.Center);
                 intersection.IntersectType = OCTreeIntersectionType.Edge;
                 intersection.Node = this;
                 intersection.PolygonIndex = polyIndex;
                 return true;
             }
             Intersection.ClosestPointOnSegment(sphere.Center, b, c, out num, out vector5);
             if (sphere.Contains(vector5) != ContainmentType.Disjoint)
             {
                 intersection.IntersectionPoint = vector5;
                 intersection.IntersectionNormal = Vector3.Normalize(sphere.Center - vector5);
                 intersection.IntersectionDepth = sphere.Radius - Vector3.Distance(vector5, sphere.Center);
                 intersection.IntersectType = OCTreeIntersectionType.Edge;
                 intersection.Node = this;
                 intersection.PolygonIndex = polyIndex;
                 flag = true;
             }
             else
             {
                 Intersection.ClosestPointOnSegment(sphere.Center, c, a, out num, out vector5);
                 if (sphere.Contains(vector5) != ContainmentType.Disjoint)
                 {
                     intersection.IntersectionPoint = vector5;
                     intersection.IntersectionNormal = Vector3.Normalize(sphere.Center - vector5);
                     intersection.IntersectionDepth = sphere.Radius - Vector3.Distance(vector5, sphere.Center);
                     intersection.IntersectType = OCTreeIntersectionType.Edge;
                     intersection.Node = this;
                     intersection.PolygonIndex = polyIndex;
                     flag = true;
                 }
             }
         }
//.........这里部分代码省略.........
开发者ID:KroneckerX,项目名称:WCell,代码行数:101,代码来源:OCTreeNode.cs

示例9: Contains

 public static ContainmentType Contains(ref BoundingSphere s1, ref BoundingSphere s2)
 {
     return s1.Contains(s2);
 }
开发者ID:CodSav,项目名称:Green-Chicken---V2,代码行数:4,代码来源:CollisionManager.cs

示例10: Contains

        internal override ContainmentType Contains(ref BoundingBox queryAabb, ref BoundingSphere querySphere, float lodVoxelSize)
        {
           ContainmentType outerContainment, innerContainment;

            BoundingSphere sphere = new BoundingSphere(
                m_translation,
                m_outerRadius+ lodVoxelSize);

            sphere.Contains(ref queryAabb, out outerContainment);
            if (outerContainment == ContainmentType.Disjoint)
                return ContainmentType.Disjoint;

            sphere.Radius = m_innerRadius - lodVoxelSize;
            sphere.Contains(ref queryAabb, out innerContainment);
            if (innerContainment == ContainmentType.Contains)
                return ContainmentType.Contains;

            float minDistance = float.MaxValue;
            float maxDistance = -float.MaxValue;

            Vector3 localPosition = queryAabb.Min - m_translation;
            float distance = localPosition.LengthSquared();
            if(distance < 0.01f)
            {
                return ContainmentType.Intersects;
            }

            Vector3I samplePos;
            Vector2 pos = Vector2.Zero;
            MyCsgPrecomputedHelpres.CalculateSamplePosition(ref localPosition, out samplePos, ref pos, m_header.Resolution);

            float value = GetValueForPosition(ref samplePos, ref pos, true);

            minDistance = MathHelper.Min(minDistance, value);
            maxDistance = MathHelper.Max(maxDistance, value);

            localPosition = queryAabb.Max - m_translation;
            distance = localPosition.LengthSquared();
            if (distance < 0.01f)
            {
                return ContainmentType.Intersects;
            }

            MyCsgPrecomputedHelpres.CalculateSamplePosition(ref localPosition, out samplePos, ref pos, m_header.Resolution);

            value = GetValueForPosition(ref samplePos, ref pos, true);

            minDistance = MathHelper.Min(minDistance, value);
            maxDistance = MathHelper.Max(maxDistance, value);

            sphere.Radius = m_innerRadius + maxDistance + lodVoxelSize;
      
            sphere.Contains(ref queryAabb, out outerContainment);
            if (outerContainment == ContainmentType.Disjoint)
                return ContainmentType.Disjoint;

            sphere.Radius = m_innerRadius + minDistance - lodVoxelSize;
            sphere.Contains(ref queryAabb, out innerContainment);
            if (innerContainment == ContainmentType.Contains)
                return ContainmentType.Contains;
            
            return ContainmentType.Intersects;
        }
开发者ID:Krulac,项目名称:SpaceEngineers,代码行数:63,代码来源:MyCsgShapePrecomputed.cs

示例11: Explode

        public void Explode(Vector3 pos, float radius, bool particles)
        {
            BoundingSphere sphere = new BoundingSphere(pos, radius);
            for(float x=pos.X-radius;x<pos.X+radius;x+= Voxel.SIZE)
                for(float y=pos.Y-radius;y<pos.Y+radius;y+= Voxel.SIZE)
                    for (float z = pos.Z - radius; z < pos.Z + radius; z+= Voxel.SIZE)
                    {
                        Vector3 screen = new Vector3(x, y, z);
                        Vector3 world = FromScreenSpace(screen);

                        if ((int)world.Z >= Z_SIZE - 1) continue;

                        if (sphere.Contains(screen) == ContainmentType.Contains)
                        {
                            Voxel v = GetVoxel(screen);
                            if (v.Active && (v.Destructable > 0 || v.Type== VoxelType.Ground))
                            {
                                SetVoxelActive((int)world.X, (int)world.Y, (int)world.Z, false);
                                if(Helper.Random.Next(20)==1 && particles) ParticleController.Instance.Spawn(screen, new Vector3(-0.05f + ((float)Helper.Random.NextDouble() * 0.1f), -0.05f + ((float)Helper.Random.NextDouble() * 0.1f), -((float)Helper.Random.NextDouble() * 1f)), 0.25f, new Color(v.SR, v.SG, v.SB), 1000, true);
                            }
                        }
                    }
        }
开发者ID:GarethIW,项目名称:LD27,代码行数:23,代码来源:VoxelWorld.cs

示例12: split

    /// <summary>
    /// Split this octree leaf into child leaves.
    /// </summary>
    protected void split()
    {
        Vector3 half = (containerBox.Max - containerBox.Min) / 2;
        Vector3 halfx = Vector3.UnitX * half;
        Vector3 halfy = Vector3.UnitY * half;
        Vector3 halfz = Vector3.UnitZ * half;
        BoundingBox[] boxes = {
            new BoundingBox(containerBox.Min, containerBox.Min + half),
            new BoundingBox(containerBox.Min + halfx, containerBox.Min + half + halfx),
            new BoundingBox(containerBox.Min + halfy, containerBox.Min + half + halfy),
            new BoundingBox(containerBox.Min + halfz, containerBox.Min + half + halfz),
            new BoundingBox(containerBox.Min + halfx + halfy, containerBox.Min + half + halfx + halfy),
            new BoundingBox(containerBox.Min + halfx + halfz, containerBox.Min + half + halfx + halfz),
            new BoundingBox(containerBox.Min + halfy + halfz, containerBox.Min + half + halfy + halfz),
            new BoundingBox(containerBox.Min + half, containerBox.Max)
        };

        childLeaves.Clear();
        foreach( BoundingBox tempBox in boxes)
        {
            OctreeLeaf tempLeaf = new OctreeLeaf(tempBox, maxDepth, currentDepth+1);
            foreach(GameObject obj in containedObjects){
                BoundingSphere objSphere = new BoundingSphere(obj.position.pos(), obj.size);
                if (tempBox.Contains(objSphere) != ContainmentType.Disjoint || objSphere.Contains(tempBox) != ContainmentType.Disjoint)
                {
                    tempLeaf.containedObjects.Add(obj);
                }
            }
            if (currentDepth < maxDepth && tempLeaf.containedObjects.Count != 0){

                tempLeaf.split();
            }
            childLeaves.Add(tempLeaf);
        }

        if (debugOctreeDepth)
        {
                Console.WriteLine("Current node depth: " + currentDepth + " Next depth: " + (currentDepth + 1));
        }
    }
开发者ID:jreese,项目名称:gammadraconis,代码行数:43,代码来源:OctreeLeaf.cs

示例13: Overlap

        public bool Overlap(BoundingSphere sphere)
        {
            for (int t = 0; t < tiles.Length; t++)
            {
                if (!tiles[t].BoundingBox.Intersects(sphere))
                    continue;
                for (int i = 0; i < indices.Length / 3; i++)
                {
                    int index0 = indices[i * 3];
                    int index1 = indices[i * 3 + 1];
                    int index2 = indices[i * 3 + 2];

                    Vector3[] triangle = new Vector3[]
                    {
                         tiles[t].Vertices[index0].Position,
                         tiles[t].Vertices[index1].Position,
                         tiles[t].Vertices[index2].Position,
                    };

                    for(int j = 0; j < 3; j++ )
                        if( sphere.Contains(triangle[j]) != ContainmentType.Disjoint )
                            return true;
                }
            }

            return false;
        }
开发者ID:koenbollen,项目名称:canyon,代码行数:27,代码来源:Terrain.cs

示例14: Process

        public override void Process(Camera camera, GameTime gameTime)
        {
#if DEBUG
            stopwatch.Restart();
#endif
            Game.GraphicsDevice.SetRenderTarget(Outputs["Light"]);
            Game.GraphicsDevice.Clear(new Color(AmbientLight.R, AmbientLight.G, AmbientLight.B, 0));

            Vector3[] frustumCorners = camera.Frustum.GetCorners();
            for (int i = 0; i < 4; i++)
                frustumCorners[i] = frustumCorners[i + 4];

            Vector3 corner = frustumCorners[2];
            frustumCorners[2] = frustumCorners[3];
            frustumCorners[3] = corner;

            pointLightEffect.Parameters["CameraPosition"].SetValue(camera.Position);
            pointLightEffect.Parameters["FarPlane"].SetValue(camera.FarPlane);
            pointLightEffect.Parameters["FrustumCorners"].SetValue(camera.Frustum.GetCorners());
            pointLightEffect.Parameters["Normal"].SetValue(Inputs["Normal"]);
            pointLightEffect.Parameters["Depth"].SetValue(Inputs["Depth"]);
            pointLightEffect.Parameters["Color"].SetValue(Inputs["Color"]);

            spotLightEffect.Parameters["CameraPosition"].SetValue(camera.Position);
            spotLightEffect.Parameters["FarPlane"].SetValue(camera.FarPlane);
            spotLightEffect.Parameters["FrustumCorners"].SetValue(camera.Frustum.GetCorners());
            spotLightEffect.Parameters["Normal"].SetValue(Inputs["Normal"]);
            spotLightEffect.Parameters["Depth"].SetValue(Inputs["Depth"]);
            spotLightEffect.Parameters["Color"].SetValue(Inputs["Color"]);

            directionalLightEffect.Parameters["CameraPosition"].SetValue(camera.Position);
            directionalLightEffect.Parameters["FarPlane"].SetValue(camera.FarPlane);
            directionalLightEffect.Parameters["FrustumCorners"].SetValue(camera.Frustum.GetCorners());
            directionalLightEffect.Parameters["Normal"].SetValue(Inputs["Normal"]);
            directionalLightEffect.Parameters["Depth"].SetValue(Inputs["Depth"]);
            directionalLightEffect.Parameters["Color"].SetValue(Inputs["Color"]);

            #region PointLights

            Game.GraphicsDevice.BlendState = BlendState.Additive;
            foreach (PointLight light in Lights.OfType<PointLight>())
            {
                // FIXME
                BoundingSphere boundingSphere = new BoundingSphere(light.Position, light.Radius);
                if (boundingSphere.Contains(camera.Position) != ContainmentType.Disjoint)
                    Game.GraphicsDevice.RasterizerState = RasterizerState.CullNone;
                else
                    Game.GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;

                pointLightEffect.Parameters["LightPosition"].SetValue(light.Position);
                pointLightEffect.Parameters["LightColor"].SetValue(light.Color.ToVector4());
                pointLightEffect.Parameters["LightIntensity"].SetValue(light.Intensity);
                pointLightEffect.Parameters["LightRadius"].SetValue(light.Radius);

                sphere.Position = light.Position;
                sphere.Scale = new Vector3(light.Radius * 1.2f);
                sphere.Effect = pointLightEffect;
                sphere.Draw(camera, gameTime);
            }

            #endregion
            #region SpotLights

            Game.GraphicsDevice.BlendState = BlendState.Additive;
            foreach (SpotLight light in Lights.OfType<SpotLight>())
            {
                BoundingSphere boundingSphere = new BoundingSphere(light.Position, light.Radius);
                if (boundingSphere.Contains(camera.Position) == ContainmentType.Contains)
                    Game.GraphicsDevice.RasterizerState = RasterizerState.CullClockwise;
                else
                    Game.GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;

                spotLightEffect.Parameters["LightPosition"].SetValue(light.Position);
                spotLightEffect.Parameters["LightColor"].SetValue(light.Color.ToVector4());
                spotLightEffect.Parameters["LightIntensity"].SetValue(light.Intensity);
                spotLightEffect.Parameters["LightRadius"].SetValue(light.Radius);
                spotLightEffect.Parameters["LightDirection"].SetValue(light.Direction);
                spotLightEffect.Parameters["LightAngle"].SetValue(light.Angle);

                // FIXME
                cone.Position = light.Position;
                cone.Rotation = Vector3Utils.GetQuaternion(Vector3.Up, light.Direction);

                float vScale = light.Radius;
                float hScale = (float)Math.Cos(light.Angle) * light.Radius * 1.2f;

                cone.Scale = new Vector3(hScale, vScale, hScale);
                cone.Effect = spotLightEffect;
                cone.Draw(camera, gameTime);
            }

            #endregion
            #region DirectionalLights

            Game.GraphicsDevice.BlendState = BlendState.Additive;
            foreach (DirectionalLight light in Lights.OfType<DirectionalLight>())
            {
                directionalLightEffect.Parameters["LightColor"].SetValue(light.Color.ToVector4());
                directionalLightEffect.Parameters["LightIntensity"].SetValue(light.Intensity);
                directionalLightEffect.Parameters["LightDirection"].SetValue(light.Direction);
//.........这里部分代码省略.........
开发者ID:FreeCraft,项目名称:xna-scenemanager,代码行数:101,代码来源:LightProcessor.cs

示例15: MoveSphere

 public void MoveSphere(ref BoundingSphere sphere, ref Vector3 sphereVelocity, float Friction, ref List<OCTreeIntersection> sphereColliders)
 {
     int num4;
     var vector = sphereVelocity;
     var velocityNormal = Vector3.Normalize(vector);
     var sphere2 = new BoundingSphere(sphere.Center + vector, sphere.Radius);
     var list = new List<OCTreeIntersection>();
     sphere2.Radius = sphere.Radius + vector.Length();
     GetIntersectingPolygons(ref sphere2, ref velocityNormal, ref list);
     sphere2.Radius = sphere.Radius;
     for (var i = 0; i < 5; i++)
     {
         var num2 = 0;
         for (var j = 0; j < list.Count; j++)
         {
             var intersection = list[j];
             if (intersection.Node.UpdateIntersection(ref intersection, ref sphere2, ref velocityNormal) &&
                 (sphere2.Contains(intersection.IntersectionPoint) != ContainmentType.Disjoint))
             {
                 num2++;
                 var vector3 =
                     (intersection.IntersectionNormal * (intersection.IntersectionDepth + 0.001f));
                 sphere2.Center += vector3;
                 vector = sphere2.Center - sphere.Center;
                 velocityNormal = Vector3.Normalize(vector);
                 var flag = false;
                 num4 = 0;
                 while (num4 < sphereColliders.Count)
                 {
                     if ((sphereColliders[num4].Node == intersection.Node) &&
                         (sphereColliders[num4].PolygonIndex == intersection.PolygonIndex))
                     {
                         flag = true;
                         break;
                     }
                     num4++;
                 }
                 if (!flag)
                 {
                     sphereColliders.Add(intersection);
                 }
             }
         }
         if (num2 == 0)
         {
             break;
         }
     }
     var flag2 = false;
     for (num4 = 0; num4 < sphereColliders.Count; num4++)
     {
         if (Vector3.Dot(sphereColliders[num4].IntersectionNormal, Vector3.Up) > 0.5f)
         {
             vector -= ((vector * (Vector3.One - Vector3.Up)) * Friction);
             flag2 = true;
             break;
         }
     }
     if (!flag2)
     {
         vector -= (((vector * (Vector3.One - Vector3.Up)) * Friction) * 0.5f);
     }
     sphereVelocity = vector;
     sphere = sphere2;
 }
开发者ID:WCell,项目名称:WCell-Terrain,代码行数:65,代码来源:OCTree.cs


注:本文中的BoundingSphere.Contains方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。