Example #1
0
        public void Spawn(IClient client, IEntityPlayer player)
        {
            if (_client != null)
            {
                throw new NotSupportedException("Connection already initialized");
            }

            _client = client;

            _networkClient.Send(new MessageClientPlayerInfo.Message(
                                    MessageClientPlayerInfo.Action.AddPlayer,
                                    new [] { player }
                                    ));

            var worldContext = player.WorldContext;
            var environment  = worldContext.GetOption(WorldOption.Environment);

            _networkClient.Send(new MessageClientInitGame.Message(
                                    player.Id,
                                    (byte)player.GameMode,
                                    environment.Id,
                                    0,
                                    LevelType,
                                    client.World.RenderDistance,
                                    false
                                    ));
        }
Example #2
0
        public void loadModelMatrix(Entity entity)
        {
            IEntityPlayer entityPlayer = capi.World.Player.Entity;

            Mat4f.Identity(ModelMat);
            Mat4f.Translate(ModelMat, ModelMat, (float)(entity.Pos.X - entityPlayer.CameraPos.X), (float)(entity.Pos.Y - entityPlayer.CameraPos.Y), (float)(entity.Pos.Z - entityPlayer.CameraPos.Z));

            float rotX = entity.Properties.Client.Shape != null ? entity.Properties.Client.Shape.rotateX : 0;
            float rotY = entity.Properties.Client.Shape != null ? entity.Properties.Client.Shape.rotateY : 0;
            float rotZ = entity.Properties.Client.Shape != null ? entity.Properties.Client.Shape.rotateZ : 0;

            Mat4f.Translate(ModelMat, ModelMat, 0, entity.CollisionBox.Y2 / 2, 0);

            double[] quat = Quaterniond.Create();
            Quaterniond.RotateX(quat, quat, entity.Pos.Pitch + rotX * GameMath.DEG2RAD);
            Quaterniond.RotateY(quat, quat, entity.Pos.Yaw + (rotY + 90) * GameMath.DEG2RAD);
            Quaterniond.RotateZ(quat, quat, entity.Pos.Roll + rotZ * GameMath.DEG2RAD);

            float[] qf = new float[quat.Length];
            for (int i = 0; i < quat.Length; i++)
            {
                qf[i] = (float)quat[i];
            }
            Mat4f.Mul(ModelMat, ModelMat, Mat4f.FromQuat(Mat4f.Create(), qf));

            float scale = entity.Properties.Client.Size;

            Mat4f.Scale(ModelMat, ModelMat, new float[] { scale, scale, scale });
            Mat4f.Translate(ModelMat, ModelMat, -0.5f, -entity.CollisionBox.Y2 / 2, -0.5f);
        }
Example #3
0
        private void LoadModelMatrix(ItemRenderInfo renderInfo, bool isShadowPass)
        {
            IRenderAPI    rapi         = capi.Render;
            IEntityPlayer entityPlayer = capi.World.Player.Entity;

            Mat4f.Identity(ModelMat);
            Mat4f.Translate(ModelMat, ModelMat,
                            (float)(entityitem.Pos.X - entityPlayer.CameraPos.X),
                            (float)(entityitem.Pos.Y - entityPlayer.CameraPos.Y),
                            (float)(entityitem.Pos.Z - entityPlayer.CameraPos.Z)
                            );

            float sizeX = 0.2f * renderInfo.Transform.ScaleXYZ.X;
            float sizeY = 0.2f * renderInfo.Transform.ScaleXYZ.Y;
            float sizeZ = 0.2f * renderInfo.Transform.ScaleXYZ.Z;



            long ellapseMs = capi.World.ElapsedMilliseconds;

            if (entity.Collided || entity.Swimming || capi.IsGamePaused)
            {
                touchGroundMS = ellapseMs;
            }

            float easeIn  = Math.Min(1, (ellapseMs - touchGroundMS) / 200);
            float angleMs = Math.Max(ellapseMs - touchGroundMS, 0) * easeIn;


            float yangle = angleMs / 7f;
            float xangle = angleMs / 7f;
            float zangle = angleMs / 7f;

            float dx = 0, dz = 0;

            if (entity.Swimming)
            {
                float diff = 1;
                if (entityitem.Itemstack.Collectible.MaterialDensity > 1000)
                {
                    dx   = GameMath.Sin((float)(ellapseMs / 1000.0)) / 50;
                    dz   = -GameMath.Sin((float)(ellapseMs / 3000.0)) / 50;
                    diff = 0.1f;
                }

                xangle = GameMath.Sin((float)(ellapseMs / 1000.0)) * 8 * diff;
                yangle = GameMath.Cos((float)(ellapseMs / 2000.0)) * 3 * diff;
                zangle = -GameMath.Sin((float)(ellapseMs / 3000.0)) * 8 * diff;
            }



            Mat4f.Translate(ModelMat, ModelMat, dx + renderInfo.Transform.Translation.X, renderInfo.Transform.Translation.Y, dz + renderInfo.Transform.Translation.Z);
            Mat4f.Scale(ModelMat, ModelMat, new float[] { sizeX + scaleRand, sizeY + scaleRand, sizeZ + scaleRand });
            Mat4f.RotateY(ModelMat, ModelMat, GameMath.DEG2RAD * (renderInfo.Transform.Rotation.Y + yangle) + (renderInfo.Transform.Rotate ? yRotRand : 0));
            Mat4f.RotateZ(ModelMat, ModelMat, GameMath.DEG2RAD * (renderInfo.Transform.Rotation.Z + zangle));
            Mat4f.RotateX(ModelMat, ModelMat, GameMath.DEG2RAD * (renderInfo.Transform.Rotation.X + xangle));
            Mat4f.Translate(ModelMat, ModelMat, -renderInfo.Transform.Origin.X, -renderInfo.Transform.Origin.Y, -renderInfo.Transform.Origin.Z);
        }
Example #4
0
        public void Init(IEntityPlayer player)
        {
            if (Player != null)
            {
                Connection.Disconnect();
                return;
            }

            Player = player;
            World.Init();

            Controller.Client                = this;
            Controller.Disconnected         += OnDisconnect;
            Controller.PingResponseReceived += OnPingResponse;
            Connection.Spawn(this, player);
        }
Example #5
0
        void loadModelMatrixForGui(Entity entity, double posX, double posY, double posZ, double yawDelta, float size)
        {
            IEntityPlayer entityPlayer = capi.World.Player.Entity;

            Mat4f.Identity(ModelMat);
            Mat4f.Translate(ModelMat, ModelMat, (float)posX, (float)posY, (float)posZ);

            Mat4f.Translate(ModelMat, ModelMat, size, 2 * size, 0);

            float rotX = entity.Properties.Client.Shape != null ? entity.Properties.Client.Shape.rotateX : 0;
            float rotY = entity.Properties.Client.Shape != null ? entity.Properties.Client.Shape.rotateY : 0;
            float rotZ = entity.Properties.Client.Shape != null ? entity.Properties.Client.Shape.rotateZ : 0;

            Mat4f.RotateX(ModelMat, ModelMat, GameMath.PI + rotX * GameMath.DEG2RAD);
            Mat4f.RotateY(ModelMat, ModelMat, (float)yawDelta + rotY * GameMath.DEG2RAD);
            Mat4f.RotateZ(ModelMat, ModelMat, rotZ * GameMath.DEG2RAD);

            float scale = entity.Properties.Client.Size * size;

            Mat4f.Scale(ModelMat, ModelMat, new float[] { scale, scale, scale });
            Mat4f.Translate(ModelMat, ModelMat, -0.5f, 0f, -0.5f);
        }
Example #6
0
        public override void DoRender3DOpaque(float dt, bool isShadowPass)
        {
            IRenderAPI    rapi         = capi.Render;
            IEntityPlayer entityPlayer = capi.World.Player.Entity;


            ItemRenderInfo renderInfo = rapi.GetItemStackRenderInfo(entityitem.Itemstack, EnumItemRenderTarget.Ground);

            if (renderInfo.ModelRef == null)
            {
                return;
            }

            IStandardShaderProgram prog = null;

            LoadModelMatrix(renderInfo, isShadowPass);

            if (isShadowPass)
            {
                rapi.CurrentActiveShader.BindTexture2D("tex2d", renderInfo.TextureId, 0);
                float[] mvpMat = Mat4f.Mul(ModelMat, capi.Render.CurrentModelviewMatrix, ModelMat);
                Mat4f.Mul(mvpMat, capi.Render.CurrentProjectionMatrix, mvpMat);
                capi.Render.CurrentActiveShader.UniformMatrix("mvpMatrix", mvpMat);
                capi.Render.CurrentActiveShader.Uniform("origin", new Vec3f());
            }
            else
            {
                prog = rapi.StandardShader;
                prog.Use();
                prog.Tex2D    = renderInfo.TextureId;
                prog.RgbaTint = ColorUtil.WhiteArgbVec;

                if (entity.Swimming)
                {
                    prog.WaterWave        = entityitem.Itemstack.Collectible.MaterialDensity > 1000 ? 0 : 1;
                    prog.WaterWaveCounter = capi.Render.WaterWaveCounter;
                    prog.Playerpos        = new Vec3f((float)entityPlayer.CameraPos.X, (float)entityPlayer.CameraPos.Y, (float)entityPlayer.CameraPos.Z);
                }
                else
                {
                    prog.WaterWave = 0;
                }

                BlockPos pos       = entityitem.Pos.AsBlockPos;
                Vec4f    lightrgbs = capi.World.BlockAccessor.GetLightRGBs(pos.X, pos.Y, pos.Z);
                int      temp      = (int)entityitem.Itemstack.Collectible.GetTemperature(capi.World, entityitem.Itemstack);
                float[]  glowColor = ColorUtil.GetIncandescenceColorAsColor4f(temp);
                lightrgbs[0] += 2 * glowColor[0];
                lightrgbs[1] += 2 * glowColor[1];
                lightrgbs[2] += 2 * glowColor[2];

                prog.ExtraGlow     = GameMath.Clamp((temp - 500) / 3, 0, 255);
                prog.RgbaAmbientIn = rapi.AmbientColor;
                prog.RgbaLightIn   = lightrgbs;
                prog.RgbaBlockIn   = ColorUtil.WhiteArgbVec;
                prog.RgbaFogIn     = rapi.FogColor;
                prog.FogMinIn      = rapi.FogMin;
                prog.FogDensityIn  = rapi.FogDensity;

                prog.ProjectionMatrix = rapi.CurrentProjectionMatrix;
                prog.ViewMatrix       = rapi.CameraMatrixOriginf;
                prog.ModelMatrix      = ModelMat;
            }


            if (!renderInfo.CullFaces)
            {
                rapi.GlDisableCullFace();
            }

            rapi.RenderMesh(renderInfo.ModelRef);

            if (!renderInfo.CullFaces)
            {
                rapi.GlEnableCullFace();
            }


            if (!isShadowPass)
            {
                prog.Stop();
            }
        }