Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Graphics;
- using StarsGame.Universe_Objects.Planets;
- namespace StarsGame
- {
- public class Quad
- {
- public PlanetGeometry.FACING_DIRECTION FaceName;
- private Triangle[] triangles;
- public Triangle[] Triangles
- {
- get { return triangles; }
- }
- private VertexPositionNormalTexture[] corners;
- public VertexPositionNormalTexture[] Corners
- {
- get { return corners; }
- set { corners = value; }
- }
- private VertexPositionNormalColor[] colorCorners;
- public VertexPositionNormalColor[] ColorCorners
- {
- get { return colorCorners; }
- set { colorCorners = value; }
- }
- public Quad(VertexPositionNormalTexture[] corners, PlanetGeometry.FACING_DIRECTION faceName)
- {
- this.corners = corners;
- triangles = CreateTriangles();
- this.FaceName = faceName;
- //calc normal from face name
- GenerateNormal();
- }
- public Quad()
- {
- }
- private Triangle[] CreateTriangles()
- {
- Triangle tri1 = new Triangle(
- new int[3] { 0, 1, 3 }); //top left, bottom right, bottom left
- Triangle tri2 = new Triangle(
- new int[3] { 1, 2, 3 }); //top right, bottom right, bottom left
- return new Triangle[2] { tri1, tri2 };
- }
- public Vector3[] GetCornerPositions()
- {
- Vector3[] positions = new Vector3[4];
- for (int p = 0; p < 4; p++)
- {
- positions[p] = corners[p].Position;
- }
- return positions;
- }
- public void CreateColorCorners(Color color)
- {
- colorCorners = new VertexPositionNormalColor[4];
- for (int c = 0; c < 4; c++)
- {
- colorCorners[c] = new VertexPositionNormalColor(corners[c].Position, color, corners[c].Normal);
- }
- }
- public bool CorrectTriangles(Vector3 centerOfBlock)
- {
- bool a = triangles[0].CheckIndices(this, centerOfBlock, FaceName);
- bool b = triangles[1].CheckIndices(this, centerOfBlock, FaceName);
- if (!(a && b))
- {
- CreateColorCorners(Color.Red);
- return false;
- }
- else
- {
- return true;
- }
- }
- private void GenerateNormal()
- {
- Vector3[] cornerPositions = GetCornerPositions();
- Vector3 a = cornerPositions[2] - cornerPositions[0];
- Vector3 b = cornerPositions[2] - cornerPositions[1];
- Vector3 normal = Vector3.Cross(a, b);
- for (int v = 0; v < corners.Length; v++)
- {
- corners[v].Normal = normal;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement