/// <summary> Sets up the state for, then renders an entity model,
        /// based on the given entity's position and orientation. </summary>
        public void Render(Entity p)
        {
            index = 0;
            pos   = p.Position;
            if (Bobbing)
            {
                pos.Y += p.anim.bobbingModel;
            }

            Vector3I P = Vector3I.Floor(p.EyePosition);

            col    = game.World.IsValidPos(P) ? game.Lighting.LightCol(P.X, P.Y, P.Z) : game.Lighting.Outside;
            uScale = 1 / 64f; vScale = 1 / 32f;

            cols[0] = col;
            cols[1] = FastColour.ScalePacked(col, FastColour.ShadeYBottom);
            cols[2] = FastColour.ScalePacked(col, FastColour.ShadeZ); cols[3] = cols[2];
            cols[4] = FastColour.ScalePacked(col, FastColour.ShadeX); cols[5] = cols[4];

            float yawDelta = p.HeadY - p.RotY;

            cosHead = (float)Math.Cos(yawDelta * Utils.Deg2Rad);
            sinHead = (float)Math.Sin(yawDelta * Utils.Deg2Rad);

            game.Graphics.SetBatchFormat(VertexFormat.P3fT2fC4b);
            game.Graphics.PushMatrix();

            Matrix4 m = p.TransformMatrix(p.ModelScale, pos);

            game.Graphics.MultiplyMatrix(ref m);
            DrawModel(p);
            game.Graphics.PopMatrix();
        }
示例#2
0
        public void SetupState(Entity p)
        {
            index = 0;
            int col = p.Colour();

            uScale = 1 / 64f; vScale = 1 / 32f;

            cols[0] = col;
            if (!p.NoShade)
            {
                cols[1] = FastColour.ScalePacked(col, FastColour.ShadeYBottom);
                cols[2] = FastColour.ScalePacked(col, FastColour.ShadeZ);
                cols[4] = FastColour.ScalePacked(col, FastColour.ShadeX);
            }
            else
            {
                cols[1] = col; cols[2] = col; cols[4] = col;
            }
            cols[3] = cols[2]; cols[5] = cols[4];

            float yawDelta = p.HeadY - p.RotY;

            cosHead = (float)Math.Cos(yawDelta * Utils.Deg2Rad);
            sinHead = (float)Math.Sin(yawDelta * Utils.Deg2Rad);
        }
示例#3
0
        public void SetupState(Entity p)
        {
            index = 0;
            Vector3I P   = Vector3I.Floor(p.EyePosition);
            int      col = game.World.IsValidPos(P) ? game.Lighting.LightCol(P.X, P.Y, P.Z) : game.Lighting.Outside;

            uScale = 1 / 64f; vScale = 1 / 32f;

            cols[0] = col;
            cols[1] = FastColour.ScalePacked(col, FastColour.ShadeYBottom);
            cols[2] = FastColour.ScalePacked(col, FastColour.ShadeZ); cols[3] = cols[2];
            cols[4] = FastColour.ScalePacked(col, FastColour.ShadeX); cols[5] = cols[4];

            float yawDelta = p.HeadY - p.RotY;

            cosHead = (float)Math.Cos(yawDelta * Utils.Deg2Rad);
            sinHead = (float)Math.Sin(yawDelta * Utils.Deg2Rad);
        }
示例#4
0
        public override int Colour()
        {
            Player realP = game.LocalPlayer;
            int    col   = realP.Colour();

            // Adjust pitch so angle when looking straight down is 0.
            float adjHeadX = realP.HeadX - 90;

            if (adjHeadX < 0)
            {
                adjHeadX += 360;
            }

            // Adjust colour so held block is brighter when looking straght up
            float t        = Math.Abs(adjHeadX - 180) / 180;
            float colScale = Utils.Lerp(0.9f, 0.7f, t);

            return(FastColour.ScalePacked(col, colScale));
        }
        protected override void DrawModel(Entity p)
        {
            game.Graphics.BindTexture(GetTexture(p.MobTextureId));
            DrawRotate(-p.HeadXRadians, 0, 0, Head, true);
            DrawRotate(-p.HeadXRadians, 0, 0, Head2, true);
            DrawRotate(-p.HeadXRadians, 0, 0, Head3, true);

            DrawPart(Torso);
            DrawRotate(0, 0, -Math.Abs(p.anim.armXRot), LeftWing, false);
            DrawRotate(0, 0, Math.Abs(p.anim.armXRot), RightWing, false);

            for (int i = 0; i < cols.Length; i++)
            {
                cols[i] = FastColour.ScalePacked(col, 0.7f);
            }
            DrawRotate(p.anim.legXRot, 0, 0, LeftLeg, false);
            DrawRotate(-p.anim.legXRot, 0, 0, RightLeg, false);
            UpdateVB();
        }
