Example #1
0
        protected override void OnFinalisePlacements(IEnumerable <InstPlacement> placements)
        {
            Vector2 min = new Vector2();
            Vector2 max = new Vector2();

            foreach (InstPlacement placement in placements)
            {
                if (placement.Position.X < min.X)
                {
                    min.X = placement.Position.X;
                }
                if (placement.Position.Z < min.Y)
                {
                    min.Y = placement.Position.Z;
                }

                if (placement.Position.X > max.X)
                {
                    max.X = placement.Position.X;
                }
                if (placement.Position.Z > max.Y)
                {
                    max.Y = placement.Position.Z;
                }
            }

            myBounds.X = min.X;
            myBounds.Y = min.Y;
            myBounds.Z = max.X;
            myBounds.W = max.Y;

            myGridWidth = (int)Math.Ceiling((max.X - min.X) / BlockSize);
            myGridDepth = (int)Math.Ceiling((max.Y - min.Y) / BlockSize);

            myInstGrid = new ExteriorBlock[myGridWidth, myGridDepth];
            for (int x = 0; x < myGridWidth; ++x)
            {
                for (int z = 0; z < myGridDepth; ++z)
                {
                    myInstGrid[x, z] = new ExteriorBlock(GetBlockPos(x, z));
                }
            }

            foreach (InstPlacement placement in placements)
            {
                int x = GetBlockX(placement.Position.X);
                int z = GetBlockZ(placement.Position.Z);
                myInstGrid[x, z].AddPlacement(placement);
            }

            foreach (ExteriorBlock block in myInstGrid)
            {
                block.FinalisePlacements();
            }
        }
Example #2
0
        public override void Render(ModelShader shader, RenderLayer layer)
        {
            float rx, rz;

            for (int x = 0; x < myGridWidth; ++x)
            {
                for (int z = 0; z < myGridDepth; ++z)
                {
                    ExteriorBlock blk = myInstGrid[x, z];

                    rx = blk.CenterPos.X - shader.Camera.Position.X;
                    rz = blk.CenterPos.Y - shader.Camera.Position.Z;

                    if ((rx * rx + rz * rz) < shader.Camera.ViewDistance2 + blk.Radius2)
                    {
                        blk.Render(shader, layer);
                    }
                }
            }
        }
Example #3
0
        protected override void OnFinalisePlacements( IEnumerable<InstPlacement> placements )
        {
            Vector2 min = new Vector2();
            Vector2 max = new Vector2();

            foreach ( InstPlacement placement in placements )
            {
                if ( placement.Position.X < min.X )
                    min.X = placement.Position.X;
                if ( placement.Position.Z < min.Y )
                    min.Y = placement.Position.Z;

                if ( placement.Position.X > max.X )
                    max.X = placement.Position.X;
                if ( placement.Position.Z > max.Y )
                    max.Y = placement.Position.Z;
            }

            myBounds.X = min.X;
            myBounds.Y = min.Y;
            myBounds.Z = max.X;
            myBounds.W = max.Y;

            myGridWidth = (int) Math.Ceiling( ( max.X - min.X ) / BlockSize );
            myGridDepth = (int) Math.Ceiling( ( max.Y - min.Y ) / BlockSize );

            myInstGrid = new ExteriorBlock[ myGridWidth, myGridDepth ];
            for ( int x = 0; x < myGridWidth; ++x ) for ( int z = 0; z < myGridDepth; ++z )
                myInstGrid[ x, z ] = new ExteriorBlock( GetBlockPos( x, z ) );

            foreach ( InstPlacement placement in placements )
            {
                int x = GetBlockX( placement.Position.X );
                int z = GetBlockZ( placement.Position.Z );
                myInstGrid[ x, z ].AddPlacement( placement );
            }

            foreach ( ExteriorBlock block in myInstGrid )
                block.FinalisePlacements();
        }