Пример #1
0
        public override void OnDraw(Matrix aM, Matrix aV, Matrix aP)
        {
            Matrix MVP = aM * aV * aP;
            Matrix MTI = Matrix.Transpose(Matrix.Invert(aM));

            this.Shader.Parameters["matM"].SetValue(aM);
            this.Shader.Parameters["matMVP"].SetValue(MVP);
            this.Shader.Parameters["matMTI"].SetValue(MTI);

            Light light = LightSystem.GetSingleton().GetLight(0);

            this.Shader.Parameters["DiffuseColor"].SetValue(new Vector3(1, 1, 1));
            this.Shader.Parameters["Texture"].SetValue(this.Tex1);
            this.Shader.Parameters["Tiling"].SetValue(new Vector2(10, 10));
            this.Shader.Parameters["LightDir"].SetValue(light.GetLightDirection());
            this.Shader.Parameters["LightColor"].SetValue(light.LightColor);
            this.Shader.Parameters["LightPosition"].SetValue(light.gameObject.Position);
            if (light.Type == LightType.POINT)
            {
                this.Shader.Parameters["LightAttenuation"].SetValue(light.Attenuation);
                this.Shader.Parameters["LightCutOffDistance"].SetValue(light.CutOffDistance);
            }
            else if (light.Type == LightType.SPOT)
            {
                this.Shader.Parameters["LightAttenuation"].SetValue(light.Attenuation);
                this.Shader.Parameters["LightCutOffDistance"].SetValue(light.CutOffDistance);
                this.Shader.Parameters["ConeAngle"].SetValue(light.ConeAngle);
            }
            this.Shader.Parameters["AmbientColor"].SetValue(LightSystem.GetSingleton().AmbientColor);
            this.Shader.Parameters["CameraPosition"].SetValue(Engine.GetSingleton().MainCamera.Position);
            this.Shader.Parameters["SpecularColor"].SetValue(new Vector3(1, 1, 1));
            this.Shader.Parameters["SpecularPower"].SetValue(4.0f);
        }
Пример #2
0
        public override void Draw()
        {
            if (this.gameObject.IsActive == false)
            {
                return;
            }

            Matrix matM = Matrix.Identity;

            matM *= Matrix.CreateScale(this.gameObject.LocalScale);
            float      x            = MathHelper.ToRadians(this.gameObject.LocalRotation.X);
            float      y            = MathHelper.ToRadians(this.gameObject.LocalRotation.Y);
            float      z            = MathHelper.ToRadians(this.gameObject.LocalRotation.Z);
            Quaternion quatRotation = Quaternion.CreateFromYawPitchRoll(y, x, z);

            matM *= Matrix.CreateFromQuaternion(quatRotation);
            matM *= Matrix.CreateTranslation(this.gameObject.Position);
            Matrix matV = Engine.GetSingleton().MainCamera.View;
            Matrix matP = Engine.GetSingleton().MainCamera.Projection;


            Engine.GetSingleton().GraphicsDevice.SetVertexBuffer(this.mVertexBuffer);
            Engine.GetSingleton().GraphicsDevice.Indices = this.mIndexBuffer;

            foreach (EffectPass pass in this.mMaterial.Shader.CurrentTechnique.Passes)
            {
                this.mMaterial.OnDraw(matM, matV, matP);
                pass.Apply();
                Engine.GetSingleton().GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, this.mModel.TriangleNum);
            }
        }
Пример #3
0
        public override void Draw()
        {
            if (this.gameObject.IsActive == false)
            {
                return;
            }

            Matrix matM = Matrix.Identity;

            matM *= Matrix.CreateScale(this.gameObject.LocalScale);
            float      x            = MathHelper.ToRadians(this.gameObject.LocalRotation.X);
            float      y            = MathHelper.ToRadians(this.gameObject.LocalRotation.Y);
            float      z            = MathHelper.ToRadians(this.gameObject.LocalRotation.Z);
            Quaternion quatRotation = Quaternion.CreateFromYawPitchRoll(y, x, z);

            matM *= Matrix.CreateFromQuaternion(quatRotation);
            matM *= Matrix.CreateTranslation(this.gameObject.Position);
            Matrix matV = Engine.GetSingleton().MainCamera.View;
            Matrix matP = Engine.GetSingleton().MainCamera.Projection;

            foreach (var mesh in this.mModel.Meshes)
            {
                this.mMaterial.OnDraw(matM, matV, matP);
                mesh.Draw();
            }
        }
