Example #1
0
        public static void DrawBBox(BoundingBox box, Matrix Projection, Matrix View, Matrix localWorld,Color color)
        {
            // Use inside a drawing loop

                Vector3[] corners = box.GetCorners();
                VertexPositionColor[] primitiveList = new VertexPositionColor[corners.Length];

                // Assign the 8 box vertices
                for (int i = 0; i < corners.Length; i++)
                {
                    primitiveList[i] = new VertexPositionColor(corners[i], color);
                }

                /* Set your own effect parameters here */

                boxEffect.World = localWorld;
                boxEffect.View = View;
                boxEffect.Projection = Projection;
                boxEffect.TextureEnabled = false;

                // Draw the box with a LineList
                foreach (EffectPass pass in boxEffect.CurrentTechnique.Passes)
                {
                    pass.Apply();
                    device.DrawUserIndexedPrimitives(
                        PrimitiveType.LineList, primitiveList, 0, 8,
                        bBoxIndices, 0, 12);
                }
        }
        /// <summary>
        /// Renders the bounding box for debugging purposes.
        /// </summary>
        /// <param name="box">The box to render.</param>
        /// <param name="graphicsDevice">The graphics device to use when rendering.</param>
        /// <param name="view">The current view matrix.</param>
        /// <param name="projection">The current projection matrix.</param>
        /// <param name="color">The color to use drawing the lines of the box.</param>
        public static void Render(
            BoundingBox box,
            GraphicsDevice graphicsDevice,
            Matrix view,
            Matrix projection,
            Color color)
        {
            if (box.Min == box.Max)
            {
                return;
            }

            if (effect == null)
            {
                effect = new BasicEffect(graphicsDevice)
                             {TextureEnabled = false, VertexColorEnabled = true, LightingEnabled = false};
            }

            Vector3[] corners = box.GetCorners();
            for (int i = 0; i < 8; i++)
            {
                verts[i].Position = corners[i];
                verts[i].Color = color;
            }

            effect.View = view;
            effect.Projection = projection;

            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                graphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.LineList, verts, 0, 8, indices, 0,
                                                         indices.Length/2);
            }
        }
Example #3
0
        public void DrawBoundingBox(BoundingBox box)
        {
            IGraphicsDeviceService graphicsService =
                    (IGraphicsDeviceService)base.Game.Services.GetService(
                                                    typeof(IGraphicsDeviceService));

            GraphicsDevice device = graphicsService.GraphicsDevice;

            vertices[0].Position = new Vector3(box.Min.X, box.Min.Y, box.Min.Z);
            vertices[1].Position = new Vector3(box.Max.X, box.Min.Y, box.Min.Z);
            vertices[2].Position = new Vector3(box.Max.X, box.Min.Y, box.Max.Z);
            vertices[3].Position = new Vector3(box.Min.X, box.Min.Y, box.Max.Z);

            vertices[4].Position = new Vector3(box.Min.X, box.Max.Y, box.Min.Z);
            vertices[5].Position = new Vector3(box.Max.X, box.Max.Y, box.Min.Z);
            vertices[6].Position = new Vector3(box.Max.X, box.Max.Y, box.Max.Z);
            vertices[7].Position = new Vector3(box.Min.X, box.Max.Y, box.Max.Z);

            Predraw(0);
            device.DrawUserIndexedPrimitives<VertexPositionColor>(
                PrimitiveType.LineList, vertices,
                0,
                8,
                indices,
                0,
                12);
            Postdraw();
        }
        public static BoundingBox Transform(BoundingBox bounds, Matrix matrix)
        {
            BoundingBox t;

            t.Min = matrix.Translation;
            t.Max = matrix.Translation;

            t.Min.X += (matrix.M11 < 0) ? bounds.Max.X * matrix.M11 : bounds.Min.X * matrix.M11;
            t.Min.X += (matrix.M21 < 0) ? bounds.Max.Y * matrix.M21 : bounds.Min.Y * matrix.M21;
            t.Min.X += (matrix.M31 < 0) ? bounds.Max.Z * matrix.M31 : bounds.Min.Z * matrix.M31;
            t.Max.X += (matrix.M11 > 0) ? bounds.Max.X * matrix.M11 : bounds.Min.X * matrix.M11;
            t.Max.X += (matrix.M21 > 0) ? bounds.Max.Y * matrix.M21 : bounds.Min.Y * matrix.M21;
            t.Max.X += (matrix.M31 > 0) ? bounds.Max.Z * matrix.M31 : bounds.Min.Z * matrix.M31;

            t.Min.Y += (matrix.M12 < 0) ? bounds.Max.X * matrix.M12 : bounds.Min.X * matrix.M12;
            t.Min.Y += (matrix.M22 < 0) ? bounds.Max.Y * matrix.M22 : bounds.Min.Y * matrix.M22;
            t.Min.Y += (matrix.M32 < 0) ? bounds.Max.Z * matrix.M32 : bounds.Min.Z * matrix.M32;
            t.Max.Y += (matrix.M12 > 0) ? bounds.Max.X * matrix.M12 : bounds.Min.X * matrix.M12;
            t.Max.Y += (matrix.M22 > 0) ? bounds.Max.Y * matrix.M22 : bounds.Min.Y * matrix.M22;
            t.Max.Y += (matrix.M32 > 0) ? bounds.Max.Z * matrix.M32 : bounds.Min.Z * matrix.M32;

            t.Min.Z += (matrix.M13 < 0) ? bounds.Max.X * matrix.M13 : bounds.Min.X * matrix.M13;
            t.Min.Z += (matrix.M23 < 0) ? bounds.Max.Y * matrix.M23 : bounds.Min.Y * matrix.M23;
            t.Min.Z += (matrix.M33 < 0) ? bounds.Max.Z * matrix.M33 : bounds.Min.Z * matrix.M33;
            t.Max.Z += (matrix.M13 > 0) ? bounds.Max.X * matrix.M13 : bounds.Min.X * matrix.M13;
            t.Max.Z += (matrix.M23 > 0) ? bounds.Max.Y * matrix.M23 : bounds.Min.Y * matrix.M23;
            t.Max.Z += (matrix.M33 > 0) ? bounds.Max.Z * matrix.M33 : bounds.Min.Z * matrix.M33;

            return t;
        }
Example #5
0
        public override void Initialize(Texture2D TextureForParticle, int ParticleCount, int MaxLife, Direction Direction, BoundingBox EnviromentBounds, Color Color)
        {
            base._t2dMainTexture = TextureForParticle;
            base._pContainer = new Particle[ParticleCount];
            base.EnviromentBounds = EnviromentBounds;
            base._Points = new VertexPositionColor[ParticleCount];
            for (int i = 0; i < ParticleCount; i++)
            {
                _pContainer[i] = new Particle();
                _pContainer[i].Life = Engine.Randomize(MaxLife / 4, MaxLife);
                _Points[i].Color = Color;
                _Points[i].Position = Engine.TempVector3(Engine.Randomize((int)EnviromentBounds.Min.X, (int)EnviromentBounds.Max.X),
                    Engine.Randomize((int)EnviromentBounds.Min.Y, (int)EnviromentBounds.Max.Y + 100),
                    Engine.Randomize((int)EnviromentBounds.Min.Z, (int)EnviromentBounds.Max.Z));
                float a = Engine.Randomize(2, 6);
                _pContainer[i].Velocity.Y = (a / DIVISIONAL_COEFFICENT);
                if(Engine.Randomize(1, 3) == 1)
                _pContainer[i].Velocity.X = (a / DIVISIONAL_COEFFICENT);
                else _pContainer[i].Velocity.X = -(a / DIVISIONAL_COEFFICENT);

                if(Engine.Randomize(1, 3) == 2)
                    _pContainer[i].Velocity.Z = (a / DIVISIONAL_COEFFICENT);
                else _pContainer[i].Velocity.Z = -(a / DIVISIONAL_COEFFICENT);
            }
        }
 /// <summary>
 /// konstruktor
 /// </summary>
 /// <param name="game">instance tridy</param>
 /// <param name="position">pozice bloku</param>
 public LabyrinthBlock(Game game, Vector3 position)
     : base(game)
 {
     base.modelPosition = position;
     boundingBox = new BoundingBox(new Vector3(position.X - 10, position.Y, position.Z - 10),
         new Vector3(position.X + 10, position.Y + 20, position.Z + 10));
 }
 /// <summary>
 /// konstruktor
 /// </summary>
 /// <param name="game">instance hry</param>
 /// <param name="x">poloha v hernim poli na ose x</param>
 /// <param name="y">poloha v hernim poli na ose y</param>
 public AbstractWall(Game game, int x, int y)
     : base(game)
 {
     base.modelPosition = new Vector3(x * 20, 0, y * 20);
     boundingBox = new BoundingBox(new Vector3(modelPosition.X - 10, modelPosition.Y, modelPosition.Z - 10),
         new Vector3(modelPosition.X + 10, modelPosition.Y + 20, modelPosition.Z + 10));
 }
        public static void Render(BoundingBox box,
                                  GraphicsDevice graphicsDevice,
                                  Matrix view,
                                  Matrix projection,
                                  Color color)
        {
            if (_effect.IsNull())
                _effect = new BasicEffect(graphicsDevice) { VertexColorEnabled = true, LightingEnabled = false };

            var corners = box.GetCorners();

            for (var i = 0; i < 8; i++)
            {
                Vertices[i].Position = corners[i];
                Vertices[i].Color = color;
            }

            _effect.View = view;
            _effect.Projection = projection;

            foreach (var pass in _effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                graphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.LineList,
                                                         Vertices,
                                                         0,
                                                         8,
                                                         Indices,
                                                         0,
                                                         Indices.Length / 2);
            }
        }
Example #9
0
        public QuadNode(NodeType nodeType, int nodeSize, int nodeDepth, QuadNode parent, QuadTree parentTree, int positionIndex)
        {
            NodeType = nodeType;
            _nodeSize = nodeSize;
            _nodeDepth = nodeDepth;
            _positionIndex = positionIndex;

            _parent = parent;
            _parentTree = parentTree;

            //Add the 9 vertices
            AddVertices();

            Bounds = new BoundingBox(_parentTree.Vertices[VertexTopLeft.Index].Position,
                        _parentTree.Vertices[VertexBottomRight.Index].Position);

            if (nodeSize >= 4)
                AddChildren();

            //Make call to UpdateNeighbors from the parent node.
            //This will update all neighbors recursively for the
            //children as well.  This ensures all nodes are created
            //prior to updating neighbors.
            if (_nodeDepth == 1)
            {
                AddNeighbors();

                VertexTopLeft.Activated = true;
                VertexTopRight.Activated = true;
                VertexCenter.Activated = true;
                VertexBottomLeft.Activated = true;
                VertexBottomRight.Activated = true;

            }
        }
