public GameModel(GameModelDTO modelData, GameModel parent = null)
 {
     this.blocks = modelData.blocks.Select(block => new GameBlock(this, block)).ToArray();
     this.subModels.AddRange(modelData.subModels.Select(modelDTO => new GameModel(modelDTO, null)));
     this.relativeBounds = new BoundingBoxInt(modelData.min, modelData.max);
     foreach (AnimationDTO animationDTO in modelData.animations)
     {
         this.Animations.Add(animationDTO.Name, new Animation(animationDTO));
     }
     this.spawnLocations = modelData.spawnLocations;
 }
 protected override void drawBlocks(BoundingBoxInt boundingBox)
 {
     foreach (SaveBlock saveBlock in MainForm.ModelManager.SelectedModel.Blocks)
     {
         if (textureBeingProjectedDown.projectedOnto.Contains(saveBlock))
         {
             drawBlock(textureWireframeBack, boundingBox, blockTypeColor[saveBlock.Type], saveBlock.Position, .01f);
             //TODO: cut out relevant piece of the texture and draw it inside the block
             drawBlock(textureWireframe, boundingBox, blockTypeColor[saveBlock.Type], saveBlock.Position, -.01f);
         }
         else
         {
             drawBlock(textureBlock, boundingBox, blockTypeColor[saveBlock.Type], saveBlock.Position);
         }
     }
 }
 public void Draw(GameTime gameTime, SpriteBatch spriteBatch, BoundingBoxInt worldBounds)
 {
     Draw(gameTime, spriteBatch, worldBounds, Vector2.Zero, 0);
 }
        //protected virtual void Draw(GameTime gameTime, SpriteBatch spriteBatch, BoundingBoxInt worldBounds, float depthOffset)
        //{
        //    Frame currentFrame = Animations["still"].Frames[0];
        //    Vector3 fractionalRenderPosition = RenderPosition(gameTime);
        //    Position wholeRenderPosition = fractionalRenderPosition.Ceiling();
        //    for (int i = 0; i < blocks.Length; i++)
        //    {
        //        if (currentFrame.textures[i] != null)
        //        {
        //            float depth = worldBounds.getRelativeDepthOf(wholeRenderPosition + blocks[i].Position, depthOffset);
        //            //Vector2 screenCoords = (CoordinateTransform.ObjectToProjectionSpace(realPosition) * 1.3f).ToPoint().ToVector2();
        //            Vector2 screenCoords = CoordinateTransform.ObjectToProjectionSpace(fractionalRenderPosition + blocks[i].Position.ToVector3());
        //            spriteBatch.Draw(currentFrame.textures[i], screenCoords, null,
        //                Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, depth);
        //        }
        //    }
        //    foreach (GameModel subModel in subModels)
        //    {
        //        subModel.Draw(gameTime, spriteBatch, worldBounds, depthOffset);
        //    }
        //}
        protected virtual void Draw(GameTime gameTime, SpriteBatch spriteBatch, BoundingBoxInt worldBounds, Vector2 offset, float depthOffset)
        {
            Frame currentFrame = Animations["still"].Frames[0];
            for (int i = 0; i < blocks.Length; i++)
            {
                if (currentFrame.textures[i] != null)
                {
                    float depth = worldBounds.getRelativeDepthOf(RenderPosition(gameTime) + blocks[i].Position, depthOffset);
                    Vector2 screenCoords = CoordinateTransform.ObjectToBlockDrawCoordsInProjectionSpace(Position + blocks[i].Position) + offset;
                    Color color = Color.White;
                    var a = Engine.Physics.GetBlocksUnderPoint(Engine.Input.Mouse.LocationInProjSpace, gameTime).FirstOrDefault();
                    if (a != null && a.Item1 == blocks[i])
                    {
                        color = Color.Red;
                    }
                    spriteBatch.Draw(currentFrame.textures[i], screenCoords, null,
                        color, 0, Vector2.Zero, 1, SpriteEffects.None, depth);
                }
            }

            foreach (GameModel subModel in subModels)
            {
                subModel.Draw(gameTime, spriteBatch, worldBounds, offset, depthOffset);
            }
        }
        protected SaveBlock getHitBlock(IEnumerable<SaveBlock> outOf, System.Drawing.Point pointInProjSpace)
        {
            BoundingBoxInt boundingBox = new BoundingBoxInt(outOf.ToPositions());

            foreach (SaveBlock block in outOf.OrderBy(block => boundingBox.getRelativeDepthOf(block.Position)))
            {
                System.Drawing.Region blockRegion = BlockRegions.WholeBlock.Offset(
                    CoordinateTransform.ObjectToProjectionSpace(block.Position).ToXnaPoint().Add(
                    Constants.blockDrawOffset.ToXnaPoint()));
                if (blockRegion.IsVisible(pointInProjSpace))
                {
                    return block;
                }
            }
            return null;
        }
 protected override void Draw(GameTime gameTime, SpriteBatch spriteBatch, BoundingBoxInt worldBounds, Vector2 offset, float depthOffset)
 {
     if (moving)
     {
         depthOffset -= 0.04f; // I don't know why -0.04, but it works :D // Björn
     }
     base.Draw(gameTime, spriteBatch, worldBounds, offset + getCurrentDrawOffset(gameTime), depthOffset);
 }
 protected virtual BoundingBoxInt getBoundingBox()
 {
     BoundingBoxInt boundingBox = new BoundingBoxInt(MainForm.ModelManager.SelectedModel.Blocks.ToPositions());
     boundingBox.addPos(new Position(-3, -3, -1));
     boundingBox.addPos(new Position(3, 3, -1));
     const int margin = 2;
     boundingBox.addPos(boundingBox.Max + new Position(margin, margin, 0));
     boundingBox.addPos(boundingBox.Min - new Position(margin, margin, 0));
     return boundingBox;
 }
 protected virtual void drawGrid(BoundingBoxInt boundingBox)
 {
     for (int x = boundingBox.Min.X; x <= boundingBox.Max.X; x++)
     {
         for (int y = boundingBox.Min.Y; y <= boundingBox.Max.Y; y++)
         {
             drawBlock(textureGridStriped, boundingBox, Color.White, new Position(x, y, -1), -0.01f);
         }
     }
 }
 protected virtual void drawBlocks(BoundingBoxInt boundingBox)
 {
     foreach (SaveBlock saveBlock in MainForm.ModelManager.SelectedModel.Blocks)
     {
         drawBlock(textureBlock, boundingBox, blockTypeColor[saveBlock.Type], saveBlock.Position);
     }
 }
 protected void drawBlock(Texture2D image, BoundingBoxInt boundingBox, Color color, Position pos, float depthOffset = 0)
 {
     float depth = boundingBox.getRelativeDepthOf(pos);
     Vector2 projCoords = CoordinateTransform.ObjectToProjectionSpace(pos);
     spriteBatch.Draw(image, projCoords + Constants.blockDrawOffset, null, color, 0, Vector2.Zero, 1, SpriteEffects.None, (depth + depthOffset) / Wrapper.Camera.Zoom);
 }
Exemple #11
0
        /// <summary>
        /// Calculates the bounding box for a set of bounding boxes.
        /// </summary>
        /// <param name="items">The list of all the bounding boxes.</param>
        /// <param name="minIndex">The first bounding box in the list to get the extends of.</param>
        /// <param name="maxIndex">The last bounding box in the list to get the extends of.</param>
        /// <param name="bounds">The extends of all the bounding boxes.</param>
        private static void CalcExtends(BoundingVolumeTreeNode[] items, int minIndex, int maxIndex, out BoundingBoxInt bounds)
        {
            bounds = items[minIndex].Bounds;

            for (int i = minIndex + 1; i < maxIndex; i++)
            {
                var it = items[i];
                bounds.Min = Vector3Int.ComponentMin(it.Bounds.Min, bounds.Min);
                bounds.Max = Vector3Int.ComponentMax(it.Bounds.Max, bounds.Max);
            }
        }