Пример #4
0
        public void Draw()
        {
            Matrix matM = Matrix.Identity;

            matM *= Matrix.CreateScale(Vector3.One * this.Size);
            matM *= Matrix.CreateTranslation(Engine.GetSingleton().MainCamera.Position);
            Matrix matV   = Engine.GetSingleton().MainCamera.View;
            Matrix matP   = Engine.GetSingleton().MainCamera.Projection;
            Matrix matMVP = matM * matV * matP;

            foreach (var mesh in this.mModel.Meshes)
            {
                this.mShader.Parameters["matM"].SetValue(matM);
                this.mShader.Parameters["matMVP"].SetValue(matMVP);
                this.mShader.Parameters["Texture"].SetValue(this.mTex);
                this.mShader.Parameters["CameraPosition"].SetValue(Engine.GetSingleton().MainCamera.Position);
                mesh.Draw();
            }
        }
Пример #5
0
        public override void OnDraw(Matrix aM, Matrix aV, Matrix aP)
        {
            Matrix MVP = aM * aV * aP;
            Matrix MTI = Matrix.Transpose(Matrix.Invert(aM));

            this.Shader.Parameters["matM"].SetValue(aM);
            this.Shader.Parameters["matMVP"].SetValue(MVP);
            this.Shader.Parameters["matMTI"].SetValue(MTI);
            this.Shader.Parameters["DiffuseColor"].SetValue(new Vector3(1, 1, 1));
            this.Shader.Parameters["Texture"].SetValue(this.Tex1);
            this.Shader.Parameters["Tiling"].SetValue(this.Tiling);
            this.Shader.Parameters["AmbientColor"].SetValue(LightSystem.GetSingleton().AmbientColor);
            this.Shader.Parameters["CameraPosition"].SetValue(Engine.GetSingleton().MainCamera.Position);
            this.Shader.Parameters["SpecularColor"].SetValue(new Vector3(1, 1, 1));
            this.Shader.Parameters["SpecularPower"].SetValue(4.0f);

            int lightNum = LightSystem.GetSingleton().GetLightNum();

            this.Shader.Parameters["LightNum"].SetValue(lightNum);
            for (int i = 0; i < lightNum; i++)
            {
                Light light = LightSystem.GetSingleton().GetLight(i);
                this.mLightType[i]           = (int)light.Type;
                this.mLightPosition[i]       = light.gameObject.Position;
                this.mLightDir[i]            = light.GetLightDirection();
                this.mLightColor[i]          = light.LightColor;
                this.mLightAttenuation[i]    = light.Attenuation;
                this.mLightCutOffDistance[i] = light.CutOffDistance;
                this.mConeAngle[i]           = light.ConeAngle;
            }


            this.Shader.Parameters["LightType"].SetValue(this.mLightType);
            this.Shader.Parameters["LightPosition"].SetValue(this.mLightPosition);
            this.Shader.Parameters["LightDir"].SetValue(this.mLightDir);
            this.Shader.Parameters["LightColor"].SetValue(this.mLightColor);
            this.Shader.Parameters["LightAttenuation"].SetValue(this.mLightAttenuation);
            this.Shader.Parameters["LightCutOffDistance"].SetValue(this.mLightCutOffDistance);
            this.Shader.Parameters["ConeAngle"].SetValue(this.mConeAngle);
        }
Пример #6
0
        public void BindVertex()
        {
            VertexPositionNormalTexture[] vertices = new VertexPositionNormalTexture[this.mModel.VertexNum];
            for (int i = 0; i < this.mModel.VertexNum; i++)
            {
                TMeshVertex vert   = this.mModel.Verts[i];
                Vector3     pos    = new Vector3(vert.x, vert.y, vert.z);
                Vector3     normal = new Vector3(vert.nx, vert.ny, vert.nz);
                Vector2     uv     = new Vector2(vert.u, vert.v);
                vertices[i] = new VertexPositionNormalTexture(pos, normal, uv);
            }

            this.mVertexBuffer = new DynamicVertexBuffer(Engine.GetSingleton().GraphicsDevice,
                                                         typeof(VertexPositionNormalTexture),
                                                         vertices.Length,
                                                         BufferUsage.WriteOnly);
            this.mVertexBuffer.SetData <VertexPositionNormalTexture>(vertices);
            this.mIndexBuffer = new IndexBuffer(Engine.GetSingleton().GraphicsDevice,
                                                typeof(int),
                                                this.mModel.TriangleIndices.Length,
                                                BufferUsage.WriteOnly);
            this.mIndexBuffer.SetData(this.mModel.TriangleIndices);
        }
Пример #7
0
        public override void OnDraw(Matrix aM, Matrix aV, Matrix aP)
        {
            Matrix MVP = aM * aV * aP;
            Matrix MTI = Matrix.Transpose(Matrix.Invert(aM));

            this.Shader.Parameters["matM"].SetValue(aM);
            this.Shader.Parameters["matMVP"].SetValue(MVP);
            this.Shader.Parameters["matMTI"].SetValue(MTI);

            Light light = LightSystem.GetSingleton().GetLight(0);

            this.Shader.Parameters["DiffuseColor"].SetValue(new Vector3(1, 1, 1));
            this.Shader.Parameters["TexDiffuse"].SetValue(this.TexDiffuse);
            this.Shader.Parameters["TexNormal"].SetValue(this.TexNormal);
            this.Shader.Parameters["UseNormalTexture"].SetValue(false);
            this.Shader.Parameters["Tiling"].SetValue(new Vector2(1, 1));
            this.Shader.Parameters["LightDir"].SetValue(light.GetLightDirection());
            this.Shader.Parameters["LightColor"].SetValue(light.LightColor);
            this.Shader.Parameters["LightPosition"].SetValue(light.gameObject.Position);
            this.Shader.Parameters["AmbientColor"].SetValue(LightSystem.GetSingleton().AmbientColor);
            this.Shader.Parameters["CameraPosition"].SetValue(Engine.GetSingleton().MainCamera.Position);
            this.Shader.Parameters["SpecularColor"].SetValue(new Vector3(2, 2, 2));
            this.Shader.Parameters["SpecularPower"].SetValue(1.0f);
        }
Пример #8
0
        protected override void LoadContent()
        {
            this.mSpriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here
            GameObject         go       = new GameObject();
            ModelRenderObject  mr       = go.AddComponent <ModelRenderObject>();
            MultiLightMaterial material = new MultiLightMaterial();

            material.Tiling = new Vector2(10, 10);
            material.Shader = this.Content.Load <Effect>("Shaders/MultiLightShader");

            //PlaneMaterial material = new PlaneMaterial();
            //material.Shader = this.Content.Load<Effect>("Shaders/SpotLightShader");

            material.Tex1 = Engine.GetSingleton().Content.Load <Texture2D>("Checkerboard");
            mr.Init(this.Content.Load <Model>("FlatPlane"), material);
            go.LocalRotation = new Vector3(-90, 0, 0);

            for (int i = 0; i < 1; i++)
            {
                GameObject        teapot = new GameObject();
                ModelRenderObject mr2    = teapot.AddComponent <ModelRenderObject>();
                //TeapotMaterial material2 = new TeapotMaterial();
                //material2.Shader = this.Content.Load<Effect>("Shaders/SpotLightShader");
                MultiLightMaterial material2 = new MultiLightMaterial();
                material2.Shader = this.Content.Load <Effect>("Shaders/MultiLightShader");

                material2.Tex1 = Engine.GetSingleton().Content.Load <Texture2D>("Metal");
                mr2.Init(this.Content.Load <Model>("Teapot"), material2);
                //teapot.LocalScale = Vector3.One * 0.3f;

                if (i == 0)
                {
                    teapot.Position = new Vector3(0, 0, 0);
                }
                else if (i == 1)
                {
                    teapot.Position = new Vector3(-30, -20, 0);
                }
                else
                {
                    teapot.Position = new Vector3(0, -20, 20);
                }

                teapot.LocalScale   *= 50;
                teapot.LocalRotation = new Vector3(-90, 0, 0);
            }

            //GameObject go = new GameObject();
            //ModelRenderObject mr = go.AddComponent<ModelRenderObject>();
            //FighterMaterial material = new FighterMaterial();
            //material.Shader = this.Content.Load<Effect>("Fighter/FighterShader");
            //material.TexDiffuse = Engine.GetSingleton().Content.Load<Texture2D>("Fighter/FighterDiffuse");
            //material.TexNormal = Engine.GetSingleton().Content.Load<Texture2D>("Fighter/FighterNormal");
            //
            ////FighterBasicMaterial material = new FighterBasicMaterial();
            //
            //mr.Init(this.Content.Load<Model>("Fighter/fighter"), material);
            ////go.LocalRotation = new Vector3(-100, -120, 0);
            //go.LocalScale = Vector3.One * 0.03f;
            //go.AddComponent<TestLogic>();
        }