Example #10
0
        public Player(Vector3 position,
            Vector3 velocity)
        {
            mPosition = position;
            mVelocity = velocity;

            mBound = new BoundingBox(mPosition + new Vector3(-5.0f, -100.0f, -5.0f), mPosition + new Vector3(5.0f, 35.0f, 5.0f));

            mYaw   = 0.0f;
            mPitch = 0.0f;

            mPlayerCamera = new Camera(mPosition, Quaternion.CreateFromAxisAngle(Vector3.Up, mYaw));

            // Start Player with 3 Stones.
            mBackpack.Clear();
            Player.AddItem("Stone");
            Player.AdjustQuantity("Stone", 2);

            m_rumble_start  = 150.0f;
            m_rumble_finish = 150.0f;
            m_prev_time     = 0.0f;
            m_time          = 0.0f;

            mFinishJump = SoundMaster.GetSound("jump_thud");
            mThrowStone = SoundMaster.GetSound("throw_sound");
        }
        /// <summary>
        /// Constructs the arena. Also constructs several platforms and physics elements
        /// which need to get added to the EntityManager and PhysicsSimulator.
        /// </summary>
        /// <param name="entityManager"></param>
        /// <param name="physicsSimulator"></param>
        public SplitBaseArena(EntityManager entityManager, PhysicsSimulator physicsSimulator)
        {
            // Create the platforms.
            float focus = 15.0f;
            Platform leftGround = new Platform(new Vector3(-focus, 0, 0), 22.0f, 2.0f, 5.0f);
            Platform rightGround = new Platform(new Vector3(focus, 0, 0), 22.0f, 2.0f, 5.0f);

            Platforms.Add(leftGround);
            entityManager.AddEntity(leftGround);
            physicsSimulator.AddPhysicsEntity(leftGround.GetBox());

            Platforms.Add(rightGround);
            entityManager.AddEntity(rightGround);
            physicsSimulator.AddPhysicsEntity(rightGround.GetBox());

            // Create the Spawn Positions
            spawnPositions = new List<Vector3>();
            spawnPositions.Add(new Vector3(-15, 10, 0));
            spawnPositions.Add(new Vector3(-5, 15, 0));
            spawnPositions.Add(new Vector3(5, 15, 0));
            spawnPositions.Add(new Vector3(15, 10, 0));

            // Create the Bounding box.
            boundingBox = new BoundingBox(new Vector3(-70, -20, -20), new Vector3(70, 60, 20));
        }
Example #12
0
        public void Constructor()
        {
            // Overloaded constructor, normal use
            b = new BoundingBox(new Vector3(-5, 3, 1),new Vector3(8, -10, 0));
            Assert.AreEqual(new Vector3(-5, 3, 1), b.Min, "Constructor#1.Min");
            Assert.AreEqual(new Vector3(8, -10, 0), b.Max, "Constructor#1.Max");

            // Overloaded constructor, when Min = Max
            b = new BoundingBox(new Vector3(0, 0, 1), new Vector3(0, 0, 1));
            Assert.AreEqual(new Vector3(0, 0, 1), b.Min, "Constructor#2.Min");
            Assert.AreEqual(new Vector3(0, 0, 1), b.Max, "Constructor#2.Max");

            // Overloaded constructor, when Min is the minimum value and Max the maximum
            b = new BoundingBox(new Vector3(float.MinValue), new Vector3(float.MaxValue));
            Assert.AreEqual(new Vector3(float.MinValue), b.Min, "Constructor#3.Min");
            Assert.AreEqual(new Vector3(float.MaxValue), b.Max, "Constructor#3.Max");

            // Overloaded constructor, changing passing Max first and Min afterwards
            // As stupid as it seems, MS's XNA doesn't check, just assumes first is Min
            // and second is Max
            b = new BoundingBox(new Vector3(10, 10, 10), new Vector3(0, 0, 0));
            Assert.AreEqual(new Vector3(10, 10, 10), b.Min, "Constructor#4.Min");
            Assert.AreEqual(new Vector3(0, 0, 0), b.Max, "Constructor#4.Max");

            // Overloaded constructor, using other Vector3
            // As before, MS's XNA does not check what's the minimum and maximum
            b = new BoundingBox(new Vector3(0, 5, 10), new Vector3(10, 5, 0));
            Assert.AreEqual(new Vector3(0, 5, 10), b.Min, "Constructor#5.Min");
            Assert.AreEqual(new Vector3(10, 5, 0), b.Max, "Constructor#5.Max");

            // Default constructor
            b = new BoundingBox();
            Assert.AreEqual(new Vector3(0, 0, 0), b.Min, "Constructor#6.Min");
            Assert.AreEqual(new Vector3(0, 0, 0), b.Max, "Constructor#6.Max");
        }
Example #13
0
        public Bounds(Vector3 center, Vector3 size)
        {
            _boundingSphere = null;
            Vector3 ext = size / 2;

            box = new Microsoft.Xna.Framework.BoundingBox(center - ext, center + ext);
        }
Example #14
0
        public static void AddBoundingBox(BoundingBox box, Color color, float life)
        {
            DebugShape shape = GetShapeForLines(12, life);

            box.GetCorners(Corners);

            shape.Vertices[0] = new VertexPositionColor(Corners[0], color);
            shape.Vertices[1] = new VertexPositionColor(Corners[1], color);
            shape.Vertices[2] = new VertexPositionColor(Corners[1], color);
            shape.Vertices[3] = new VertexPositionColor(Corners[2], color);
            shape.Vertices[4] = new VertexPositionColor(Corners[2], color);
            shape.Vertices[5] = new VertexPositionColor(Corners[3], color);
            shape.Vertices[6] = new VertexPositionColor(Corners[3], color);
            shape.Vertices[7] = new VertexPositionColor(Corners[0], color);

            shape.Vertices[8] = new VertexPositionColor(Corners[4], color);
            shape.Vertices[9] = new VertexPositionColor(Corners[5], color);
            shape.Vertices[10] = new VertexPositionColor(Corners[5], color);
            shape.Vertices[11] = new VertexPositionColor(Corners[6], color);
            shape.Vertices[12] = new VertexPositionColor(Corners[6], color);
            shape.Vertices[13] = new VertexPositionColor(Corners[7], color);
            shape.Vertices[14] = new VertexPositionColor(Corners[7], color);
            shape.Vertices[15] = new VertexPositionColor(Corners[4], color);

            shape.Vertices[16] = new VertexPositionColor(Corners[0], color);
            shape.Vertices[17] = new VertexPositionColor(Corners[4], color);
            shape.Vertices[18] = new VertexPositionColor(Corners[1], color);
            shape.Vertices[19] = new VertexPositionColor(Corners[5], color);
            shape.Vertices[20] = new VertexPositionColor(Corners[2], color);
            shape.Vertices[21] = new VertexPositionColor(Corners[6], color);
            shape.Vertices[22] = new VertexPositionColor(Corners[3], color);
            shape.Vertices[23] = new VertexPositionColor(Corners[7], color);
        }
Example #15
0
        public RedHead(Game game, Vector3 pos, Level l)
            : base(game, pos, l)
        {
            //Parameters for this specific enemy
            life = 5;
            textures = new Texture2D[life];
            Damage = 5;
            this.level = l;
            this.position = pos;
            RotationSpeed = 0.1f;
            ForwardSpeed = 6f;
            boxMin = new Vector3(-0.235f, 0, -0.235f);
            boxMax = new Vector3(0.235f, 0.8f, 0.235f);
            boundingBox = new BoundingBox(position + boxMin, position + boxMax);
            //Different textures for each life count
            textures[4] = ContentPreImporter.GetTexture("RedHead");
            textures[3] = ContentPreImporter.GetTexture("RedHead4");
            textures[2] = ContentPreImporter.GetTexture("RedHead3");
            textures[1] = ContentPreImporter.GetTexture("RedHead2");
            textures[0] = ContentPreImporter.GetTexture("RedHead1");
            hurtSound = ContentPreImporter.GetSound("enemyHurt");

            billboard = new Billboard(game, textures[life - 1], Vector2.One / 2);
            billboard.Move(position + new Vector3(0, 0.25f, 0));
            billboard.ForceUpdate();
            target = pos;
            //Set new values for the fog if required
            billboard.OverrideFog(GlobalSettings.FogEnabled, GlobalSettings.FogColor, GlobalSettings.FogStart, GlobalSettings.FogEnd * 2.1f);
        }
Example #16
0
        /// <summary>
        /// Model 全体を包む BoundingBox を取得します。
        /// </summary>
        /// <param name="model">Model。</param>
        /// <param name="result">Model 全体を包む BoundingBox。</param>
        public static void GetBoundingBox(this Model model, out BoundingBox result)
        {
            var boneTransforms = new Matrix[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(boneTransforms);

            var points = new List<Vector3>();
            foreach (var mesh in model.Meshes)
            {
                foreach (var part in mesh.MeshParts)
                {
                    var vertexBuffer = part.VertexBuffer;
                    var data = new float[vertexBuffer.VertexCount * vertexBuffer.VertexDeclaration.VertexStride / sizeof(float)];
                    vertexBuffer.GetData<float>(data);
                    var boneTransform = boneTransforms[mesh.ParentBone.Index];
                    var increment = vertexBuffer.VertexDeclaration.VertexStride / sizeof(float);
                    for (int i = 0; i < data.Length; i += increment)
                    {
                        Vector3 point;
                        point.X = data[i];
                        point.Y = data[i + 1];
                        point.Z = data[i + 2];

                        point = Vector3.Transform(point, boneTransform);

                        points.Add(point);
                    }
                }
            }
            result = BoundingBox.CreateFromPoints(points);
        }
Example #17
0
 public override BoundingBox[] GetCollisionBoxes()
 {
     BoundingBox[] result = new BoundingBox[2];
     result[0] = new BoundingBox(new Vector3(0, 0, 0), new Vector3(0.5f, 1, 1));
     result[1] = new BoundingBox(new Vector3(0.5f, 0, 0), new Vector3(1, 1, 1));
     return result;
 }
Example #18
0
        public bool Convert(string s, out object value)
        {
            BoundingBox v = new BoundingBox();
            value = v;
            object corner;
            string[] splits = s.Split(VALUE_DELIMITERS, StringSplitOptions.RemoveEmptyEntries);
            if(splits.Length < 2) return false;
            int vi = 0;
            foreach(var sv in splits) {
                if(vi == 2) break;
                if(string.IsNullOrWhiteSpace(sv))
                    continue;
                if(vec3Conv.Convert(sv, out corner)) {
                    switch(vi) {
                        case 0: v.Min = (Vector3)corner; break;
                        case 1: v.Max = (Vector3)corner; break;
                    }
                    vi++;
                }
            }
            if(vi < 2) return false;

            value = v;
            return true;
        }
Example #19
0
 public override void Update(GameTime gametime)
 {
     min = MIN + currentPosition;
     max = MAX + currentPosition;
     tankBox = new BoundingBox(min, max);
     turretRorationValue = (float)Math.Sin(gametime.TotalGameTime.TotalSeconds);
 }
Example #20
0
        /// <summary>
        /// Creates a new chunk.
        /// </summary>
        /// <param name="world">The world this chunk belongs to.</param>
        /// <param name="index">The index of the chunk.</param>
        /// <param name="generateTerrain">True to generate some initial terrain, false to leave each block empty.</param>
        private Chunk( World world, Vector3 index, bool generateTerrain )
        {
            _world = world;
            _data = new ChunkData( index );
            _terrain = new VoxelBuffer();

            // create bounds
            var sizeOffs = ChunkData.SizeXZ * 0.5f - 0.5f;
            Vector3 boundsMin = new Vector3(
                index.X - sizeOffs,
                -0.5f,
                index.Z - sizeOffs
            );
            Vector3 boundsMax = new Vector3(
                index.X + sizeOffs,
                0.5f + ChunkData.SizeY,
                index.Z + sizeOffs
            );
            _bounds = new BoundingBox( boundsMin, boundsMax );
            _octree = new ChunkOctree( _bounds );

            // check if we need to populate
            if ( generateTerrain )
            {
                PopulateTerrain();
            }
        }
Example #21
0
        public float?Intersect(Microsoft.Xna.Framework.BoundingBox bound)
        {
            float tfirst = 0.0f, tlast = Length;

            if (!RaySlabIntersect(StartPosition.X,
                                  Direction.X,
                                  bound.Min.X,
                                  bound.Max.X,
                                  ref tfirst, ref tlast))
            {
                return(null);
            }
            if (!RaySlabIntersect(StartPosition.Y,
                                  Direction.Y,
                                  bound.Min.Y,
                                  bound.Max.Y,
                                  ref tfirst, ref tlast))
            {
                return(null);
            }
            if (!RaySlabIntersect(StartPosition.Z,
                                  Direction.Z,
                                  bound.Min.Z,
                                  bound.Max.Z,
                                  ref tfirst, ref tlast))
            {
                return(null);
            }

            return(tfirst);
        }
Example #22
0
        public ContainmentType Contains(ref BoundingBox boundingBox)
        {
            ContainmentType result;
            _boundingSphere.Contains(ref boundingBox, out result);

            return result;
        }
    /// <summary>
    /// Initializes a new instance of the <see cref="GhostObject"/> class.
    /// </summary>
    /// <param name="position">The position.</param>
    /// <param name="orientation">The orientation.</param>
    /// <param name="scale">The scale.</param>
 public GhostObject(Vector3 position, Matrix orientation, Vector3 scale, BoundingBox? bb = null) : base(MaterialDescription.DefaultBepuMaterial(), 0)
 {
     this.pos = position;
     this.ori = orientation;
     this.scale = scale;
     this.bb = bb;
 }
Example #24
0
        public BasicEntity(ModelDefinition modelbb, MaterialEffect material, Vector3 position, double angleZ, double angleX, double angleY, Vector3 scale, MeshMaterialLibrary library = null, Entity physicsObject = null)
        {
            Id                  = IdGenerator.GetNewId();
            Name                = GetType().Name + " " + Id;
            WorldTransform      = new TransformMatrix(Matrix.Identity, Id);
            ModelDefinition     = modelbb;
            Model               = modelbb.Model;
            BoundingBox         = modelbb.BoundingBox;
            BoundingBoxOffset   = modelbb.BoundingBoxOffset;
            SignedDistanceField = modelbb.SDF;

            Material = material;
            Position = position;
            Scale    = scale;

            RotationMatrix = Matrix.CreateRotationX((float)angleX) * Matrix.CreateRotationY((float)angleY) *
                             Matrix.CreateRotationZ((float)angleZ);

            if (library != null)
            {
                RegisterInLibrary(library);
            }

            if (physicsObject != null)
            {
                RegisterPhysics(physicsObject);
            }

            WorldTransform.World        = Matrix.CreateScale(Scale) * RotationMatrix * Matrix.CreateTranslation(Position);
            WorldTransform.Scale        = Scale;
            WorldTransform.InverseWorld = Matrix.Invert(Matrix.CreateTranslation(BoundingBoxOffset * Scale) * RotationMatrix * Matrix.CreateTranslation(Position));
        }
Example #25
0
 private BSP(Node root, BoundingBox? bounds, object[] description, bool createDescription = true)
 {
     _root = root;
     Bounds = bounds;
     _description = description;
     _createDescription = createDescription;
 }
Example #26
0
 public GameObject()
 {
     Model = null;
     Position = Vector3.Zero;
     BoundingSphere = new BoundingSphere();
     boundingBox = new BoundingBox();
 }
Example #27
0
        public static void DrawBoundingBox(BoundingBox bBox, GraphicsDevice device, BasicEffect basicEffect, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix)
        {
            Vector3 v1 = bBox.Min;
            Vector3 v2 = bBox.Max;

            VertexPositionColor[] cubeLineVertices = new VertexPositionColor[8];
            cubeLineVertices[0] = new VertexPositionColor(v1, Color.White);
            cubeLineVertices[1] = new VertexPositionColor(new Vector3(v2.X, v1.Y, v1.Z), Color.Red);
            cubeLineVertices[2] = new VertexPositionColor(new Vector3(v2.X, v1.Y, v2.Z), Color.Green);
            cubeLineVertices[3] = new VertexPositionColor(new Vector3(v1.X, v1.Y, v2.Z), Color.Blue);

            cubeLineVertices[4] = new VertexPositionColor(new Vector3(v1.X, v2.Y, v1.Z), Color.White);
            cubeLineVertices[5] = new VertexPositionColor(new Vector3(v2.X, v2.Y, v1.Z), Color.Red);
            cubeLineVertices[6] = new VertexPositionColor(v2, Color.Green);
            cubeLineVertices[7] = new VertexPositionColor(new Vector3(v1.X, v2.Y, v2.Z), Color.Blue);

            short[] cubeLineIndices = { 0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7 };

            basicEffect.World = worldMatrix;
            basicEffect.View = viewMatrix;
            basicEffect.Projection = projectionMatrix;
            basicEffect.VertexColorEnabled = true;

            device.RasterizerState = _solidRasterizer;
            foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                device.DrawUserIndexedPrimitives<VertexPositionColor>(PrimitiveType.LineList, cubeLineVertices, 0, 8, cubeLineIndices, 0, 12);
            }
        }
    /// <summary>
    /// Initializes a new instance of the <see cref="PhysxGhostObject"/> class.
    /// </summary>
    /// <param name="position">The position.</param>
    /// <param name="orientation">The orientation.</param>
    /// <param name="scale">The scale.</param>
    /// <param name="bb">The bb.</param>
 public PhysxGhostObject(Vector3 position, Matrix orientation, Vector3 scale, BoundingBox? bb = null) 
 {
     this.pos = position;
     this.ori = orientation;
     this.scale = scale;
     this.bb = bb;
 }
        public void colisao()
        {
            Vector3 A = new Vector3(screen.player.positionPlayer.X+5, screen.player.positionPlayer.Y+10, 0);
            Vector3 B = new Vector3(screen.player.positionPlayer.X + 44, screen.player.positionPlayer.Y + screen.player.imgPlayer.Height - 13, 0);

            Vector3 C = new Vector3(posicao.X, posicao.Y, 0);
            Vector3 D = new Vector3(posicao.X + largura, posicao.Y + image.Height, 0);

            BoundingBox boxPlayer = new BoundingBox(A, B);
            BoundingBox boxEnemy = new BoundingBox(C, D);

            if (boxEnemy.Intersects(boxPlayer))
            {
                screen.removeComponent(this);
                screen.addComponent(new Explosao(mygame, C + new Vector3(0, 10, 0), 1, screen));
                screen.player.hp--;
                if (screen.player.hp < 0) {
                    screen.addComponent(new Explosao(mygame, new Vector3(screen.player.positionPlayer.X, screen.player.positionPlayer.Y, 0), 2, screen));
                    screen.player.vida--;
                    screen.player.hp = 5;
                }
                if(screen.player.vida < 0){
                    screen.removeComponent(screen.player);
                    mygame.setScreen(new ScreenSplash(mygame));
                }

            }
        }
 /// <summary>
 /// Initializes a new instance of the GhostObject class.
 /// DEfault Object in 0,0,0 identity rotation and 1,1,1 scale
 /// </summary>
 /// <param name="bb">The bb.</param>
 public PhysxGhostObject(BoundingBox? bb = null)         
 {
     this.pos = Vector3.Zero;
     this.ori = Matrix.Identity;
     this.scale = Vector3.One;
     this.bb = bb;
 }
