Exemple #1
0
        public static MeshObject Tetrahedron(Vector3 position, float radius, AsciiTexture texture)
        {
            List <Triangle> triangles = new List <Triangle>();

            float sqrt2 = (float)Math.Sqrt(2);
            float sqrt3 = (float)Math.Sqrt(3);

            Vector3 up = radius * Vector3.Up;
            Vector3 v0 = radius * new Vector3(0f, -1f / 3f, 2f * sqrt2 / 3f);
            Vector3 v1 = radius * new Vector3(-sqrt2 / sqrt3, -1f / 3f, 1 - sqrt2);
            Vector3 v2 = radius * new Vector3(sqrt2 / sqrt3, -1f / 3f, 1 - sqrt2);

            Vector2 uv0   = new Vector2(0.5f, 0f);
            Vector2 uv1   = new Vector2(0.25f, 0.25f * sqrt3);
            Vector2 uv2   = new Vector2(0.75f, 0.25f * sqrt3);
            Vector2 uvup0 = new Vector2(0.5f, 0.5f * sqrt3);
            Vector2 uvup1 = new Vector2(1f, 0f);
            Vector2 uvup2 = new Vector2(0f, 0f);

            triangles.Add(new Triangle(v0, v1, v2, texture, uv0, uv1, uv2));
            triangles.Add(new Triangle(up, v0, v2, texture, uvup1, uv0, uv2));
            triangles.Add(new Triangle(up, v1, v0, texture, uvup2, uv1, uv0));
            triangles.Add(new Triangle(up, v2, v1, texture, uvup0, uv2, uv1));

            return(new MeshObject(triangles, position, 0f));
        }
Exemple #2
0
        // More reflection hacks -- starting to feel bad about it xD
        public static void LoadAssets(ContentManager content)
        {
            // Gather all Assets fields
            FieldInfo[] fields         = typeof(Assets).GetFields();
            MethodInfo  loadMethodInfo = content.GetType().GetMethod("Load"); // Content.Load method

            foreach (FieldInfo field in fields)
            {
                string path = field.GetCustomAttribute <AssetPathAttribute>().Path;
                Type   type = field.FieldType;
                if (type == typeof(AsciiTexture))
                {
                    type = typeof(Texture2D);
                }

                // Execute Content.Load with appropriate generic argument
                object result = loadMethodInfo.MakeGenericMethod(type).Invoke(content, new object[] { path });
                if (field.FieldType == typeof(AsciiTexture))
                {
                    result = new AsciiTexture((Texture2D)result);
                }

                field.SetValue(path, result);
            }
        }
 public Triangle(Vector3 v0, Vector3 v1, Vector3 v2, AsciiTexture texture, Vector2 uv0, Vector2 uv1, Vector2 uv2)
 {
     V0      = v0;
     V1      = v1;
     V2      = v2;
     UV0     = uv0;
     UV1     = uv1;
     UV2     = uv2;
     Texture = texture;
     Normal  = Vector3.Cross(v1 - v0, v2 - v0);
 }
Exemple #4
0
 public MeshObject(OBJFile objFile, AsciiTexture texture, Vector3 position)
 {
     Position  = position;
     triangles = new List <Triangle>();
     for (int i = 0; i < objFile.triangleVertices.Length; i += 3)
     {
         Vector3 v0  = objFile.vertices[objFile.triangleVertices[i]];
         Vector3 v1  = objFile.vertices[objFile.triangleVertices[i + 1]];
         Vector3 v2  = objFile.vertices[objFile.triangleVertices[i + 2]];
         Vector2 uv0 = objFile.texcoords[objFile.triangleTexcoords[i]];
         Vector2 uv1 = objFile.texcoords[objFile.triangleTexcoords[i + 1]];
         Vector2 uv2 = objFile.texcoords[objFile.triangleTexcoords[i + 2]];
         triangles.Add(new Triangle(v0, v1, v2, texture, uv0, uv1, uv2));
     }
 }
        public static Triangle Load(BinaryReader reader)
        {
            Vector3 v0 = GameSave.ReadVector3(reader);
            Vector3 v1 = GameSave.ReadVector3(reader);
            Vector3 v2 = GameSave.ReadVector3(reader);

            Vector2 uv0 = GameSave.ReadVector2(reader);
            Vector2 uv1 = GameSave.ReadVector2(reader);
            Vector2 uv2 = GameSave.ReadVector2(reader);

            Vector3 normal = GameSave.ReadVector3(reader);

            int id = reader.ReadInt32();

            return(new Triangle(v0, v1, v2, AsciiTexture.GetByID(id), uv0, uv1, uv2));
        }
Exemple #6
0
        public static MeshObject Octahedron(Vector3 position, float radius, AsciiTexture texture)
        {
            List <Triangle> triangles = new List <Triangle>();

            Vector3 f = radius * Vector3.Forward;
            Vector3 b = radius * Vector3.Backward;
            Vector3 l = radius * Vector3.Left;
            Vector3 r = radius * Vector3.Right;
            Vector3 u = radius * Vector3.Up;
            Vector3 d = radius * Vector3.Down;

            triangles.Add(new Triangle(r, f, u, texture, new Vector2(1f, 0.5f), new Vector2(0.5f, 0f), new Vector2(0.5f, 0.5f)));
            triangles.Add(new Triangle(b, r, u, texture, new Vector2(0.5f, 1f), new Vector2(1f, 0.5f), new Vector2(0.5f, 0.5f)));
            triangles.Add(new Triangle(l, b, u, texture, new Vector2(0f, 0.5f), new Vector2(0.5f, 1f), new Vector2(0.5f, 0.5f)));
            triangles.Add(new Triangle(f, l, u, texture, new Vector2(0.5f, 0f), new Vector2(0f, 0.5f), new Vector2(0.5f, 0.5f)));

            triangles.Add(new Triangle(f, r, d, texture, new Vector2(0.5f, 0f), new Vector2(1f, 0.5f), new Vector2(0.5f, 0.5f)));
            triangles.Add(new Triangle(r, b, d, texture, new Vector2(1f, 0.5f), new Vector2(0.5f, 1f), new Vector2(0.5f, 0.5f)));
            triangles.Add(new Triangle(b, l, d, texture, new Vector2(0.5f, 1f), new Vector2(0f, 0.5f), new Vector2(0.5f, 0.5f)));
            triangles.Add(new Triangle(l, f, d, texture, new Vector2(0f, 0.5f), new Vector2(0.5f, 0f), new Vector2(0.5f, 0.5f)));

            return(new MeshObject(triangles, position, 0f));
        }
 public Triangle(Vector3 v0, Vector3 v1, Vector3 v2, AsciiTexture texture) : this(v0, v1, v2, texture, Vector2.Zero, Vector2.Zero, Vector2.Zero)
 {
 }
 private static void Register(AsciiTexture asciiTexture)
 {
     asciiTexture.ID = textures.Count;
     textures.Add(asciiTexture);
 }