-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAssets.cs
129 lines (101 loc) · 5.93 KB
/
Assets.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SharpDX;
using SharpDX.Toolkit;
namespace Project1
{
using SharpDX.Toolkit.Graphics;
public class Assets
{
Project1Game game;
public Assets(Project1Game game)
{
this.game = game;
}
// Dictionary of currently loaded models.
// New/existing models are loaded by calling GetModel(modelName, modelMaker).
public Dictionary<String, MyModel> modelDict = new Dictionary<String, MyModel>();
// Load a model from the model dictionary.
// If the model name hasn't been loaded before then modelMaker will be called to generate the model.
public delegate MyModel ModelMaker();
public MyModel GetModel(String modelName, ModelMaker modelMaker)
{
if (!modelDict.ContainsKey(modelName))
{
modelDict[modelName] = modelMaker();
}
return modelDict[modelName];
}
// Create a cube with one texture for all faces.
public MyModel CreateTexturedCube(String textureName, float size)
{
return CreateTexturedCube(textureName, new Vector3(size, size, size));
}
public VertexPositionColor[] CreateColoredTriangle(Vector3 size, Color color)
{
VertexPositionColor[] shapeArray = new VertexPositionColor[]{
new VertexPositionColor(new Vector3(-1.0f, -1.0f, -1.0f), color), // Front
new VertexPositionColor(new Vector3(1.0f, 1.0f, -1.0f), color),
new VertexPositionColor(new Vector3(-1.0f, 1.0f, -1.0f),color)
};
for (int i = 0; i < shapeArray.Length; i++)
{
shapeArray[i].Position.X *= size.X / 2;
shapeArray[i].Position.Y *= size.Y / 2;
shapeArray[i].Position.Z *= size.Z / 2;
}
return shapeArray;
}
public MyModel CreateTexturedCube(String texturePath, Vector3 size)
{
VertexPositionTexture[] shapeArray = new VertexPositionTexture[]{
new VertexPositionTexture(new Vector3(-1.0f, -1.0f, -1.0f), new Vector2(1f, 2/3f)), // Front
new VertexPositionTexture(new Vector3(1.0f, 1.0f, -1.0f), new Vector2(3/4f, 1/3f)),
new VertexPositionTexture(new Vector3(-1.0f, 1.0f, -1.0f), new Vector2(1f, 1/3f)),
new VertexPositionTexture(new Vector3(-1.0f, -1.0f, -1.0f), new Vector2(1f, 2/3f)),
new VertexPositionTexture(new Vector3(1.0f, -1.0f, -1.0f), new Vector2(3/4f, 2/3f)),
new VertexPositionTexture(new Vector3(1.0f, 1.0f, -1.0f), new Vector2(3/4f, 1/3f)),
new VertexPositionTexture(new Vector3(-1.0f, -1.0f, 1.0f), new Vector2(1/4f, 2/3f)), // BACK
new VertexPositionTexture(new Vector3(-1.0f, 1.0f, 1.0f), new Vector2(1/4f, 1/3f)),
new VertexPositionTexture(new Vector3(1.0f, 1.0f, 1.0f), new Vector2(2/4f, 1/3f)),
new VertexPositionTexture(new Vector3(-1.0f, -1.0f, 1.0f), new Vector2(1/4f, 2/3f)),
new VertexPositionTexture(new Vector3(1.0f, 1.0f, 1.0f), new Vector2(2/4f, 1/3f)),
new VertexPositionTexture(new Vector3(1.0f, -1.0f, 1.0f), new Vector2(2/4f, 2/3f)),
new VertexPositionTexture(new Vector3(-1.0f, 1.0f, -1.0f), new Vector2(1/4f, 0.0f)), // Top
new VertexPositionTexture(new Vector3(1.0f, 1.0f, 1.0f), new Vector2(2/4f, 1/3f)),
new VertexPositionTexture(new Vector3(-1.0f, 1.0f, 1.0f), new Vector2(1/4f, 1/3f)),
new VertexPositionTexture(new Vector3(-1.0f, 1.0f, -1.0f), new Vector2(1/4f, 1/3f)),
new VertexPositionTexture(new Vector3(1.0f, 1.0f, -1.0f), new Vector2(2/4f, 1/3f)),
new VertexPositionTexture(new Vector3(1.0f, 1.0f, 1.0f), new Vector2(2/4f, 0.0f)),
new VertexPositionTexture(new Vector3(-1.0f, -1.0f, -1.0f), new Vector2(1/4f, 1.0f)), // Bottom
new VertexPositionTexture(new Vector3(-1.0f, -1.0f, 1.0f), new Vector2(1/4f, 2/3f)),
new VertexPositionTexture(new Vector3(1.0f, -1.0f, 1.0f), new Vector2(2/4f, 2/3f)),
new VertexPositionTexture(new Vector3(-1.0f, -1.0f, -1.0f), new Vector2(1/4f, 1.0f)),
new VertexPositionTexture(new Vector3(1.0f, -1.0f, 1.0f), new Vector2(2/4f, 2/3f)),
new VertexPositionTexture(new Vector3(1.0f, -1.0f, -1.0f), new Vector2(2/4f, 1.0f)),
new VertexPositionTexture(new Vector3(-1.0f, -1.0f, -1.0f), new Vector2(0.0f, 2/3f)), // Left
new VertexPositionTexture(new Vector3(-1.0f, 1.0f, 1.0f), new Vector2(1/4f, 1/3f)),
new VertexPositionTexture(new Vector3(-1.0f, -1.0f, 1.0f), new Vector2(1/4f, 2/3f)),
new VertexPositionTexture(new Vector3(-1.0f, -1.0f, -1.0f), new Vector2(0.0f, 2/3f)),
new VertexPositionTexture(new Vector3(-1.0f, 1.0f, -1.0f), new Vector2(0.0f, 1/3f)),
new VertexPositionTexture(new Vector3(-1.0f, 1.0f, 1.0f), new Vector2(1/4f, 1/3f)),
new VertexPositionTexture(new Vector3(1.0f, -1.0f, -1.0f), new Vector2(3/4f, 2/3f)), // Right
new VertexPositionTexture(new Vector3(1.0f, -1.0f, 1.0f), new Vector2(2/4f, 2/3f)),
new VertexPositionTexture(new Vector3(1.0f, 1.0f, 1.0f), new Vector2(2/4f, 1/3f)),
new VertexPositionTexture(new Vector3(1.0f, -1.0f, -1.0f), new Vector2(3/4f, 2/3f)),
new VertexPositionTexture(new Vector3(1.0f, 1.0f, 1.0f), new Vector2(2/4f, 1/3f)),
new VertexPositionTexture(new Vector3(1.0f, 1.0f, -1.0f), new Vector2(3/4f, 1/3f)),
};
for (int i = 0; i < shapeArray.Length; i++)
{
shapeArray[i].Position.X *= size.X / 2;
shapeArray[i].Position.Y *= size.Y / 2;
shapeArray[i].Position.Z *= size.Z / 2;
}
return new MyModel(game, shapeArray, texturePath);
}
}
}