Example #31
0
 public void Encapsulate(Vector3 point)
 {
     if (box.Contains(point) == ContainmentType.Disjoint)
     {
         box = BoundingBox.CreateFromPoints(new Microsoft.Xna.Framework.Vector3[] { point, box.Min, box.Max });
     }
 }
 /// <summary>
 /// konstruktor
 /// </summary>
 /// <param name="game">instance hry</param>
 /// <param name="x">poloha v hernim poli na ose x</param>
 /// <param name="y">poloha v hernim poli na ose y</param>
 public AbstractBonus(Game game, AbstractWall wall)
     : base(game)
 {
     base.modelPosition = new Vector3(wall.ModelPosition.X, 0, wall.ModelPosition.Z);
     boundingBox = new BoundingBox(new Vector3(modelPosition.X - 10, modelPosition.Y, modelPosition.Z - 10),
         new Vector3(modelPosition.X + 10, modelPosition.Y + 20, modelPosition.Z + 10));
 }
Example #33
0
        public static VertexPositionColor[] GetVerticesFromBounds(BoundingBox bounds, Color hitboxColor)
        {
            Vector3[] corners = bounds.GetCorners();
            VertexPositionColor[] debugVerts = new VertexPositionColor[24];
            debugVerts[0] = new VertexPositionColor(corners[0], hitboxColor);
            debugVerts[1] = new VertexPositionColor(corners[1], hitboxColor);
            debugVerts[2] = new VertexPositionColor(corners[1], hitboxColor);
            debugVerts[3] = new VertexPositionColor(corners[5], hitboxColor);
            debugVerts[4] = new VertexPositionColor(corners[5], hitboxColor);
            debugVerts[5] = new VertexPositionColor(corners[4], hitboxColor);
            debugVerts[6] = new VertexPositionColor(corners[4], hitboxColor);
            debugVerts[7] = new VertexPositionColor(corners[0], hitboxColor);

            debugVerts[8] = new VertexPositionColor(corners[3], hitboxColor);
            debugVerts[9] = new VertexPositionColor(corners[2], hitboxColor);
            debugVerts[10] = new VertexPositionColor(corners[2], hitboxColor);
            debugVerts[11] = new VertexPositionColor(corners[6], hitboxColor);
            debugVerts[12] = new VertexPositionColor(corners[6], hitboxColor);
            debugVerts[13] = new VertexPositionColor(corners[7], hitboxColor);
            debugVerts[14] = new VertexPositionColor(corners[7], hitboxColor);
            debugVerts[15] = new VertexPositionColor(corners[3], hitboxColor);

            debugVerts[16] = new VertexPositionColor(corners[3], hitboxColor);
            debugVerts[17] = new VertexPositionColor(corners[0], hitboxColor);
            debugVerts[18] = new VertexPositionColor(corners[2], hitboxColor);
            debugVerts[19] = new VertexPositionColor(corners[1], hitboxColor);
            debugVerts[20] = new VertexPositionColor(corners[6], hitboxColor);
            debugVerts[21] = new VertexPositionColor(corners[5], hitboxColor);
            debugVerts[22] = new VertexPositionColor(corners[7], hitboxColor);
            debugVerts[23] = new VertexPositionColor(corners[4], hitboxColor);

            return debugVerts;
        }
Example #34
0
 public BoundingBox Collision()
 {
     Vector3 Middle= new Vector3(Position.X+100,Position.Y+100,Position.Z-75);
     Vector3 abc = new Vector3(80);
     BoundingBox bb= new BoundingBox(Middle - new Vector3(40), Middle + new Vector3(40));
     return bb;
 }
Example #35
0
        public static BoundingBox Convert(Microsoft.Xna.Framework.BoundingBox boundingBox)
        {
            BoundingBox toReturn;

            Convert(ref boundingBox.Min, out toReturn.Min);
            Convert(ref boundingBox.Max, out toReturn.Max);
            return(toReturn);
        }
Example #36
0
 public void Encapsulate(Microsoft.Xna.Framework.Vector3[] points)
 {
     if (points == null || points.Length == 0)
     {
         box = new BoundingBox();
         return;
     }
     box             = BoundingBox.CreateFromPoints(points);
     _boundingSphere = null;
 }
Example #37
0
        private float RadiusFromBounds(Microsoft.Xna.Framework.BoundingBox bounds)
        {
            Microsoft.Xna.Framework.Vector3 corner;

            corner.X = Math.Abs(bounds.Min.X) > Math.Abs(bounds.Max.X) ? Math.Abs(bounds.Min.X) : Math.Abs(bounds.Max.X);
            corner.Y = Math.Abs(bounds.Min.Y) > Math.Abs(bounds.Max.Y) ? Math.Abs(bounds.Min.Y) : Math.Abs(bounds.Max.Y);
            corner.Z = Math.Abs(bounds.Min.Z) > Math.Abs(bounds.Max.Z) ? Math.Abs(bounds.Min.Z) : Math.Abs(bounds.Max.Z);

            return(corner.Length());
        }
Example #38
0
 /// <summary>
 /// Converts the specified XNA bounding box to a Protogame bounding box.
 /// </summary>
 /// <param name="boundingBox">
 /// The XNA bounding box to convert.
 /// </param>
 /// <returns>
 /// The <see cref="IBoundingBox"/>.
 /// </returns>
 public static IBoundingBox ToProtogame(this Microsoft.Xna.Framework.BoundingBox boundingBox)
 {
     return(new BoundingBox
     {
         LocalMatrix = Matrix.CreateTranslation(boundingBox.Min.X, boundingBox.Min.Y, boundingBox.Min.Z),
         Width = (boundingBox.Max - boundingBox.Min).X,
         Height = (boundingBox.Max - boundingBox.Min).Y,
         Depth = (boundingBox.Max - boundingBox.Min).Z
     });
 }
 /// <summary>
 /// Converts the specified XNA bounding box to a Protogame bounding box.
 /// </summary>
 /// <param name="boundingBox">
 /// The XNA bounding box to convert.
 /// </param>
 /// <returns>
 /// The <see cref="IBoundingBox"/>.
 /// </returns>
 public static IBoundingBox ToProtogame(this Microsoft.Xna.Framework.BoundingBox boundingBox)
 {
     return(new BoundingBox
     {
         X = boundingBox.Min.X,
         Y = boundingBox.Min.Y,
         Z = boundingBox.Min.Z,
         Width = (boundingBox.Max - boundingBox.Min).X,
         Height = (boundingBox.Max - boundingBox.Min).Y,
         Depth = (boundingBox.Max - boundingBox.Min).Z
     });
 }
        /// <summary>
        /// Converts the specified XNA bounding box to a Protogame bounding box.
        /// </summary>
        /// <param name="boundingBox">
        /// The XNA bounding box to convert.
        /// </param>
        /// <returns>
        /// The <see cref="IBoundingBox"/>.
        /// </returns>
        public static IBoundingBox ToProtogame(this Microsoft.Xna.Framework.BoundingBox boundingBox)
        {
            var bb = new BoundingBox
            {
                Width  = (boundingBox.Max - boundingBox.Min).X,
                Height = (boundingBox.Max - boundingBox.Min).Y,
                Depth  = (boundingBox.Max - boundingBox.Min).Z
            };

            bb.Transform.Assign(new DefaultTransform {
                LocalPosition = new Vector3(boundingBox.Min.X, boundingBox.Min.Y, boundingBox.Min.Z)
            });
            return(bb);
        }
Example #41
0
        public void Initialize()
        {
            FacesCreated          = false;
            VertexBufferCreated   = false;
            FacesComputing        = false;
            WaitForFacesComputing = false;
            OpaqueFaceCount       = 0;
            WaterFaceCount        = 0;

            IsLoading              = true;
            Neighbors              = new Chunk[6];
            LightComputed          = false;
            LightComputing         = false;
            LightFirstPassComputed = false;

            FirstBlocAbsolutPosition = new Point3d(ChunkPosition.X * chunkSize, ChunkPosition.Y, ChunkPosition.Z * chunkSize);
            Transform   = Matrix.CreateTranslation(FirstBlocAbsolutPosition.X, FirstBlocAbsolutPosition.Y, FirstBlocAbsolutPosition.Z);
            BoundingBox = new BoundingBox(FirstBlocAbsolutPosition.ToVector3(), FirstBlocAbsolutPosition.ToVector3() + new Vector3(16, 256, 16));
        }
Example #42
0
        public bool IsColliding(BoundingBox bbox, IEntity other)
        {
            //if (!Compare((int) KnownPosition.X, (int) other.KnownPosition.X, 5)) return false;
            //if (!Compare((int) KnownPosition.Z, (int) other.KnownPosition.Z, 5)) return false;
            if (!Compare((int)KnownPosition.X, (int)other.KnownPosition.X, 4))
            {
                return(false);
            }
            if (!Compare((int)KnownPosition.Z, (int)other.KnownPosition.Z, 4))
            {
                return(false);
            }
            if (!bbox.Intersects(other.GetBoundingBox()))
            {
                return(false);
            }

            return(true);
        }
Example #43
0
        public BasicEntity(ModelDefinition modelbb, MaterialEffect material, Vector3 position, Matrix rotationMatrix, Vector3 scale)
        {
            Id                  = IdGenerator.GetNewId();
            Name                = GetType().Name + " " + Id;
            WorldTransform      = new TransformMatrix(Matrix.Identity, Id);
            Model               = modelbb.Model;
            ModelDefinition     = modelbb;
            BoundingBox         = modelbb.BoundingBox;
            BoundingBoxOffset   = modelbb.BoundingBoxOffset;
            SignedDistanceField = modelbb.SDF;

            Material       = material;
            Position       = position;
            RotationMatrix = rotationMatrix;
            Scale          = scale;
            RotationMatrix = rotationMatrix;

            WorldTransform.World        = Matrix.CreateScale(Scale) * RotationMatrix * Matrix.CreateTranslation(Position);
            WorldTransform.Scale        = Scale;
            WorldTransform.InverseWorld = Matrix.Invert(Matrix.CreateTranslation(BoundingBoxOffset * Scale) * RotationMatrix * Matrix.CreateTranslation(Position));
        }
        public void FillFrom(Chunk component)
        {
            ChunkWorldMapLocationPoint = component.ChunkWorldMapLocationPoint;
            Bounds = new Microsoft.Xna.Framework.BoundingBox(component.Bounds.Min, component.Bounds.Max);
            WorldPositionBottomLeftCorner = component.WorldPositionBottomLeftCorner;
            var tiles = component.GetChunkTiles();

            if (tiles != null)
            {
                ChunkResolution = Constants.ChunkSize;
                Tiles           = new TileStorage[ChunkResolution * ChunkResolution];

                for (int i = 0; i < ChunkResolution; i++)
                {
                    for (int j = 0; j < ChunkResolution; j++)
                    {
                        Tiles[i * ChunkResolution + j] = tiles[i][j];
                    }
                }
            }
        }
Example #45
0
        public void GetEntries(Microsoft.Xna.Framework.BoundingBox boundingShape, IList <BroadPhaseEntry> overlaps)
        {
            //Compute the min and max of the bounding box.
            //Loop through the cells and select bounding boxes which overlap the x axis.

            Int2 min, max;

            Grid2DSortAndSweep.ComputeCell(ref boundingShape.Min, out min);
            Grid2DSortAndSweep.ComputeCell(ref boundingShape.Max, out max);
            for (int i = min.Y; i <= max.Y; i++)
            {
                for (int j = min.Z; j <= max.Z; j++)
                {
                    //Grab the cell that we are currently in.
                    Int2 cellIndex;
                    cellIndex.Y = i;
                    cellIndex.Z = j;
                    GridCell2D cell;
                    if (owner.cellSet.TryGetCell(ref cellIndex, out cell))
                    {
                        //To fully accelerate this, the entries list would need to contain both min and max interval markers.
                        //Since it only contains the sorted min intervals, we can't just start at a point in the middle of the list.
                        //Consider some giant bounding box that spans the entire list.
                        for (int k = 0; k < cell.entries.count &&
                             cell.entries.Elements[k].item.boundingBox.Min.X <= boundingShape.Max.X; k++)   //TODO: Try additional x axis pruning? A bit of optimization potential due to overlap with AABB test.
                        {
                            bool intersects;
                            var  item = cell.entries.Elements[k].item;
                            boundingShape.Intersects(ref item.boundingBox, out intersects);
                            if (intersects && !overlaps.Contains(item))
                            {
                                overlaps.Add(item);
                            }
                        }
                    }
                }
            }
        }
Example #46
0
 /// <summary>
 /// Initialize The System
 /// </summary>
 /// <param name="img"></param>
 public void Initialize(Graphics.Image img)
 {
     this.img          = img;
     this._boundingbox = new Microsoft.Xna.Framework.BoundingBox(new Vector3(img.Position.X, img.Position.Y, 0), new Vector3(img.Position.X + img.Size.X, img.Position.Y + img.Size.Y, 0));
 }
Example #47
0
        /// <summary>
        /// Gets the bouding sphere of this bouding box.
        /// </summary>
        /// <param name="boundingBox"></param>
        /// <returns>A bounding sphere.</returns>
        public static BoundingSphere ToBoundingSphere(this BoundingBox boundingBox)
        {
            var boundingSphere = new BoundingSphere(boundingBox.GetCenter(), boundingBox.GetMaxSize());

            return(boundingSphere);
        }
Example #48
0
 public static void Convert(ref BoundingBox boundingBox, out Microsoft.Xna.Framework.BoundingBox xnaBoundingBox)
 {
     Convert(ref boundingBox.Min, out xnaBoundingBox.Min);
     Convert(ref boundingBox.Max, out xnaBoundingBox.Max);
 }
Example #49
0
 public IntegerBoundingBox(Microsoft.Xna.Framework.BoundingBox Box)
 {
     this.Min = new Point3((int)Math.Floor(Box.Min.X), (int)Math.Floor(Box.Min.Y), (int)Math.Floor(Box.Min.Z));
     this.Max = new Point3((int)Math.Ceiling(Box.Max.X), (int)Math.Ceiling(Box.Max.Y), (int)Math.Ceiling(Box.Max.Z));
 }
Example #50
0
 /// <summary>
 /// Gets whether or not a specified <see cref="BoundingBox"/> intersects with this sphere.
 /// </summary>
 /// <param name="box">The box for testing.</param>
 /// <param name="result"><c>true</c> if <see cref="BoundingBox"/> intersects with this sphere; <c>false</c> otherwise. As an output parameter.</param>
 public void Intersects(ref BoundingBox box, out bool result)
 {
     box.Intersects(ref this, out result);
 }
Example #51
0
 public static void Convert(ref Microsoft.Xna.Framework.BoundingBox boundingBox, out BoundingBox bepuBoundingBox)
 {
     Convert(ref boundingBox.Min, out bepuBoundingBox.Min);
     Convert(ref boundingBox.Max, out bepuBoundingBox.Max);
 }
Example #52
0
 public static void CreateFromBoundingBox(ref BoundingBox box, out BoundingSphere result)
 {
     result = CreateFromBoundingBox(box);
 }
Example #53
0
 public void Contains(ref BoundingBox box, out ContainmentType result)
 {
     result = this.Contains(box);
 }
Example #54
0
 public void Intersects(ref BoundingBox box, out bool result)
 {
     result = Intersects(box);
 }
Example #55
0
 public bool Intersects(BoundingBox box)
 {
     return(box.Intersects(this));
 }
Example #56
0
 public void Intersects(ref BoundingBox box, out bool result)
 {
     throw new NotImplementedException();
 }
Example #57
0
 /// <summary>
 /// Update The Sytem
 /// </summary>
 public void Update()
 {
     this._boundingbox = new Microsoft.Xna.Framework.BoundingBox(new Vector3(img.Position.X, img.Position.Y, 0), new Vector3(img.Position.X + img.Size.X, img.Position.Y + img.Size.Y, 0));
 }
Example #58
0
 public Bounds(Microsoft.Xna.Framework.BoundingBox b)
 {
     _boundingSphere = null;
     box             = b;
 }
Example #59
0
 public void Encapsulate(Bounds bounds)
 {
     box             = BoundingBox.CreateMerged(box, bounds.box);
     _boundingSphere = null;
 }
Example #60
0
 public void SetMinMax(Vector3 min, Vector3 max)
 {
     box             = new Microsoft.Xna.Framework.BoundingBox(min, max);
     _boundingSphere = null;
 }