示例#6
0
        public void SetupColours(Entity p)
        {
            int col = p.Colour();

            cols[0] = col;
                        #if USE_DX
            if (!p.NoShade)
            {
                cols[1] = FastColour.ScalePacked(col, FastColour.ShadeYBottom);
                cols[2] = FastColour.ScalePacked(col, FastColour.ShadeZ);
                cols[4] = FastColour.ScalePacked(col, FastColour.ShadeX);
            }
            else
            {
                cols[1] = col; cols[2] = col; cols[4] = col;
            }
            cols[3] = cols[2]; cols[5] = cols[4];
                        #else
            cols[1] = col; cols[2] = col; cols[4] = col;
            cols[3] = cols[2]; cols[5] = cols[4];
                        #endif
        }
示例#7
0
        protected override void PostStretchTiles(int x1, int y1, int z1)
        {
            base.PostStretchTiles(x1, y1, z1);
            for (int i = 0; i < isOccluder.Length; i++)
            {
                isOccluder[i] =
                    BlockInfo.BlocksLight[i] &&
                    BlockInfo.MinBB[i] == Vector3.Zero &&
                    BlockInfo.MaxBB[i] == Vector3.One &&
                    BlockInfo.Draw[i] != DrawType.TransparentThick;                     // goodlyay, did you hack this for leaves?
            }

            sun        = env.Sunlight;
            sunX       = FastColour.Unpack(env.SunXSide);
            sunZ       = FastColour.Unpack(env.SunZSide);
            sunYBottom = FastColour.Unpack(env.SunYBottom);

            dark        = FastColour.Unpack(FastColour.ScalePacked(env.Shadow, 0.3f));
            darkX       = FastColour.Unpack(FastColour.ScalePacked(env.ShadowXSide, 0.3f));
            darkZ       = FastColour.Unpack(FastColour.ScalePacked(env.ShadowZSide, 0.3f));
            darkYBottom = FastColour.Unpack(FastColour.ScalePacked(env.ShadowYBottom, 0.3f));
        }
示例#8
0
        protected override void DrawModel(Entity p)
        {
            // TODO: using 'is' is ugly, but means we can avoid creating
            // a string every single time held block changes.
            if (p is FakePlayer)
            {
                Player   realP = game.LocalPlayer;
                Vector3I P     = Vector3I.Floor(realP.EyePosition);
                col = game.World.IsValidPos(P) ? game.Lighting.LightCol(P.X, P.Y, P.Z) : game.Lighting.Outside;

                // Adjust pitch so angle when looking straight down is 0.
                float adjHeadX = realP.HeadX - 90;
                if (adjHeadX < 0)
                {
                    adjHeadX += 360;
                }

                // Adjust colour so held block is brighter when looking straght up
                float t        = Math.Abs(adjHeadX - 180) / 180;
                float colScale = Utils.Lerp(0.9f, 0.7f, t);
                col   = FastColour.ScalePacked(col, colScale);
                block = ((FakePlayer)p).Block;
            }
            else
            {
                block = Utils.FastByte(p.ModelName);
            }

            CalcState(block);
            if (!(p is FakePlayer))
            {
                NoShade = bright;
            }
            if (bright)
            {
                col = FastColour.WhitePacked;
            }
            if (game.BlockInfo.Draw[block] == DrawType.Gas)
            {
                return;
            }

            lastTexId = -1;
            atlas     = game.TerrainAtlas1D;
            bool sprite = game.BlockInfo.Draw[block] == DrawType.Sprite;

            DrawParts(sprite);
            if (index == 0)
            {
                return;
            }

            IGraphicsApi gfx = game.Graphics;

            gfx.BindTexture(lastTexId);
            TransformVertices();

            if (sprite)
            {
                gfx.FaceCulling = true;
            }
            UpdateVB();
            if (sprite)
            {
                gfx.FaceCulling = false;
            }
        }
示例#9
0
 int Colour(float shade)
 {
     return(NoShade ? col : FastColour.ScalePacked(col, shade));
 }