Advertisement
Guest User

TexturedBox.cs

a guest
Sep 17th, 2011
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 24.63 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Microsoft.Xna.Framework;
  6. using Microsoft.Xna.Framework.Graphics;
  7. using BEPUphysics.Entities.Prefabs;
  8.  
  9. namespace CharacterControllerTest
  10. {
  11.     /// <summary>
  12.     /// A physics box that can also be drawn, with textures on each side.
  13.     /// </summary>
  14.     class TexturedBox : Box
  15.     {
  16.         /// <summary>
  17.         /// The names of each side of a box.
  18.         /// </summary>
  19.         public enum BoxSideName { Top, Bottom, Front, Back, Right, Left };
  20.  
  21.         /// <summary>
  22.         /// Nested class for storing information about each side of the box.
  23.         /// </summary>
  24.         public class BoxSide
  25.         {
  26.             /// <summary>
  27.             /// Fires when the orientation of a texture is changed.
  28.             /// </summary>
  29.             public event EventHandler TextureOrientationChanged;
  30.  
  31.             /// <summary>
  32.             /// Called when the texture on the side is flipped.
  33.             /// </summary>
  34.             private void OnTextureOrientationChanged()
  35.             {
  36.                 EventArgs e = new EventArgs();
  37.                 TextureOrientationChanged(this, e);
  38.             }
  39.  
  40.             /// <summary>
  41.             /// The name of this side.
  42.             /// </summary>
  43.             public BoxSideName Name { get; private set; }
  44.  
  45.             /// <summary>
  46.             /// The texture of this side.
  47.             /// </summary>
  48.             public Texture2D Texture { get; set; }
  49.  
  50.             /// <summary>
  51.             /// Is the texture on this side flipped horizontally?
  52.             /// </summary>
  53.             private bool flipHorizontal;
  54.  
  55.             /// <summary>
  56.             /// Sets wheter the texture on this side should be flipped horizontally.
  57.             /// </summary>
  58.             public bool FlipTextureHorizontal
  59.             {
  60.                 get { return flipHorizontal; }
  61.                 set
  62.                 {
  63.                     flipHorizontal = value;
  64.  
  65.                     // Texture orientation has changed.
  66.                     OnTextureOrientationChanged();
  67.                 }
  68.             }
  69.  
  70.             /// <summary>
  71.             /// Is the texture on this side flipped vertically?
  72.             /// </summary>
  73.             private bool flipVertical;
  74.  
  75.             /// <summary>
  76.             /// Sets whether the texture on this side should be flipped vertically.
  77.             /// </summary>
  78.             public bool FlipTextureVertical
  79.             {
  80.                 get { return flipVertical; }
  81.                 set
  82.                 {
  83.                     flipVertical = value;
  84.  
  85.                     // Texture orientation has changed.
  86.                     OnTextureOrientationChanged();
  87.                 }
  88.             }
  89.  
  90.             /// <summary>
  91.             /// Constructor for holding information about the side of a box.
  92.             /// </summary>
  93.             /// <param name="name">The name of this side.</param>
  94.             /// <param name="texture">The texture of this side.</param>
  95.             public BoxSide(BoxSideName name, Texture2D texture)
  96.             {
  97.                 Name = name;
  98.                 Texture = texture;
  99.  
  100.                 // By default, don't flip the texture.
  101.                 flipHorizontal = false;
  102.                 flipVertical = false;
  103.             }
  104.  
  105.         }
  106.  
  107.         /// <summary>
  108.         /// The top side of the box.
  109.         /// </summary>
  110.         public BoxSide Top { get; private set; }
  111.  
  112.         /// <summary>
  113.         /// The bottom side of the box.
  114.         /// </summary>
  115.         public BoxSide Bottom { get; private set; }
  116.        
  117.         /// <summary>
  118.         /// The front side of the box.
  119.         /// </summary>
  120.         public BoxSide Front { get; private set; }
  121.  
  122.         /// <summary>
  123.         /// The back side of the box.
  124.         /// </summary>
  125.         public BoxSide Back { get; private set; }
  126.  
  127.         /// <summary>
  128.         /// The right side of the box.
  129.         /// </summary>
  130.         public BoxSide Right { get; private set; }
  131.  
  132.         /// <summary>
  133.         /// The left side of the box.
  134.         /// </summary>
  135.         public BoxSide Left { get; private set; }
  136.  
  137.         /// <summary>
  138.         /// The BasicEffect used to draw the box.
  139.         /// </summary>
  140.         private BasicEffect effect;
  141.  
  142.         /// <summary>
  143.         /// An array holding the vertices of the box.
  144.         /// </summary>
  145.         private VertexPositionNormalTexture[] verts;
  146.  
  147.         /// <summary>
  148.         /// An array holding the indices of the box.
  149.         /// </summary>
  150.         private short[] indices;
  151.  
  152.         /// <summary>
  153.         /// An array holding the corner positions of the box.
  154.         /// </summary>
  155.         private Vector3[] corners;
  156.  
  157.         /// <summary>
  158.         /// The GraphicsDevice used to draw the box.
  159.         /// </summary>
  160.         private readonly GraphicsDevice graphicsDevice;
  161.  
  162.         /// <summary>
  163.         /// Constructs a nondynamic TexturedBox.
  164.         /// </summary>
  165.         /// <param name="pos">The position of the box.</param>
  166.         /// <param name="width">The width of the box.</param>
  167.         /// <param name="height">The height of the box.</param>
  168.         /// <param name="length">The length of the box.</param>
  169.         /// <param name="texture">The texture to apply to all sides of the box.</param>
  170.         /// <param name="graphicsDevice">The graphics device of the game.</param>
  171.         public TexturedBox(Vector3 pos, float width, float height, float length,
  172.             Texture2D texture, GraphicsDevice graphicsDevice)
  173.             : base(pos, width, height, length)
  174.         {
  175.             this.graphicsDevice = graphicsDevice;
  176.             effect = new BasicEffect(graphicsDevice);
  177.             effect.EnableDefaultLighting();
  178.             effect.VertexColorEnabled = false;
  179.             effect.TextureEnabled = true;
  180.  
  181.             // Apply the texture to all sides of the box.
  182.             // Also, wire up the BoxSide's TextureChanged event to the event handler
  183.             // so that the textures can be modified if any changes are made.
  184.  
  185.             Top = new BoxSide(BoxSideName.Top, texture);
  186.             Top.TextureOrientationChanged += TextureChangedHandler;
  187.  
  188.             Bottom = new BoxSide(BoxSideName.Bottom, texture);
  189.             Bottom.TextureOrientationChanged += TextureChangedHandler;
  190.  
  191.             Front = new BoxSide(BoxSideName.Front, texture);
  192.             Front.TextureOrientationChanged += TextureChangedHandler;
  193.  
  194.             Back = new BoxSide(BoxSideName.Back, texture);
  195.             Back.TextureOrientationChanged += TextureChangedHandler;
  196.  
  197.             Right = new BoxSide(BoxSideName.Right, texture);
  198.             Right.TextureOrientationChanged += TextureChangedHandler;
  199.  
  200.             Left = new BoxSide(BoxSideName.Left, texture);
  201.             Left.TextureOrientationChanged += TextureChangedHandler;
  202.            
  203.             // Now set up the box.
  204.             InitializeBox();
  205.         }
  206.  
  207.         /// <summary>
  208.         /// Constructs a physically simulated TexturedBox.
  209.         /// </summary>
  210.         /// <param name="pos">The position of the box.</param>
  211.         /// <param name="width">The width of the box.</param>
  212.         /// <param name="height">The height of the box.</param>
  213.         /// <param name="length">The length of the box.</param>
  214.         /// <param name="mass">The mass of the box.</param>
  215.         /// <param name="texture">The texture to apply to all sides of the box.</param>
  216.         /// <param name="graphicsDevice">The graphics device of the game.</param>
  217.         public TexturedBox(Vector3 pos, float width, float height, float length,
  218.             float mass, Texture2D texture, GraphicsDevice graphicsDevice)
  219.             : base(pos, width, height, length, mass)
  220.         {
  221.             this.graphicsDevice = graphicsDevice;
  222.             effect = new BasicEffect(graphicsDevice);
  223.             effect.EnableDefaultLighting();
  224.             effect.VertexColorEnabled = false;
  225.             effect.TextureEnabled = true;
  226.  
  227.             // Apply the texture to all sides of the box.
  228.             // Also, wire up the BoxSide's TextureChanged event to the event handler
  229.             // so that the textures can be modified if any changes are made.
  230.  
  231.             Top = new BoxSide(BoxSideName.Top, texture);
  232.             Top.TextureOrientationChanged += TextureChangedHandler;
  233.  
  234.             Bottom = new BoxSide(BoxSideName.Bottom, texture);
  235.             Bottom.TextureOrientationChanged += TextureChangedHandler;
  236.  
  237.             Front = new BoxSide(BoxSideName.Front, texture);
  238.             Front.TextureOrientationChanged += TextureChangedHandler;
  239.  
  240.             Back = new BoxSide(BoxSideName.Back, texture);
  241.             Back.TextureOrientationChanged += TextureChangedHandler;
  242.  
  243.             Right = new BoxSide(BoxSideName.Right, texture);
  244.             Right.TextureOrientationChanged += TextureChangedHandler;
  245.  
  246.             Left = new BoxSide(BoxSideName.Left, texture);
  247.             Left.TextureOrientationChanged += TextureChangedHandler;
  248.  
  249.             // Now set up the box.
  250.             InitializeBox();
  251.         }
  252.  
  253.         /// <summary>
  254.         /// Sets up the vertices and indices of the box.
  255.         /// </summary>
  256.         private void InitializeBox()
  257.         {
  258.             // If we haven't already, get the corner positions of the box.
  259.             if (corners == null)
  260.                 corners = GetCorners();
  261.  
  262.             // When working with normals, it's not enough to hold just 8 vertices.
  263.             // We need to hold 4 vertices with unique normals for each side of the box.
  264.             verts = new VertexPositionNormalTexture[24];
  265.  
  266.             // The bottom/top corners are as if you are looking directly at that face of the box
  267.             // At the top from above, the bottom from below, from the left of the left side, etc.
  268.  
  269.             // Initialize the vertices for each side of the box.
  270.  
  271.             InitializeSideVertices(Top);
  272.  
  273.             InitializeSideVertices(Bottom);
  274.  
  275.             InitializeSideVertices(Front);
  276.  
  277.             InitializeSideVertices(Back);
  278.  
  279.             InitializeSideVertices(Right);
  280.  
  281.             InitializeSideVertices(Left);
  282.  
  283.  
  284.             // Initialize the indices that will be used to draw the triangles of the box.
  285.  
  286.             indices = new short[]
  287.             {
  288.                 // TOP
  289.                 0, 1, 2,
  290.                 1, 3, 2,
  291.  
  292.                 // BOTTOM
  293.                 7, 4, 5,
  294.                 6, 4, 7,
  295.  
  296.                 // FRONT
  297.                 8, 9, 10,
  298.                 9, 11, 10,
  299.  
  300.                 // BACK
  301.                 12, 13, 14,
  302.                 13, 15, 14,
  303.  
  304.                 // RIGHT
  305.                 16, 17, 18,
  306.                 17, 19, 18,
  307.  
  308.                 // LEFT
  309.                 21, 23, 22,
  310.                 20, 21, 22
  311.             };
  312.         }
  313.  
  314.         /// <summary>
  315.         /// Handler for dealing with a change in texture orientation on a side of the box.
  316.         /// </summary>
  317.         /// <param name="sender">The object that fired the event.</param>
  318.         /// <param name="e">The event arguments.</param>
  319.         private void TextureChangedHandler(object sender, EventArgs e)
  320.         {
  321.             // Cast the sender object as a BoxSide
  322.             BoxSide boxSide = sender as BoxSide;
  323.  
  324.             // Reset the vertices for that side of the box.
  325.             InitializeSideVertices(boxSide);
  326.         }
  327.  
  328.         /// <summary>
  329.         /// Sets up the vertices for a certain side of the box.
  330.         /// </summary>
  331.         /// <param name="side">The side to set the vertices for.</param>
  332.         private void InitializeSideVertices(BoxSide side)
  333.         {
  334.             // Create a Vector2 array to hold the 4 texture coordinates of the side.
  335.             Vector2[] textureCorners;
  336.  
  337.             // Now, check to see which side will get its vertices set.
  338.             // Also, we need to get the texture coordinates for each side
  339.             // via the DetermineTextureCoords function to see if any flipping is needed.
  340.  
  341.             if (side.Name == BoxSideName.Top)
  342.             {
  343.                 // TOP OF THE BOX
  344.                 //---------------------------------------
  345.                 textureCorners = DetermineTextureCoords(Top);
  346.                 // Top left corner
  347.                 verts[0] = new VertexPositionNormalTexture(
  348.                     corners[4], Vector3.Up, textureCorners[0]);
  349.  
  350.                 // Top right corner
  351.                 verts[1] = new VertexPositionNormalTexture(
  352.                     corners[5], Vector3.Up, textureCorners[1]);
  353.  
  354.                 // Bottom left corner
  355.                 verts[2] = new VertexPositionNormalTexture(
  356.                     corners[0], Vector3.Up, textureCorners[3]);
  357.  
  358.                 // Bottom right corner
  359.                 verts[3] = new VertexPositionNormalTexture(
  360.                     corners[1], Vector3.Up, textureCorners[2]);
  361.                 //---------------------------------------
  362.             }
  363.  
  364.             else if (side.Name == BoxSideName.Bottom)
  365.             {
  366.                 // BOTTOM OF THE BOX
  367.                 //---------------------------------------
  368.                 textureCorners = DetermineTextureCoords(Bottom);
  369.                 // Top left corner
  370.                 verts[4] = new VertexPositionNormalTexture(
  371.                     corners[3], Vector3.Down, textureCorners[0]);
  372.  
  373.                 // Top right corner
  374.                 verts[5] = new VertexPositionNormalTexture(
  375.                     corners[2], Vector3.Down, textureCorners[1]);
  376.  
  377.                 // Bottom left corner
  378.                 verts[6] = new VertexPositionNormalTexture(
  379.                     corners[7], Vector3.Down, textureCorners[3]);
  380.  
  381.                 // Bottom right corner
  382.                 verts[7] = new VertexPositionNormalTexture(
  383.                     corners[6], Vector3.Down, textureCorners[2]);
  384.                 //---------------------------------------
  385.             }
  386.  
  387.             else if (side.Name == BoxSideName.Front)
  388.             {
  389.                 // FRONT OF THE BOX
  390.                 //---------------------------------------
  391.                 textureCorners = DetermineTextureCoords(Front);
  392.                 // Top left corner
  393.                 verts[8] = new VertexPositionNormalTexture(
  394.                     corners[0], Vector3.Backward, textureCorners[0]);
  395.  
  396.                 // Top right corner
  397.                 verts[9] = new VertexPositionNormalTexture(
  398.                     corners[1], Vector3.Backward, textureCorners[1]);
  399.  
  400.                 // Bottom left corner
  401.                 verts[10] = new VertexPositionNormalTexture(
  402.                     corners[3], Vector3.Backward, textureCorners[3]);
  403.  
  404.                 // Bottom right corner
  405.                 verts[11] = new VertexPositionNormalTexture(
  406.                     corners[2], Vector3.Backward, textureCorners[2]);
  407.                 //---------------------------------------
  408.             }
  409.  
  410.             else if (side.Name == BoxSideName.Back)
  411.             {
  412.                 // BACK OF THE BOX
  413.                 //---------------------------------------
  414.                 textureCorners = DetermineTextureCoords(Back);
  415.                 // Top left corner
  416.                 verts[12] = new VertexPositionNormalTexture(
  417.                     corners[5], Vector3.Forward, textureCorners[0]);
  418.  
  419.                 // Top right corner
  420.                 verts[13] = new VertexPositionNormalTexture(
  421.                     corners[4], Vector3.Forward, textureCorners[1]);
  422.  
  423.                 // Bottom left corner
  424.                 verts[14] = new VertexPositionNormalTexture(
  425.                     corners[6], Vector3.Forward, textureCorners[3]);
  426.  
  427.                 // Bottom right corner
  428.                 verts[15] = new VertexPositionNormalTexture(
  429.                     corners[7], Vector3.Forward, textureCorners[2]);
  430.                 //---------------------------------------
  431.             }
  432.  
  433.             else if (side.Name == BoxSideName.Right)
  434.             {
  435.                 // RIGHT OF THE BOX
  436.                 //---------------------------------------
  437.                 textureCorners = DetermineTextureCoords(Right);
  438.                 // Top left corner
  439.                 verts[16] = new VertexPositionNormalTexture(
  440.                     corners[1], Vector3.Right, textureCorners[0]);
  441.  
  442.                 // Top right corner
  443.                 verts[17] = new VertexPositionNormalTexture(
  444.                     corners[5], Vector3.Right, textureCorners[1]);
  445.  
  446.                 // Bottom left corner
  447.                 verts[18] = new VertexPositionNormalTexture(
  448.                     corners[2], Vector3.Right, textureCorners[3]);
  449.  
  450.                 // Bottom right corner
  451.                 verts[19] = new VertexPositionNormalTexture(
  452.                     corners[6], Vector3.Right, textureCorners[2]);
  453.                 //---------------------------------------
  454.             }
  455.  
  456.             else if (side.Name == BoxSideName.Left)
  457.             {
  458.                 // LEFT OF THE BOX
  459.                 //---------------------------------------
  460.                 textureCorners = DetermineTextureCoords(Left);
  461.                 // Top left corner
  462.                 verts[20] = new VertexPositionNormalTexture(
  463.                     corners[4], Vector3.Left, textureCorners[0]);
  464.  
  465.                 // Top right corner
  466.                 verts[21] = new VertexPositionNormalTexture(
  467.                     corners[0], Vector3.Left, textureCorners[1]);
  468.  
  469.                 // Bottom left corner
  470.                 verts[22] = new VertexPositionNormalTexture(
  471.                     corners[7], Vector3.Left, textureCorners[3]);
  472.  
  473.                 // Bottom right corner
  474.                 verts[23] = new VertexPositionNormalTexture(
  475.                     corners[3], Vector3.Left, textureCorners[2]);
  476.                 //---------------------------------------
  477.             }
  478.         }
  479.  
  480.         /// <summary>
  481.         /// Gets the corner positions of the box.
  482.         /// </summary>
  483.         /// <returns>An array holding the corner positions of the box.</returns>
  484.         private Vector3[] GetCorners()
  485.         {
  486.             // The corner positions will be centered around the world origin.
  487.             // Any transformations needed can be applied in the world matrix when it's time to draw.
  488.             float maxX = this.HalfLength;
  489.             float minX = -maxX;
  490.             float maxY = this.HalfHeight;
  491.             float minY = -maxY;
  492.             float maxZ = this.HalfWidth;
  493.             float minZ = -maxZ;
  494.  
  495.             // Now we need to set up the array that will hold the positions of the corners.
  496.             // This array is ordered like in the MSDN samples:
  497.             //     ZMax    ZMin
  498.             //    0----1  4----5
  499.             //    |    |  |    |
  500.             //    |    |  |    |
  501.             //    3----2  7----6
  502.             Vector3[] corners = new Vector3[]
  503.             {
  504.                 new Vector3(minX, maxY, maxZ),
  505.                 new Vector3(maxX, maxY, maxZ),
  506.                 new Vector3(maxX, minY, maxZ),
  507.                 new Vector3(minX, minY, maxZ),
  508.  
  509.                 new Vector3(minX, maxY, minZ),
  510.                 new Vector3(maxX, maxY, minZ),
  511.                 new Vector3(maxX, minY, minZ),
  512.                 new Vector3(minX, minY, minZ)
  513.             };
  514.             return corners;
  515.         }
  516.  
  517.         /// <summary>
  518.         /// Draws the box.
  519.         /// </summary>
  520.         /// <param name="view">The camera's view matrix.</param>
  521.         /// <param name="projection">The camera's projection matrix.</param>
  522.         public void Draw(Matrix view, Matrix projection)        
  523.         {
  524.             // The box is currently centered at the origin.
  525.             // The world matrix will transform it to the correct position and orientation.
  526.             Matrix world = Matrix.Identity;
  527.             world *= Matrix.CreateFromQuaternion(this.Orientation);
  528.             world *= Matrix.CreateTranslation(this.Position);
  529.  
  530.             // Set the values for the WVP matrices.
  531.             effect.World = world;
  532.             effect.View = view;
  533.             effect.Projection = projection;
  534.  
  535.             // Now draw the box.
  536.             foreach (EffectPass pass in effect.CurrentTechnique.Passes)
  537.             {
  538.                 // To account for different textures on each side of the box,
  539.                 // We need to set the effect's texture and reapply the pass before drawing
  540.                 // each side.
  541.  
  542.                 // Top
  543.                 effect.Texture = Top.Texture;
  544.                 pass.Apply();            
  545.                 graphicsDevice.DrawUserIndexedPrimitives<VertexPositionNormalTexture>(PrimitiveType.TriangleList,
  546.                     verts, 0, verts.Length, indices, 0, 2);
  547.  
  548.                 // Bottom
  549.                 effect.Texture = Bottom.Texture;
  550.                 pass.Apply();
  551.                 graphicsDevice.DrawUserIndexedPrimitives<VertexPositionNormalTexture>(PrimitiveType.TriangleList,
  552.                     verts, 0, verts.Length, indices, 6, 2);
  553.  
  554.                 // Front
  555.                 effect.Texture = Front.Texture;
  556.                 pass.Apply();
  557.                 graphicsDevice.DrawUserIndexedPrimitives<VertexPositionNormalTexture>(PrimitiveType.TriangleList,
  558.                     verts, 0, verts.Length, indices, 12, 2);
  559.  
  560.                 // Back
  561.                 effect.Texture = Back.Texture;
  562.                 pass.Apply();
  563.                 graphicsDevice.DrawUserIndexedPrimitives<VertexPositionNormalTexture>(PrimitiveType.TriangleList,
  564.                     verts, 0, verts.Length, indices, 18, 2);
  565.                
  566.                 // Right
  567.                 effect.Texture = Right.Texture;
  568.                 pass.Apply();
  569.                 graphicsDevice.DrawUserIndexedPrimitives<VertexPositionNormalTexture>(PrimitiveType.TriangleList,
  570.                     verts, 0, verts.Length, indices, 24, 2);
  571.  
  572.                 // Left
  573.                 effect.Texture = Left.Texture;
  574.                 pass.Apply();
  575.                 graphicsDevice.DrawUserIndexedPrimitives<VertexPositionNormalTexture>(PrimitiveType.TriangleList,
  576.                     verts, 0, verts.Length, indices, 30, 2);
  577.  
  578.             }
  579.         }
  580.  
  581.         /// <summary>
  582.         /// Sets all the textures on the sides of the box to the given texture.
  583.         /// </summary>
  584.         /// <param name="texture">The texture to be applied to the sides of the box.</param>
  585.         public void SetAllTextures(Texture2D texture)
  586.         {
  587.             Top.Texture = texture;
  588.             Bottom.Texture = texture;
  589.             Front.Texture = texture;
  590.             Back.Texture = texture;
  591.             Right.Texture = texture;
  592.             Left.Texture = texture;
  593.         }
  594.  
  595.         /// <summary>
  596.         /// Gets the texture coordinates for the side of a box.
  597.         /// </summary>
  598.         /// <param name="side">The side to get texture coordinates from.</param>
  599.         /// <returns>An array holding the 4 texture coordinates of the box from the top left coordinate
  600.         ///  in clockwise order.</returns>
  601.         private Vector2[] DetermineTextureCoords(BoxSide side)
  602.         {
  603.             // Create the 4 Vector2's that will hold each corner's texture coordinate.
  604.             Vector2 topLeft, topRight, bottomLeft, bottomRight;
  605.  
  606.             // Do this if only a horizontal flipping is needed.
  607.             if (side.FlipTextureHorizontal && !side.FlipTextureVertical)
  608.             {
  609.                 topLeft = new Vector2(1f, 0f);
  610.                 topRight = Vector2.Zero;
  611.                 bottomLeft = Vector2.One;
  612.                 bottomRight = new Vector2(0f, 1f);
  613.             }
  614.  
  615.             // Do this if only a vertical flipping is needed.
  616.             else if (side.FlipTextureVertical && !side.FlipTextureHorizontal)
  617.             {
  618.                 topLeft = new Vector2(0f, 1f);
  619.                 topRight = Vector2.One;
  620.                 bottomLeft = Vector2.Zero;
  621.                 bottomRight = new Vector2(1f, 0f);
  622.             }
  623.  
  624.             // Do this if both a horizontal and vertical flipping are needed.
  625.             else if (side.FlipTextureHorizontal && side.FlipTextureVertical)
  626.             {
  627.                 topLeft = Vector2.One;
  628.                 topRight = new Vector2(0f, 1f);
  629.                 bottomLeft = new Vector2(1f, 0f);
  630.                 bottomRight = Vector2.Zero;
  631.             }
  632.  
  633.             // If we've come to here, then no flipping was needed at all.
  634.             // Just set the default texture coordinates.
  635.             else
  636.             {
  637.                 topLeft = Vector2.Zero;
  638.                 topRight = new Vector2(1f, 0f);
  639.                 bottomLeft = new Vector2(0f, 1f);
  640.                 bottomRight = Vector2.One;
  641.             }
  642.  
  643.             return new Vector2[]
  644.             {
  645.                 topLeft,
  646.                 topRight,
  647.                 bottomRight,
  648.                 bottomLeft
  649.             };
  650.         }
  651.  
  652.        
  653.     }
  654. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement