コード例 #1
0
ファイル: Game1.cs プロジェクト: ArTc0re/University
        private void Beleuchtungsrechnung_Spieler(Schlaeger spieler)
        {
            if (spieler == Spieler1)
                Material_diffuse = new Vector3(1f, 0f, 0f);
            if (spieler == Spieler2)
                Material_diffuse = new Vector3(0f, 0f, 1f);

            int vertices = spieler.Buffer2.Length - 1;
            int vertices2 = spieler.Buffer.Length - 1;

            // Ambienter Farbanteil
            Color_ambient = Light_ambient * Material_ambient;

            #region Zylinder"deckel"

            for (int i = 0; i <= vertices; i++)
            {

                Licht_direction = spieler.Buffer2[i].Position - Lichtquelle;
                Camera_direction = spieler.Buffer2[i].Position - Camera;
                Normale = new Vector3(0, 0, 1);

                // Diffuser Farbanteil
                float Skalarprodukt_NL = Normale.X * Licht_direction.X + Normale.Y * Licht_direction.Y + Normale.Z * Licht_direction.Z;
                float Betrag_NL = (float)Math.Sqrt(Normale.X * Normale.X + Normale.Y * Normale.Y + Normale.Z * Normale.Z) * (float)Math.Sqrt(Licht_direction.X * Licht_direction.X + Licht_direction.Y * Licht_direction.Y + Licht_direction.Z * Licht_direction.Z);

                angle_diffuse = Skalarprodukt_NL / Betrag_NL;

                if (angle_diffuse < 0)
                {
                    angle_diffuse = angle_diffuse * (-1);
                }

                Color_diffuse = Light_diffuse * Material_diffuse * angle_diffuse;

                // Spiegelnder Farbanteil
                float Skalarprodukt_CN = Normale.X * Camera_direction.X + Normale.Y * Camera_direction.Y + Normale.Z * Camera_direction.Z;
                float Betrag_CN = (float)Math.Sqrt(Normale.X * Normale.X + Normale.Y * Normale.Y + Normale.Z * Normale.Z) * (float)Math.Sqrt(Camera_direction.X * Camera_direction.X + Camera_direction.Y * Camera_direction.Y + Camera_direction.Z * Camera_direction.Z);

                angle_CN = Skalarprodukt_NL / Betrag_NL;

                if (angle_CN < 0)
                {
                    angle_CN = angle_CN * (-1);
                }
                angle_specular = angle_diffuse - angle_CN;

                Color_specular = Light_specular * Material_specular * angle_specular;

                // Gesamtfarbe
                Color_iluminated = Color_ambient + Color_diffuse + Color_specular;
                spieler.Buffer2[i].Color = new Color(Color_iluminated.X, Color_iluminated.Y, Color_iluminated.Z);
            }

            #endregion

            #region Zylindermantel

            for (int i = 0; i <= vertices2; i++)
            {

                Licht_direction = spieler.Buffer[i].Position - Lichtquelle;
                Camera_direction = spieler.Buffer[i].Position - Camera;

                float NormaleX = spieler.Buffer[i].Position.X - Spieler1.CurrentPosition.X;
                float NormaleY = spieler.Buffer[i].Position.Y - Spieler1.CurrentPosition.Y;

                float laenge_normale = (float)Math.Sqrt(NormaleX * NormaleX + NormaleY * NormaleY);
                Normale = new Vector3(NormaleX, NormaleY, 0);

                // Diffuser Farbanteil
                float Skalarprodukt_NL = Normale.X * Licht_direction.X + Normale.Y * Licht_direction.Y + Normale.Z * Licht_direction.Z;
                float Betrag_NL = (float)Math.Sqrt(Normale.X * Normale.X + Normale.Y * Normale.Y + Normale.Z * Normale.Z) * (float)Math.Sqrt(Licht_direction.X * Licht_direction.X + Licht_direction.Y * Licht_direction.Y + Licht_direction.Z * Licht_direction.Z);

                angle_diffuse = Skalarprodukt_NL / Betrag_NL;

                if (angle_diffuse < 0)
                {
                    angle_diffuse = angle_diffuse * (-1);
                }

                Color_diffuse = Light_diffuse * Material_diffuse * angle_diffuse;

                // Spiegelnder Farbanteil
                float Skalarprodukt_CN = Normale.X * Camera_direction.X + Normale.Y * Camera_direction.Y + Normale.Z * Camera_direction.Z;
                float Betrag_CN = (float)Math.Sqrt(Normale.X * Normale.X + Normale.Y * Normale.Y + Normale.Z * Normale.Z) * (float)Math.Sqrt(Camera_direction.X * Camera_direction.X + Camera_direction.Y * Camera_direction.Y + Camera_direction.Z * Camera_direction.Z);

                angle_CN = Skalarprodukt_NL / Betrag_NL;

                if (angle_CN < 0)
                {
                    angle_CN = angle_CN * (-1);
                }
                angle_specular = angle_diffuse - angle_CN;

                Color_specular = Light_specular * Material_specular * angle_specular;

                // Gesamtfarbe
                Color_iluminated = Color_ambient + Color_diffuse + Color_specular;
                spieler.Buffer[i].Color = new Color(Color_iluminated.X, Color_iluminated.Y, Color_iluminated.Z);
            }

            #endregion
        }
コード例 #2
0
ファイル: Game1.cs プロジェクト: ArTc0re/University
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            field = new Spielfeld(GraphicsDevice, Spielfeldbreite, Spielfeldlaenge, new Vector3(0, 0, 0), fieldTexture);

            puck = new Puck(GraphicsDevice, new Vector3(0, 0, 0), new Vector3(0, 0, 0));
            Spieler1 = new Schlaeger(GraphicsDevice, new Vector3(-22, 0, 0), new Color(1f, 0f, 0f));
            Spieler2 = new Schlaeger(GraphicsDevice, new Vector3(22, 0, 0), new Color(0f, 0f, 1f));

            fieldTexture = Content.Load<Texture2D>("textures\\snow");
        }