Ejemplo n.º 1
0
        public void Update(GameTime gameTime)
        {
            if (timer > 0)
            {
                timer -= gameTime.ElapsedGameTime.TotalSeconds;
                scale += 0.12f;
                alpha -= 0.016f;
            }
            else
                isActive = false;

            BoundingSphere bombSphere = new BoundingSphere(position, explosionModel.Meshes[0].BoundingSphere.Radius * scale);
            for (int i = 0; i < GamePlay.asteroidList.Length; i++)
            {
                if (GamePlay.asteroidList[i].isActive)
                {
                    BoundingSphere asteroidSphere = new BoundingSphere(GamePlay.asteroidList[i].position,
                        GamePlay.asteroidModel.Meshes[0].BoundingSphere.Radius * 0.95f);
                    if (asteroidSphere.Intersects(bombSphere))
                    {
                        //destroy asteroid
                        MainClass.soundBank.PlayCue("explosion2");
                        GamePlay.asteroidList[i].isActive = false;
                        GamePlay.playerList[index].score += GameConstants.KillBonus;
                        return; //exit the loop
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="center">center position of the sphere</param>
        /// <param name="radius">radius of the sphere</param>
        public CollideSphere(Vector3 center, float radius)
            : base()
        {
            localCenter = center;

            boundingSphere = new BoundingSphere(localCenter, radius);
        }
Ejemplo n.º 3
0
        public Planet(Vector3 Position, float Scale, float ParentMass, Vector3 OrbitalPlaneNormal)
            : base()
        {
            Body.CreateUVSphere(32, 32, out ModelVertices, out ModelIndices);
            effect = Manager.TexturedEffect;

            NoiseMap = Manager.WrappedNoiseTextures[MyGame.random.Next(Manager.WrappedNoiseTextures.Length)];
            Color[] StaticNoise = Manager.GenerateStaticNoise(5, 5);
            for (int i = 0; i < StaticNoise.Length; i++)
            {
                StaticNoise[i] = Color.Lerp(planetColors[MyGame.random.Next(planetColors.Length)]
                    , StaticNoise[i]
                    , 0.1f * (float)MyGame.random.NextDouble());
            }
            ColorMap = new Texture2D(MyGame.graphics.GraphicsDevice, 5, 5);
            ColorMap.SetData<Color>(StaticNoise);

            RotationAxis = Manager.GetRandomNormal();
            RotationTime = (float)MyGame.random.NextDouble();
            Bounds = new BoundingSphere(Position, 2.0f * Scale);
            this.Transforms = new ScalePositionRotation(
                Scale
                , Position
                , Matrix.CreateFromAxisAngle(RotationAxis, RotationTime));
            Mass = 10.0f * (float)(4.0 / 3.0 * Math.PI * Math.Pow(Transforms.Scale, 3.0));

            this.Velocity = Body.GetRandomInitialOrbitVelocity(Position, OrbitalPlaneNormal, ParentMass, Mass);
        }
 public GameObject()
 {
     Model = null;
     Position = Vector3.Zero;
     Rotation = Vector3.Zero;
     BoundingSphere = new BoundingSphere();
 }
Ejemplo n.º 5
0
        public Character(string textureName, Vector2 position, ContentManager content, int frameCount)
        {
            mContent = content;
            mTextureName = textureName;
            mPosition = position;
            mAge = age.BABY;
            mStates = states.SPAWNING;
            mSpeed = new Vector2(1.0f, 0.25f);
            //mSpeed = new Vector2(0, 0);

            mSprite = new AnimatedSprite();
            //mSprite.Load(mContent, "AnimatedSprites/" + mTextureName, frameCount, 30, 149, 139, false);
            mSprite.Load(mContent, "AnimatedSprites/" + mTextureName, frameCount, 0.125f, 128, 128, false);

            bSphere = new BoundingSphere(new Vector3(position.X + mSprite.getWidth() / 2, position.Y + mSprite.getHeight() / 2, 0), mSprite.getWidth() / 2);
            distance = 10000;
            destination = Vector2.Zero;
            timeEating = 2.0f;

            timeOnFire = 0.5f;

            respawnRate = 3.0f;
            remove = false;
            multipleOfTwo = false;
            hacktex = Class1.CreateCircle((int)mSprite.getWidth() / 2, Color.Yellow);

            timespawning = 2.0f;
        }
Ejemplo n.º 6
0
        protected override void GetAllBroadcastersInMyRange(ref HashSet<MyDataBroadcaster> relayedBroadcasters, long localPlayerId, HashSet<long> gridsQueued)
        {
            var sphere = new BoundingSphere(Parent.PositionComp.GetPosition(), 0.5f);

            MyRadioBroadcasters.GetAllBroadcastersInSphere(sphere, m_broadcastersInRange);

            foreach (var broadcaster in m_broadcastersInRange)
            {
                if (relayedBroadcasters.Contains(broadcaster))
                    continue;

                relayedBroadcasters.Add(broadcaster);

                if (!CanIUseIt(broadcaster, localPlayerId))
                    continue;

                if (broadcaster.Parent is IMyComponentOwner<MyDataReceiver>)
                {
                    MyDataReceiver radioReceiver;
                    if ((broadcaster.Parent as IMyComponentOwner<MyDataReceiver>).GetComponent(out radioReceiver))
                    {
                        radioReceiver.UpdateBroadcastersInRange(relayedBroadcasters, localPlayerId, gridsQueued);
                    }
                }
            }
        }
        public BoundingSphere GetBoundingSphere(Vector3 aLowest, Vector3 aHighest, Vector3 aTranslation, Vector3 aTile)
        {
            Vector3 temporaryRadius = new Vector3((aHighest.X - aLowest.X) / 2, (aHighest.Y - aLowest.Y) / 2, (aHighest.Z - aLowest.Z) / 2) * aTile;
            BoundingSphere temporarySphere = new BoundingSphere(aTranslation, (temporaryRadius.X + temporaryRadius.Y + temporaryRadius.Z) / 3);

            return temporarySphere;
        }
Ejemplo n.º 8
0
Archivo: AI.cs Proyecto: HazWard/Tank3D
 public override void Initialize()
 {
     PourcentageVie = 1;
     SphereCollision = new BoundingSphere(Position, RAYON_COLLISION);
     CompteurCollision = 0;
     base.Initialize();
 }
Ejemplo n.º 9
0
 public static bool Intersect(Triangle triangle, BoundingSphere sphere, out object intersection)
 {
     intersection = null;
     return Common.Intersection.Intersect(sphere, triangle.A.Position, out intersection) ||
         Common.Intersection.Intersect(sphere, triangle.B.Position, out intersection) ||
         Common.Intersection.Intersect(sphere, triangle.C.Position, out intersection);
 }
Ejemplo n.º 10
0
        public override void Draw(GraphicsDevice device, Camera cam)
        {
            if (filter == null)
            {
                return;
            }

            Mesh mesh = filter.meshToRender;
            BoundingSphere sphere = new BoundingSphere(transform.TransformPoint(filter.boundingSphere.Center), filter.boundingSphere.Radius * Math.Max(transform.lossyScale.x, Math.Max(transform.lossyScale.y, transform.lossyScale.z)));
            bool cull = cam.DoFrustumCulling(ref sphere);
            if (cull)
            {
            #if DEBUG
                if (Camera.logRenderCalls)
                {
                    Debug.LogFormat("VP cull mesh {0} with center {1} radius {2} cam {3} at {4}", gameObject, sphere.Center, sphere.Radius, cam.gameObject, cam.transform.position);
                }
            #endif
                return;
            }

            if (filter.CanBatch())
            {
                cam.BatchRender(filter.meshToRender, sharedMaterials, transform);
            }
        }
Ejemplo n.º 11
0
        public unsafe static BoundingBox ComputeBounds(this VertexBufferBinding vertexBufferBinding, ref Matrix matrix, out BoundingSphere boundingSphere)
        {
            var positionOffset = vertexBufferBinding.Declaration
                .EnumerateWithOffsets()
                .First(x => x.VertexElement.SemanticAsText == "POSITION")
                .Offset;

            var boundingBox = BoundingBox.Empty;
            boundingSphere = new BoundingSphere();

            var vertexStride = vertexBufferBinding.Declaration.VertexStride;
            fixed (byte* bufferStart = &vertexBufferBinding.Buffer.GetSerializationData().Content[vertexBufferBinding.Offset])
            {
                // Calculates bounding box and bounding sphere center
                byte* buffer = bufferStart + positionOffset;
                for (int i = 0; i < vertexBufferBinding.Count; ++i)
                {
                    var position = (Vector3*)buffer;
                    Vector3 transformedPosition;

                    Vector3.TransformCoordinate(ref *position, ref matrix, out transformedPosition);

                    // Prepass calculate the center of the sphere
                    Vector3.Add(ref transformedPosition, ref boundingSphere.Center, out boundingSphere.Center);
                    
                    BoundingBox.Merge(ref boundingBox, ref transformedPosition, out boundingBox);
                    
                    buffer += vertexStride;
                }

                //This is the center of our sphere.
                boundingSphere.Center /= (float)vertexBufferBinding.Count;

                // Calculates bounding sphere center
                buffer = bufferStart + positionOffset;
                for (int i = 0; i < vertexBufferBinding.Count; ++i)
                {
                    var position = (Vector3*)buffer;
                    Vector3 transformedPosition;

                    Vector3.TransformCoordinate(ref *position, ref matrix, out transformedPosition);


                    //We are doing a relative distance comparasin to find the maximum distance
                    //from the center of our sphere.
                    float distance;
                    Vector3.DistanceSquared(ref boundingSphere.Center, ref transformedPosition, out distance);

                    if (distance > boundingSphere.Radius)
                        boundingSphere.Radius = distance;

                    buffer += vertexStride;
                }

                //Find the real distance from the DistanceSquared.
                boundingSphere.Radius = (float)Math.Sqrt(boundingSphere.Radius);
            }

            return boundingBox;
        }
Ejemplo n.º 12
0
 public void RayInterSection_OutsideSpherePointingAway_NoIntersection()
 {
     var sphere = new BoundingSphere(new Point3D(0.2, 0.3, 0), 1.0);
     var ray = new Ray3D(sphere.Center + new Vector3D(0.2, 0.3, sphere.Radius), new Vector3D(1, 0.1, 0.1));
     Point3D[] result;
     Assert.IsFalse(sphere.RayIntersection(ray, out result));
 }
Ejemplo n.º 13
0
        public void Draw(ref BoundingSphere sphere, BasicEffect effect, ref Color vertexColor)
        {
            graphicsDevice.SetVertexBuffer(vertexBuffer);

            Matrix scale;
            Matrix.CreateScale(sphere.Radius, out scale);
            Matrix translation;
            Matrix.CreateTranslation(ref sphere.Center, out translation);
            Matrix transform;
            Matrix.Multiply(ref scale, ref translation, out transform);

            effect.World = transform;
            effect.DiffuseColor = vertexColor.ToVector3();

            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                //render each circle individually
                graphicsDevice.DrawPrimitives(
                        PrimitiveType.LineStrip,
                        0,
                        sphereResolution);
                graphicsDevice.DrawPrimitives(
                        PrimitiveType.LineStrip,
                        sphereResolution + 1,
                        sphereResolution);
                graphicsDevice.DrawPrimitives(
                        PrimitiveType.LineStrip,
                        (sphereResolution + 1) * 2,
                        sphereResolution);
            }
        }
        public static void Render(Primitive prim, RenderContext context, Color color)
        {
            if (prim.PrimType == Forever.Physics.Collide.CollideType.Sphere)
              {
            Sphere sphere = (Sphere)prim;
            BoundingSphere bs = new BoundingSphere(prim.Body.Position, sphere.Radius);
            BoundingSphereRenderer.Render(bs, context, color);
              }
              else if (prim.PrimType == Forever.Physics.Collide.CollideType.Box)
              {
            Box b = (Box)prim;
            Matrix world = prim.Body.World;
            BoundingBoxRenderer.Render(
              BoundingBox.CreateFromPoints(b.LocalVerts()),
              context.GraphicsDevice,
              world * b.OffsetMatrix,
              context.Camera.View,
              context.Camera.Projection,
              color
            );
              }else if(prim.PrimType == Forever.Physics.Collide.CollideType.Plane){

              Render((Forever.Physics.Collide.Plane)prim, context, color);
              }
              else
              {
            throw new Exception("I don't know how to draw that!");
              }
        }
Ejemplo n.º 15
0
 public void RayPointingAwayFromBoundingSphereShouldBeIntersected()
 {
     var boundingSphere = new BoundingSphere(new Vector(0, 0, 0), 1);
     var ray = new Ray(new Vector(0, -10, 0), new Vector(0, -1, 0));
     var result = ray.Intersects(boundingSphere);
     Assert.That(result, Is.Null);
 }
Ejemplo n.º 16
0
        /// <summary>
        /// Returns the raw number of triangles actually checked for collision 
        /// (all triangles in all nodes that are reached)
        /// </summary>
        /// <param name="b"></param>
        /// <param name="result"></param>
        public void checkedFaces(BoundingSphere b, LinkedList<Face> result)
        {
            LinkedList<BspNode> toProcess = new LinkedList<BspNode>();
            toProcess.AddLast(mRoot);

            while (toProcess.Count > 0)
            {
                BspNode curNode = toProcess.First.Value;
                toProcess.RemoveFirst();

                if (curNode.separatingPlane.Normal.X == 0.0f &&
                    curNode.separatingPlane.Normal.Y == 0.0f &&
                    curNode.separatingPlane.Normal.Z == 0.0f &&
                    curNode.separatingPlane.D == 0.0f)
                {
                    foreach (Face f in curNode.faces)
                        result.AddLast(f);

                }

                else
                {
                    PlaneIntersectionType side = curNode.separatingPlane.Intersects(b);

                    if (side == PlaneIntersectionType.Back) toProcess.AddLast(curNode.neg);
                    else if (side == PlaneIntersectionType.Front) toProcess.AddLast(curNode.pos);
                    else
                    {
                        toProcess.AddLast(curNode.pos);
                        toProcess.AddLast(curNode.neg);
                    }
                }
            }
        }
Ejemplo n.º 17
0
 public void RayPointingThroughBoundingSphereFromRightShouldBeIntersected()
 {
     var boundingSphere = new BoundingSphere(new Vector(0, 0, 0), 1);
     var ray = new Ray(new Vector(10, 0, 0), new Vector(-1, 0, 0));
     var result = ray.Intersects(boundingSphere);
     Assert.That(result, Is.Not.Null);
 }
Ejemplo n.º 18
0
        public static void DrawSphereSpikes(BoundingSphere sphere, GraphicsDevice device, BasicEffect basicEffect, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix)
        {
            Vector3 up = sphere.Center + sphere.Radius * Vector3.Up;
            Vector3 down = sphere.Center + sphere.Radius * Vector3.Down;
            Vector3 right = sphere.Center + sphere.Radius * Vector3.Right;
            Vector3 left = sphere.Center + sphere.Radius * Vector3.Left;
            Vector3 forward = sphere.Center + sphere.Radius * Vector3.Forward;
            Vector3 back = sphere.Center + sphere.Radius * Vector3.Backward;

            VertexPositionColor[] sphereLineVertices = new VertexPositionColor[6];
            sphereLineVertices[0] = new VertexPositionColor(up, Color.White);
            sphereLineVertices[1] = new VertexPositionColor(down, Color.White);
            sphereLineVertices[2] = new VertexPositionColor(left, Color.White);
            sphereLineVertices[3] = new VertexPositionColor(right, Color.White);
            sphereLineVertices[4] = new VertexPositionColor(forward, Color.White);
            sphereLineVertices[5] = new VertexPositionColor(back, Color.White);

            basicEffect.World = worldMatrix;
            basicEffect.View = viewMatrix;
            basicEffect.Projection = projectionMatrix;
            basicEffect.VertexColorEnabled = true;
            foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
               // device.VertexDeclaration = new VertexDeclaration(device, VertexPositionColor.VertexElements);
                device.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.LineList, sphereLineVertices, 0, 3);
            }
        }
Ejemplo n.º 19
0
 public List<Actor> Intersect(BoundingSphere sphere)
 {
     UpdateDirty();
     var result = new List<Actor>();
     Root.Intersect(ref sphere, result);
     return result;
 }
        public static void Render(BoundingSphere sphere,
                                  GraphicsDevice graphicsDevice,
                                  Matrix view,
                                  Matrix projection,
                                  Color color,
                                  Guid id)
        {
            var subscription = Subscriptions[id];

            graphicsDevice.SetVertexBuffer(subscription.VertexBuffer);
            subscription.BasicEffect.World = Matrix.CreateScale(sphere.Radius)*
                                                   Matrix.CreateTranslation(sphere.Center);
            subscription.BasicEffect.View = view;
            subscription.BasicEffect.Projection = projection;
            subscription.BasicEffect.DiffuseColor = color.ToVector3();

            foreach (var pass in subscription.BasicEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                graphicsDevice.DrawPrimitives(PrimitiveType.LineStrip, 0, SphereResolution);
                graphicsDevice.DrawPrimitives(PrimitiveType.LineStrip,
                                              SphereResolution + 1,
                                              SphereResolution);
                graphicsDevice.DrawPrimitives(PrimitiveType.LineStrip,
                                              (SphereResolution + 1)*2,
                                              SphereResolution);
            }
        }
Ejemplo n.º 21
0
        public override void Update(GameTime gameTime)
        {
            float timeDelta = (float)gameTime.ElapsedGameTime.TotalSeconds;

            center = pos + new Vector2(sprite.Width / 2, sprite.Height / 2);

            sphere = new BoundingSphere(new Vector3(center.X, center.Y, 0), radius);

            target = new Vector2(Game1.Instance.PlayerCell.center.X - center.X, Game1.Instance.PlayerCell.center.Y - center.Y);

            comboRadius = (Game1.Instance.PlayerCell.radius + radius);
            distance = Vector2.Distance(Game1.Instance.PlayerCell.center, center) - comboRadius;

            look.X = (float)Math.Sin(rotation);
            look.Y = (float)-Math.Cos(rotation);

            rotation = (float)Math.Acos(Vector2.Dot(basis, target) / target.Length());

            if (Game1.Instance.PlayerCell.center.X < center.X)
            {
                rotation = -rotation;
            }

            CheckDistance(timeDelta);
        }
Ejemplo n.º 22
0
 public static BoundingSphere MergeWith(
     this BoundingSphere first,
     BoundingSphere second
     )
 {
     return BoundingSphere.CreateMerged(first, second);
 }
        protected BoundingSphere CalculateBoundingSphere()
        {
            BoundingSphere mergedSphere = new BoundingSphere();
            BoundingSphere[] boundingSpheres;
            int index = 0;
            int meshCount = Model.Meshes.Count;

            boundingSpheres = new BoundingSphere[meshCount];
            foreach (ModelMesh mesh in Model.Meshes)
            {
                boundingSpheres[index++] = mesh.BoundingSphere;
            }

            mergedSphere = boundingSpheres[0];
            if ((Model.Meshes.Count) > 1)
            {
                index = 1;
                do
                {
                    mergedSphere = BoundingSphere.CreateMerged(mergedSphere,
                        boundingSpheres[index]);
                    index++;
                } while (index < Model.Meshes.Count);
            }
            mergedSphere.Center.Y = 0;
            return mergedSphere;
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public void Initialize()
        {
            // TODO: Add your initialization code here
            content = Game.Content;

            position = Vector3.Zero;
            direction = Vector3.Zero;
            right = Vector3.Right;
            up = Vector3.Up;

            int max = 500000;
            int min = -460000;

            position = new Vector3(randomiser.Next(min, max),
                randomiser.Next(5000,450000),
                randomiser.Next(min, max));

            int random = randomiser.Next(10);

            model = content.Load<Model>("Models/PowerUp/powerup");
            boundingSphere = new BoundingSphere(position, 5000.0f);

            rotDir = randomiser.Next(0,1);

            world = Matrix.CreateTranslation(position);

            Effect cartoonEffect = content.Load<Effect>("CartoonShader/CartoonEffect");
            ChangeEffectUsedByModel(model, cartoonEffect);
        }
Ejemplo n.º 25
0
        //  This explosive collides with something after which it must explode
        public override void Explode()
        {
            if (m_isExploded)
                return;

            base.Explode();
            MarkForClose();

            if (m_isExploded)
            {
                const int stepsCount = 5;
                Vector3 directionDelta = WorldMatrix.Forward * (7 * m_ammoProperties.ExplosionRadius / stepsCount);

                for (int i = 0; i < stepsCount; i++)
                {
                    MyExplosion newExplosion = MyExplosions.AddExplosion();
                    if (newExplosion != null)
                    {
                        Vector3 explosionPos = GetPosition() + directionDelta * i;
                        BoundingSphere boundingSphere = new BoundingSphere(explosionPos, m_ammoProperties.ExplosionRadius);
                        newExplosion.Start(m_ammoProperties.HealthDamage, m_ammoProperties.ShipDamage, m_ammoProperties.EMPDamage, MyExplosionTypeEnum.BOMB_EXPLOSION, boundingSphere, MyExplosionsConstants.EXPLOSION_LIFESPAN, CascadedExplosionLevel, ownerEntity: OwnerEntity, hitEntity: m_collidedEntity, playSound: i == 0 ? true : false);
                    }
                }
            }
        }
 public override void Update(GameTime gameTime)
 {
     if (!absorbed)
         velocity = new Vector3(0, 0, -0.5f);
     position += velocity;
     sphere = new BoundingSphere(position, 2);
     worldMat = Matrix.CreateScale(0.8f) * Matrix.CreateRotationX(rotation.X) * Matrix.CreateRotationY(rotation.Y) * Matrix.CreateRotationZ(rotation.Z) * Matrix.CreateTranslation(position);
     checkBounds();
     switch (rot)
     {
         case 0:
             rotate(new Vector3(MathHelper.ToRadians(2), 0, 0));
             break;
         case 1:
             rotate(new Vector3(0, MathHelper.ToRadians(2), 0));
             break;
         case 2:
             rotate(new Vector3(0, 0, MathHelper.ToRadians(2)));
             break;
         case 3:
             rotate(new Vector3(-MathHelper.ToRadians(2), 0, 0));
             break;
         case 4:
             rotate(new Vector3(0, -MathHelper.ToRadians(2), 0));
             break;
         case 5:
             rotate(new Vector3(0, 0, -MathHelper.ToRadians(2)));
             break;
     }
 }
Ejemplo n.º 27
0
        public void DrawBoundingSphere(BoundingSphere sphere)
        {
            const int numCircleSegments = 12;

            float step = 2.0f * (float)Math.PI / numCircleSegments;

            for (int i = 0; i < numCircleSegments; ++i) {
                float u0 = (float)Math.Cos(step * i) * sphere.Radius;
                float v0 = (float)Math.Sin(step * i) * sphere.Radius;
                float u1 = (float)Math.Cos(step * (i + 1)) * sphere.Radius;
                float v1 = (float)Math.Sin(step * (i + 1)) * sphere.Radius;

                // xy
                DrawLine(new Vector3(u0, v0, 0) + sphere.Center,
                         new Vector3(u1, v1, 0) + sphere.Center);

                // xz
                DrawLine(new Vector3(u0, 0, v0) + sphere.Center,
                         new Vector3(u1, 0, v1) + sphere.Center);

                // yz
                DrawLine(new Vector3(0, u0, v0) + sphere.Center,
                         new Vector3(0, u1, v1) + sphere.Center);
            }
        }
        public void Update(Vector3 position)
        {
            Clear();

            if (!OnCheckControl())
                return;

            var sphere = new BoundingSphere(position, DetectionRadius);
            MyGamePruningStructure.GetAllEntitiesInSphere(ref sphere, m_entitiesInRange);

            foreach (var entity in m_entitiesInRange)
            {
                MyVoxelMap voxelMap = entity as MyVoxelMap;
                if (voxelMap == null)
                    continue;

                foreach (var oreDeposit in voxelMap.Storage.OreDeposits)
                {
                    Debug.Assert(oreDeposit != null);
                    if (oreDeposit.TotalRareOreContent > 0 &&
                        Vector3.DistanceSquared(oreDeposit.WorldCenter, position) < DetectionRadius * DetectionRadius)
                    {
                        m_depositsInRange.Add(oreDeposit);
                        MyHud.OreMarkers.RegisterMarker(oreDeposit, new MyHudEntityParams());
                    }
                }
            }

            m_entitiesInRange.Clear();
        }
 public override void Update(GameTime gameTime)
 {
     position += velocity;
     sphere = new BoundingSphere(position, 2);
     worldMat = Matrix.CreateScale(0.4f) * Matrix.CreateRotationY(rotation.Y) * Matrix.CreateTranslation(position);
     checkBounds();
 }
Ejemplo n.º 30
0
        public Sphere(Model sphere,LabGame game)
        {
            this.game = game;
            model = sphere;
            basicEffect = new BasicEffect(game.GraphicsDevice)
            {
                View = game.camera.View,
                Projection = game.camera.Projection,
                World = Matrix.Identity,
                //Texture = myModel.Texture,
                TextureEnabled = true,
                VertexColorEnabled = false
            };
            BasicEffect.EnableDefaultLighting(model,true);
            const float MaxModelSize = 10.0f;
            //var scaling = MaxModelSize / modelBounds.Radius;
            //var scaling = MaxModelSize / model.Meshes[0].BoundingSphere.Radius;
            modelBounds = model.CalculateBounds();
            view = Matrix.LookAtRH(new Vector3(0, 0, MaxModelSize * 2.5f), new Vector3(0, 0, 0), Vector3.UnitY);
            projection = Matrix.PerspectiveFovRH(0.9f, (float)game.GraphicsDevice.BackBuffer.Width / game.GraphicsDevice.BackBuffer.Height, 0.1f, MaxModelSize * 10.0f);
            world = Matrix.Translation(-modelBounds.Center.X, -modelBounds.Center.Y, -modelBounds.Center.Z)*Matrix.Scaling(1);
            basicEffect.View = game.camera.View;
            basicEffect.Projection = game.camera.Projection;
            //modelBounds = model.CalculateBounds();
            //pos = model.BoundingSphere.Center;
              //  pos = new Vector3(-model.BoundingSphere.Center.X,-model.BoundingSphere.Center.Y,-model.BoundingSphere.Center.Z);
            pos = new Vector3(0, 0, 0);
            //basicEffect.World = Matrix.Translation(pos);// * Matrix.Scaling(1f);
            //effect = game.Content.Load<Effect>("Phong");

            radius = model.Meshes[0].BoundingSphere.Radius;
            frictionConstant = 0.4f;
        }