Advertisement
Guest User

Sym & Phys

a guest
Jun 26th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 19.40 KB | None | 0 0
  1.  
  2. using Microsoft.Xna.Framework;
  3. using Microsoft.Xna.Framework.Content;
  4. using Microsoft.Xna.Framework.Graphics;
  5. using Microsoft.Xna.Framework.Input;
  6. using System;
  7. using System.Collections.Generic;
  8.  
  9. namespace Opdracht6_Transformations
  10. {
  11.  
  12.  
  13.     public class SimPhyGameWorld : Game
  14.     {
  15.         private GraphicsDeviceManager graphDev;
  16.  
  17.         private Color background = new Color(20, 0, 60);
  18.  
  19.         public static SimPhyGameWorld World;
  20.  
  21.         private Vector3 cameraPosition = new Vector3(0f, 30f, 80f);
  22.  
  23.         public Matrix View;
  24.  
  25.         public Matrix Projection;
  26.  
  27.         public static GraphicsDevice Graphics;
  28.  
  29.         private List<Sphere> spheres;
  30.  
  31.         private Sphere sun;
  32.  
  33.         private Sphere earth;
  34.  
  35.         private Sphere moon;
  36.  
  37.         private Sphere mars;
  38.  
  39.         private Sphere jupiter;
  40.  
  41.         private Sphere saturnus;
  42.  
  43.         private Sphere uranus;
  44.  
  45.         private Sphere body1;
  46.  
  47.         private Sphere body2;
  48.  
  49.         private Sphere body3;
  50.  
  51.         private Sphere body4;
  52.  
  53.         private Sphere armL1;
  54.  
  55.         private Sphere armL2;
  56.  
  57.         private Sphere armL3;
  58.  
  59.         private Sphere handL;
  60.  
  61.         private Sphere armR1;
  62.  
  63.         private Sphere armR2;
  64.  
  65.         private Sphere armR3;
  66.  
  67.         private Sphere handR;
  68.  
  69.         private Sphere legL1;
  70.  
  71.         private Sphere legL2;
  72.  
  73.         private Sphere legL3;
  74.  
  75.         private Sphere footL;
  76.  
  77.         private Sphere legR1;
  78.  
  79.         private Sphere legR2;
  80.  
  81.         private Sphere legR3;
  82.  
  83.         private Sphere footR;
  84.  
  85.         private Sphere neck;
  86.  
  87.         private Sphere head1;
  88.  
  89.         private Sphere head2;
  90.  
  91.         private Sphere eyeL;
  92.  
  93.         private Sphere eyeR;
  94.  
  95.         private Matrix orientAL1;
  96.  
  97.         private Vector3 endAL1;
  98.  
  99.         private float blinkPhase;
  100.  
  101.         private float blink;
  102.  
  103.         private Random rand = new Random();
  104.  
  105.         public SimPhyGameWorld()
  106.         {
  107.             base.Content.RootDirectory = "Content";
  108.             SimPhyGameWorld.World = this;
  109.             this.graphDev = new GraphicsDeviceManager(this);
  110.         }
  111.  
  112.         protected override void Draw(GameTime gameTime)
  113.         {
  114.             base.GraphicsDevice.Clear(this.background);
  115.             foreach (Sphere sphere in this.spheres)
  116.             {
  117.                 sphere.Draw();
  118.             }
  119.             base.Draw(gameTime);
  120.         }
  121.  
  122.         protected override void Initialize()
  123.         {
  124.             SimPhyGameWorld.Graphics = base.GraphicsDevice;
  125.             this.graphDev.PreferredBackBufferWidth = 1280;
  126.             this.graphDev.PreferredBackBufferHeight = 800;
  127.             this.graphDev.IsFullScreen = false;
  128.             this.graphDev.ApplyChanges();
  129.             this.SetupCamera(true);
  130.             base.Window.Title = "HvA - Simulation & Physics - Opdracht 6 - Transformations - press <> to rotate camera";
  131.             this.spheres = new List<Sphere>();
  132.  
  133.  
  134.             //Sun
  135.             List<Sphere> spheres = this.spheres;
  136.             sun = new Sphere(Matrix.CreateScale(2f), Color.Yellow, 30);
  137.             spheres.Add(sun);
  138.  
  139.             //Earth
  140.             earth = new Sphere(Matrix.CreateTranslation(16f, 0f, 0f) * Matrix.CreateRotationY((float)(this.rand.NextDouble() * 6.28318548202515)), Color.Navy, 30);
  141.             spheres.Add(earth);
  142.  
  143.             //Moon
  144.             moon = new Sphere((Matrix.CreateScale(0.5f) * Matrix.CreateTranslation(18f, 0f, 0f)) * Matrix.CreateRotationY((float)(this.rand.NextDouble() * 6.28318548202515)), Color.LightGray, 30);
  145.             spheres.Add(moon);
  146.  
  147.             //Mars
  148.             mars = new Sphere((Matrix.CreateScale(0.6f) * Matrix.CreateTranslation(21f, 0f, 0f)) * Matrix.CreateRotationY((float)(this.rand.NextDouble() * 6.28318548202515)), Color.Red, 30);
  149.             spheres.Add(mars);
  150.  
  151.             //Jupiter
  152.             jupiter = new Sphere((Matrix.CreateScale(1.7f) * Matrix.CreateTranslation(27f, 0f, 0f)) * Matrix.CreateRotationY((float)(this.rand.NextDouble() * 6.28318548202515)), Color.Orange, 30);
  153.             spheres.Add(jupiter);
  154.  
  155.             //Saturnus
  156.             saturnus = new Sphere((Matrix.CreateScale(1.6f) * Matrix.CreateTranslation(36f, 0f, 0f)) * Matrix.CreateRotationY((float)(this.rand.NextDouble() * 6.28318548202515)), Color.Khaki, 30);
  157.             spheres.Add(saturnus);
  158.  
  159.             //Uranus
  160.             uranus = new Sphere((Matrix.CreateScale(1.5f) * Matrix.CreateTranslation(43f, 0f, 0f)) * Matrix.CreateRotationY((float)(this.rand.NextDouble() * 6.28318548202515)), Color.Cyan, 30);
  161.             spheres.Add(uranus);
  162.  
  163.  
  164.             //---Begin Body---
  165.             body1 = new Sphere(Matrix.CreateScale(2.9f, 1.3f, 2.5f) * Matrix.CreateTranslation(0f, 18.7f, 0f), Color.White, 30);
  166.             spheres.Add(body1);
  167.  
  168.             body2 = new Sphere(Matrix.CreateScale(3.1f, 1.5f, 2.7f) * Matrix.CreateTranslation(0f, 20f, 0f), Color.White, 30);
  169.             spheres.Add(body2);
  170.  
  171.             body3 = new Sphere(Matrix.CreateScale(3f, 1.5f, 2.6f) * Matrix.CreateTranslation(0f, 21.5f, 0f), Color.White, 30);
  172.             spheres.Add(body3);
  173.  
  174.             body4 = new Sphere(Matrix.CreateScale(2.7f, 1.3f, 2.4f) * Matrix.CreateTranslation(0f, 22.8f, 0f), Color.White, 30);
  175.             spheres.Add(body4);
  176.  
  177.  
  178.             //---Begin Arm Left---
  179.             this.orientAL1 = Matrix.CreateRotationZ(-0.3f);
  180.             armL1 = new Sphere(((Matrix.CreateScale(1.6f, 1f, 1f) * Matrix.CreateTranslation(1f, 0f, 0f)) * this.orientAL1) * Matrix.CreateTranslation(2.3f, 22.8f, 0f), Color.White, 30);
  181.             spheres.Add(armL1);
  182.             this.endAL1 = Vector3.Transform(new Vector3(1f, 0f, 0f), this.armL1.Transform);
  183.  
  184.             armL2 = new Sphere((Matrix.CreateScale(1f, 0.9f, 0.9f) * this.orientAL1) * Matrix.CreateTranslation(this.endAL1), Color.White, 30);
  185.             spheres.Add(armL2);
  186.  
  187.             Matrix orientAL3 = this.orientAL1 * Matrix.CreateRotationZ(1.6f);
  188.             armL3 = new Sphere(((Matrix.CreateScale(1.4f, 0.9f, 0.9f) * Matrix.CreateTranslation(1.4f, 0f, 0f)) * orientAL3) * Matrix.CreateTranslation(this.endAL1), Color.White, 30);
  189.             spheres.Add(armL3);
  190.             Vector3 endAL3 = Vector3.Transform(new Vector3(0.6f, 0f, 0f), this.armL3.Transform);
  191.  
  192.             Matrix orientHL = orientAL3 * Matrix.CreateRotationZ(0.1f);
  193.             handL = new Sphere(((Matrix.CreateScale(1.1f, 0.7f, 0.3f) * Matrix.CreateTranslation(0.8f, 0f, 0f)) * orientHL) * Matrix.CreateTranslation(endAL3), Color.White, 30);
  194.             spheres.Add(handL);
  195.  
  196.  
  197.             //---Begin Arm Right---
  198.             Matrix orientAR1 = Matrix.CreateRotationZ(0.8f) * Matrix.CreateRotationY(-0.5f);
  199.             armR1 = new Sphere(((Matrix.CreateScale(1.6f, 1f, 1f) * Matrix.CreateTranslation(-1f, 0f, 0f)) * orientAR1) * Matrix.CreateTranslation(-2.3f, 22.8f, 0f), Color.White, 30);
  200.             spheres.Add(armR1);
  201.             Vector3 endAR1 = Vector3.Transform(new Vector3(-1f, 0f, 0f), this.armR1.Transform);
  202.  
  203.             armR2 = new Sphere((Matrix.CreateScale(1f, 0.9f, 0.9f) * orientAR1) * Matrix.CreateTranslation(endAR1), Color.White, 30);
  204.             spheres.Add(armR2);
  205.  
  206.             Matrix orientAR3 = (orientAR1 * Matrix.CreateRotationZ(0.3f)) * Matrix.CreateRotationY(1.5f);
  207.             armR3 = new Sphere(((Matrix.CreateScale(1.4f, 0.9f, 0.9f) * Matrix.CreateTranslation(-1.4f, 0f, 0f)) * orientAR3) * Matrix.CreateTranslation(endAR1), Color.White, 30);
  208.             spheres.Add(armR3);
  209.             Vector3 endAR3 = Vector3.Transform(new Vector3(-0.6f, 0f, 0f), this.armR3.Transform);
  210.  
  211.             Matrix orientHR = orientAR3 * Matrix.CreateRotationZ(0.4f);
  212.             handR = new Sphere(((Matrix.CreateScale(1.1f, 0.7f, 0.3f) * Matrix.CreateTranslation(-0.8f, 0f, 0f)) * orientHR) * Matrix.CreateTranslation(endAR3), Color.White, 30);
  213.             spheres.Add(handR);
  214.  
  215.  
  216.             //---Begin Leg Left---
  217.             Matrix orientLL1 = (Matrix.CreateRotationY(-0.7f) * Matrix.CreateRotationZ(-1.5f)) * Matrix.CreateRotationX(-0.2f);
  218.             legL1 = new Sphere(((Matrix.CreateScale(2f, 1.7f, 1.7f) * Matrix.CreateTranslation(1f, 0f, 0f)) * orientLL1) * Matrix.CreateTranslation(1.4f, 17.5f, 0f), Color.White, 30);
  219.             spheres.Add(legL1);
  220.             Vector3 endLL1 = Vector3.Transform(new Vector3(1f, 0f, 0f), this.legL1.Transform);
  221.  
  222.             legL2 = new Sphere((Matrix.CreateScale(1.3f, 1.3f, 1.3f) * orientLL1) * Matrix.CreateTranslation(endLL1), Color.White, 30);
  223.             spheres.Add(legL2);
  224.  
  225.             Matrix orientLL3 = orientLL1 * Matrix.CreateRotationX(1.4f);
  226.             legL3 = new Sphere(((Matrix.CreateScale(2f, 1.5f, 1.5f) * Matrix.CreateTranslation(1.4f, 0f, 0f)) * orientLL3) * Matrix.CreateTranslation(endLL1), Color.White, 30);
  227.             spheres.Add(legL3);
  228.             Vector3 endLL3 = Vector3.Transform(new Vector3(1f, 0f, 0f), this.legL3.Transform);
  229.  
  230.             Matrix orientFL = orientLL3 * Matrix.CreateRotationX(-1.4f);
  231.             footL = new Sphere(((Matrix.CreateScale(1.8f, 1f, 0.7f) * Matrix.CreateTranslation(0.8f, 0f, 0f)) * orientFL) * Matrix.CreateTranslation(endLL3), Color.White, 30);
  232.             spheres.Add(footL);
  233.  
  234.  
  235.             //---Begin Leg Right---
  236.             Matrix orientLR1 = (Matrix.CreateRotationY(0.4f) * Matrix.CreateRotationZ(-1.63f)) * Matrix.CreateRotationX(-0.2f);
  237.             legR1 = new Sphere(((Matrix.CreateScale(2f, 1.7f, 1.7f) * Matrix.CreateTranslation(1f, 0f, 0f)) * orientLR1) * Matrix.CreateTranslation(-1.4f, 17.5f, 0f), Color.White, 30);
  238.             spheres.Add(legR1);
  239.             Vector3 endLR1 = Vector3.Transform(new Vector3(1f, 0f, 0f), this.legR1.Transform);
  240.  
  241.             legR2 = new Sphere((Matrix.CreateScale(1.3f, 1.3f, 1.3f) * orientLR1) * Matrix.CreateTranslation(endLR1), Color.White, 30);
  242.             spheres.Add(legR2);
  243.  
  244.             Matrix orientLR3 = orientLR1 * Matrix.CreateRotationX(0.5f);
  245.             legR3 = new Sphere(((Matrix.CreateScale(2f, 1.5f, 1.5f) * Matrix.CreateTranslation(1.4f, 0f, 0f)) * orientLR3) * Matrix.CreateTranslation(endLR1), Color.White, 30);
  246.             spheres.Add(legR3);
  247.             Vector3 endLR3 = Vector3.Transform(new Vector3(1f, 0f, 0f), this.legR3.Transform);
  248.  
  249.             Matrix orientFR = orientLR3 * Matrix.CreateRotationX(-1.9f);
  250.    
  251.             footR = new Sphere(((Matrix.CreateScale(1.8f, 1f, 0.7f) * Matrix.CreateTranslation(0.8f, 0f, 0f)) * orientFR) * Matrix.CreateTranslation(endLR3), Color.White, 30);
  252.             spheres.Add(footR);
  253.  
  254.  
  255.             //---Begin Head---
  256.             neck = new Sphere(Matrix.CreateScale(1.4f, 1.2f, 1.3f) * Matrix.CreateTranslation(0f, 24f, 0f), Color.White, 30);
  257.             spheres.Add(neck);
  258.  
  259.             head1 = new Sphere(Matrix.CreateScale(2f, 1.2f, 1.7f) * Matrix.CreateTranslation(0f, 25f, 0f), Color.White, 30);
  260.             spheres.Add(head1);
  261.  
  262.             head2 = new Sphere(Matrix.CreateScale(1.4f, 1.4f, 1.4f) * Matrix.CreateTranslation(0f, 25.8f, 0f), Color.White, 30);
  263.             spheres.Add(head2);
  264.  
  265.             eyeL = new Sphere((Matrix.CreateScale(0.2f, 0.25f, 0.1f) * Matrix.CreateTranslation(0.32f, 0.1f, 0.95f)) * this.head2.Transform, Color.Black, 30);
  266.             spheres.Add(eyeL);
  267.  
  268.             eyeR = new Sphere((Matrix.CreateScale(0.2f, 0.25f, 0.1f) * Matrix.CreateTranslation(-0.32f, 0.1f, 0.95f)) * this.head2.Transform, Color.Black, 30);
  269.             spheres.Add(eyeR);
  270.  
  271.             base.Initialize();
  272.         }
  273.  
  274.         protected override void LoadContent()
  275.         {
  276.             base.LoadContent();
  277.             base.IsMouseVisible = true;
  278.         }
  279.  
  280.         private void SetupCamera(bool initialize = false)
  281.         {
  282.             this.View = Matrix.CreateLookAt(this.cameraPosition, new Vector3(0f, 0f, 0f), new Vector3(0f, 1f, 0f));
  283.             if (initialize)
  284.             {
  285.                 Viewport viewport = SimPhyGameWorld.World.GraphicsDevice.Viewport;
  286.                 this.Projection = Matrix.CreatePerspectiveFieldOfView(0.7853982f, viewport.AspectRatio, 1f, 300f);
  287.             }
  288.         }
  289.  
  290.         protected override void Update(GameTime gameTime)
  291.         {
  292.             /*
  293.                 * --------------------------
  294.                 *
  295.                 * Made by: Micha Ferdinandus
  296.                 *
  297.                 * --------------------------
  298.             * */
  299.  
  300.             if (Keyboard.GetState().IsKeyDown(Keys.Right))
  301.             {
  302.                 this.cameraPosition = Vector3.Transform(this.cameraPosition, Matrix.CreateRotationY((float)gameTime.ElapsedGameTime.TotalSeconds * 1.3f));
  303.                 this.SetupCamera(false);
  304.             }
  305.             else if (Keyboard.GetState().IsKeyDown(Keys.Left))
  306.             {
  307.                 this.cameraPosition = Vector3.Transform(this.cameraPosition, Matrix.CreateRotationY((float)gameTime.ElapsedGameTime.TotalSeconds * -1.3f));
  308.                 this.SetupCamera(false);
  309.             }
  310.  
  311.             //Uranus
  312.             uranus.Transform *= Matrix.CreateRotationY(0.33f * (float)gameTime.ElapsedGameTime.TotalSeconds);
  313.  
  314.             //Saturn
  315.             saturnus.Transform *= Matrix.CreateRotationY(0.26f * (float)gameTime.ElapsedGameTime.TotalSeconds);
  316.  
  317.             //Jupiter
  318.             jupiter.Transform *= Matrix.CreateRotationY(0.22f * (float)gameTime.ElapsedGameTime.TotalSeconds);
  319.  
  320.             //Mars
  321.             mars.Transform *= Matrix.CreateRotationY(0.2f * (float)gameTime.ElapsedGameTime.TotalSeconds);
  322.  
  323.             //Earth
  324.             earth.Transform *= Matrix.CreateRotationY(0.3f * (float)gameTime.ElapsedGameTime.TotalSeconds);
  325.  
  326.             //Moon
  327.             Matrix matrixHelp1 = Matrix.CreateScale(0.5f) * Matrix.CreateTranslation(2f, 0f, 0f);
  328.             moon.Transform = ((matrixHelp1 * Matrix.CreateRotationY(1.5f * (float)gameTime.TotalGameTime.TotalSeconds)) * Matrix.CreateRotationZ(0.7853982f)) * earth.Transform;
  329.  
  330.  
  331.             //---Begin Left Arm + hand
  332.             Matrix orientAL3 = orientAL1 * Matrix.CreateRotationZ(1.6f + (float)(0.2 * Math.Sin(gameTime.TotalGameTime.TotalSeconds * 6)));
  333.             armL3.Transform = ((Matrix.CreateScale(1.4f, 0.9f, 0.9f) * Matrix.CreateTranslation(1.4f, 0f, 0f)) * orientAL3) * Matrix.CreateTranslation(endAL1);
  334.  
  335.             Vector3 endAL3 = Vector3.Transform(new Vector3(0.6f, 0f, 0f), armL3.Transform);
  336.             Matrix matrixHelp2 = orientAL3 * Matrix.CreateRotationZ(0.1f + (float)(0.3 * Math.Sin(gameTime.TotalGameTime.TotalSeconds * 6)));
  337.  
  338.             Matrix orientHL = matrixHelp2 * Matrix.CreateRotationY((float)(0.4 * Math.Sin(gameTime.TotalGameTime.TotalSeconds * 6)));
  339.             handL.Transform = ((Matrix.CreateScale(1.1f, 0.7f, 0.3f) * Matrix.CreateTranslation(0.8f, 0f, 0f)) * orientHL) * Matrix.CreateTranslation(endAL3);
  340.  
  341.  
  342.             //--Begin Left Leg + foot
  343.             Matrix orientLL1 = (Matrix.CreateRotationY((float)(0.66 * Math.Sin(gameTime.TotalGameTime.TotalSeconds * 4))) * Matrix.CreateRotationZ(-1.5f)) * Matrix.CreateRotationX(-0.2f);
  344.             legL1.Transform = ((Matrix.CreateScale(2f, 1.7f, 1.7f) * Matrix.CreateTranslation(1f, 0f, 0f)) * orientLL1) * Matrix.CreateTranslation(1.4f, 17.5f, 0f);
  345.  
  346.             Vector3 endLL1 = Vector3.Transform(new Vector3(1f, 0f, 0f), legL1.Transform);
  347.             legL2.Transform = (Matrix.CreateScale(1.3f, 1.3f, 1.3f) * orientLL1) * Matrix.CreateTranslation(endLL1);
  348.  
  349.             Matrix orientLL3 = orientLL1 * Matrix.CreateRotationX(1f - (float)(0.66 * Math.Cos(gameTime.TotalGameTime.TotalSeconds * 4)));
  350.             legL3.Transform = ((Matrix.CreateScale(2f, 1.5f, 1.5f) * Matrix.CreateTranslation(1.4f, 0f, 0f)) * orientLL3) * Matrix.CreateTranslation(endLL1);
  351.             Vector3 endLL3 = Vector3.Transform(new Vector3(1f, 0f, 0f), legL3.Transform);
  352.  
  353.             Matrix orientFL = orientLL3 * Matrix.CreateRotationX(-1.4f + (float)(0.5 * Math.Sin(gameTime.TotalGameTime.TotalSeconds * 4 - 2)));
  354.             footL.Transform = ((Matrix.CreateScale(1.8f, 1f, 0.7f) * Matrix.CreateTranslation(0.8f, 0f, 0f)) * orientFL) * Matrix.CreateTranslation(endLL3);
  355.  
  356.  
  357.             //---Begin Right Leg + foot---
  358.             Matrix orientLR1 = (Matrix.CreateRotationY((float)(0.66 * Math.Sin(gameTime.TotalGameTime.TotalSeconds * 4 + 2))) * Matrix.CreateRotationZ(-1.5f)) * Matrix.CreateRotationX(-0.2f);
  359.             legR1.Transform = ((Matrix.CreateScale(2f, 1.7f, 1.7f) * Matrix.CreateTranslation(1f, 0f, 0f)) * orientLR1) * Matrix.CreateTranslation(-1.4f, 17.5f, 0f);
  360.  
  361.             Vector3 endLR1 = Vector3.Transform(new Vector3(1f, 0f, 0f), legR1.Transform);
  362.             legR2.Transform = (Matrix.CreateScale(1.3f, 1.3f, 1.3f) * orientLR1) * Matrix.CreateTranslation(endLR1);
  363.  
  364.             Matrix orientLR3 = orientLR1 * Matrix.CreateRotationX(1f - (float)(0.66 * Math.Cos(gameTime.TotalGameTime.TotalSeconds * 4 + 2)));
  365.             legR3.Transform = ((Matrix.CreateScale(2f, 1.5f, 1.5f) * Matrix.CreateTranslation(1.4f, 0f, 0f)) * orientLR3) * Matrix.CreateTranslation(endLR1);
  366.             Vector3 endLR3 = Vector3.Transform(new Vector3(1f, 0f, 0f), legR3.Transform);
  367.  
  368.             Matrix orientFR = orientLR3 * Matrix.CreateRotationX(-1.4f + (float)(0.5 * Math.Sin(gameTime.TotalGameTime.TotalSeconds * 4)));
  369.             footR.Transform = ((Matrix.CreateScale(1.8f, 1f, 0.7f) * Matrix.CreateTranslation(0.8f, 0f, 0f)) * orientFR) * Matrix.CreateTranslation(endLR3);
  370.  
  371.             /*
  372.                 * --------------------------
  373.                 *
  374.                 * Made by: Micha Ferdinandus
  375.                 *
  376.                 * --------------------------
  377.             * */
  378.  
  379.             //--Begin Left Leg + foot---
  380.             Matrix matrixHelp3 = Matrix.CreateRotationZ(0.8f) * Matrix.CreateRotationY((float)(0.1 * Math.Sin(gameTime.TotalGameTime.TotalSeconds * 4 + 2)));
  381.  
  382.             Matrix orientAR1 = matrixHelp3 * Matrix.CreateRotationX((float)(-0.1 * Math.Sin(gameTime.TotalGameTime.TotalSeconds * 4 + 2)));
  383.             armR1.Transform = ((Matrix.CreateScale(1.6f, 1f, 1f) * Matrix.CreateTranslation(-1f, 0f, 0f)) * orientAR1) * Matrix.CreateTranslation(-2.3f, 22.8f, 0f);
  384.  
  385.             Vector3 endAR1 = Vector3.Transform(new Vector3(-1f, 0f, 0f), this.armR1.Transform);
  386.             armR2.Transform = (Matrix.CreateScale(1f, 0.9f, 0.9f) * orientAR1) * Matrix.CreateTranslation(endAR1);
  387.  
  388.             Matrix orientAR3 = (orientAR1 * Matrix.CreateRotationZ(0.3f)) * Matrix.CreateRotationY(1.5f);
  389.             armR3.Transform = ((Matrix.CreateScale(1.4f, 0.9f, 0.9f) * Matrix.CreateTranslation(-1.4f, 0f, 0f)) * orientAR3) * Matrix.CreateTranslation(endAR1);
  390.             Vector3 endAR3 = Vector3.Transform(new Vector3(-0.6f, 0f, 0f), armR3.Transform);
  391.  
  392.             Matrix orientHR = orientAR3 * Matrix.CreateRotationZ(0.4f);
  393.             handR.Transform = ((Matrix.CreateScale(1.1f, 0.7f, 0.3f) * Matrix.CreateTranslation(-0.8f, 0f, 0f)) * orientHR) * Matrix.CreateTranslation(endAR3);
  394.  
  395.  
  396.             //---Begin Blinking
  397.             this.blinkPhase -= (float)gameTime.ElapsedGameTime.TotalSeconds;
  398.             if (this.blinkPhase <= 0f)
  399.             {
  400.                 this.blink = 1f;
  401.                 this.blinkPhase = 2f + (float)this.rand.NextDouble() * 3f;
  402.             }
  403.             else if (this.blinkPhase < 0.25f)
  404.             {
  405.                 this.blink = (0.25f - this.blinkPhase) / 0.25f;
  406.             }
  407.             this.eyeL.Transform = (Matrix.CreateScale(0.2f, 0.03f + 0.22f * this.blink, 0.1f) * Matrix.CreateTranslation(0.32f, 0.1f, 0.95f)) * this.head2.Transform;
  408.             this.eyeR.Transform = (Matrix.CreateScale(0.2f, 0.03f + 0.22f * this.blink, 0.1f) * Matrix.CreateTranslation(-0.32f, 0.1f, 0.95f)) * this.head2.Transform;
  409.  
  410.             base.Update(gameTime);
  411.         }
  412.     }
  413. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement