本文整理汇总了C#中Microsoft.Xna.Framework.Graphics.VertexPositionNormalTexture类的典型用法代码示例。如果您正苦于以下问题:C# VertexPositionNormalTexture类的具体用法?C# VertexPositionNormalTexture怎么用?C# VertexPositionNormalTexture使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
VertexPositionNormalTexture类属于Microsoft.Xna.Framework.Graphics命名空间,在下文中一共展示了VertexPositionNormalTexture类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetShapeMeshData
public static void GetShapeMeshData(EntityCollidable collidable, List<VertexPositionNormalTexture> vertices, List<ushort> indices)
{
var convexHullShape = collidable.Shape as ConvexHullShape;
if (convexHullShape == null)
throw new ArgumentException("Wrong shape type.");
var hullTriangleVertices = new List<Vector3>();
var hullTriangleIndices = new List<int>();
Toolbox.GetConvexHull(convexHullShape.Vertices, hullTriangleIndices, hullTriangleVertices);
//The hull triangle vertices are used as a dummy to get the unnecessary hull vertices, which are cleared afterwards.
hullTriangleVertices.Clear();
foreach (int i in hullTriangleIndices)
{
hullTriangleVertices.Add(convexHullShape.Vertices[i]);
}
var toReturn = new VertexPositionNormalTexture[hullTriangleVertices.Count];
Vector3 normal;
for (ushort i = 0; i < hullTriangleVertices.Count; i += 3)
{
normal = Vector3.Normalize(Vector3.Cross(hullTriangleVertices[i + 2] - hullTriangleVertices[i], hullTriangleVertices[i + 1] - hullTriangleVertices[i]));
vertices.Add(new VertexPositionNormalTexture(hullTriangleVertices[i], normal, new Vector2(0, 0)));
vertices.Add(new VertexPositionNormalTexture(hullTriangleVertices[i + 1], normal, new Vector2(1, 0)));
vertices.Add(new VertexPositionNormalTexture(hullTriangleVertices[i + 2], normal, new Vector2(0, 1)));
indices.Add(i);
indices.Add((ushort)(i + 1));
indices.Add((ushort)(i + 2));
}
}
示例2: Plane
/// <summary>
/// Constructor to generate the plane geometry
/// </summary>
/// <param name="segments">The number of rows/columns</param>
public Plane(int segments = 1)
{
int rowCount = segments + 1;
float fSegments = segments;
// Initialize the arrays
Indices = new int[6 * segments * segments];
Vertices = new VertexPositionNormalTexture[(rowCount) * (rowCount)];
// Populate the vertices
for(int i = 0; i <= segments; i++)
for (int j = 0; j <= segments; j++)
{
Vertices[i * rowCount + j] = new VertexPositionNormalTexture(
new Vector3(-1 + 2 * j / fSegments, 0, -1 + 2 * i / fSegments), // Position
Vector3.Up, // Normal
new Vector2(j / fSegments, i / fSegments)); // Texture
}
// Populate the indices
int index = 0;
for(int i = 0; i < segments; i++)
for (int j = 0; j < segments; j++)
{
Indices[index++] = i * rowCount + j;
Indices[index++] = i * rowCount + j + 1;
Indices[index++] = (i + 1) * rowCount + j + 1;
Indices[index++] = i * rowCount + j;
Indices[index++] = (i + 1) * rowCount + j + 1;
Indices[index++] = (i + 1) * rowCount + j;
}
}
示例3: GenerateStructures
public void GenerateStructures()
{
vertices = new VertexPositionNormalTexture[(dimension + 1) * (dimension + 1)];
indices = new int[dimension * dimension * 6];
for (int i = 0; i < dimension + 1; i++)
{
for (int j = 0; j < dimension + 1; j++)
{
VertexPositionNormalTexture vert = new VertexPositionNormalTexture();
vert.Position = new Vector3((i - dimension / 2.0f) * cellSize, 0, (j - dimension / 2.0f) * cellSize);
vert.Normal = Vector3.Up;
vert.TextureCoordinate = new Vector2((float)i / dimension, (float)j / dimension);
vertices[i * (dimension + 1) + j] = vert;
}
}
for (int i = 0; i < dimension; i++)
{
for (int j = 0; j < dimension; j++)
{
indices[6 * (i * dimension + j)] = (i * (dimension + 1) + j);
indices[6 * (i * dimension + j) + 1] = (i * (dimension + 1) + j + 1);
indices[6 * (i * dimension + j) + 2] = ((i + 1) * (dimension + 1) + j + 1);
indices[6 * (i * dimension + j) + 3] = (i * (dimension + 1) + j);
indices[6 * (i * dimension + j) + 4] = ((i + 1) * (dimension + 1) + j + 1);
indices[6 * (i * dimension + j) + 5] = ((i + 1) * (dimension + 1) + j);
}
}
}
示例4: Clouds
public Clouds(Vector2 orbit)
{
var size = new Vector2(9192, 4096);
billboardVertices = new VertexPositionNormalTexture[6];
Vector3 e = new Vector3(-size.X / 2, size.Y, 0);
Vector3 f = new Vector3(size.X / 2, size.Y, 0);
Vector3 g = new Vector3(size.X / 2, 0, 0);
Vector3 h = new Vector3(-size.X / 2, 0, 0);
Vector3 frontNormal = new Vector3(0.0f, 0.0f, 1.0f);
billboardVertices[0] = new VertexPositionNormalTexture(h, frontNormal, new Vector2(0, 1));
billboardVertices[1] = new VertexPositionNormalTexture(e, frontNormal, new Vector2(0, 0));
billboardVertices[2] = new VertexPositionNormalTexture(f, frontNormal, new Vector2(1, 0));
billboardVertices[3] = new VertexPositionNormalTexture(h, frontNormal, new Vector2(0, 1));
billboardVertices[4] = new VertexPositionNormalTexture(f, frontNormal, new Vector2(1, 0));
billboardVertices[5] = new VertexPositionNormalTexture(g, frontNormal, new Vector2(1, 1));
offsetA = new Vector3(-orbit.X * 4, 0, -orbit.Y * 4);
offsetB = new Vector3(-orbit.X * 3, 0, -orbit.Y * 3);
offsetC = new Vector3(-orbit.X * 5f, 0, -orbit.Y * 5f);
orbitA = new Vector3(orbit.X, 256, orbit.Y);
orbitB = new Vector3(orbit.X, 5120, orbit.Y);
orbitC = new Vector3(orbit.X, 2048, orbit.Y);
degreesA = G.r.Next(360);
degreesB = G.r.Next(360);
degreesC = G.r.Next(360);
CloudA = RM.GetTexture("cloud1");
CloudB = RM.GetTexture("cloud2");
CloudC = RM.GetTexture("cloud3");
}
示例5: BuildBoundingBox
//See https://electronicmeteor.wordpress.com/2011/10/25/bounding-boxes-for-your-model-meshes/
public static BoundingBox BuildBoundingBox(ModelMesh mesh, Matrix meshTransform)
{
// Create initial variables to hold min and max xyz values for the mesh
Vector3 meshMax = new Vector3(float.MinValue);
Vector3 meshMin = new Vector3(float.MaxValue);
foreach (ModelMeshPart part in mesh.MeshParts)
{
// The stride is how big, in bytes, one vertex is in the vertex buffer
// We have to use this as we do not know the make up of the vertex
int stride = part.VertexBuffer.VertexDeclaration.VertexStride;
VertexPositionNormalTexture[] vertexData = new VertexPositionNormalTexture[part.NumVertices];
part.VertexBuffer.GetData(part.VertexOffset * stride, vertexData, 0, part.NumVertices, stride);
// Find minimum and maximum xyz values for this mesh part
Vector3 vertPosition = new Vector3();
for (int i = 0; i < vertexData.Length; i++)
{
vertPosition = vertexData[i].Position;
// update our values from this vertex
meshMin = Vector3.Min(meshMin, vertPosition);
meshMax = Vector3.Max(meshMax, vertPosition);
}
}
// transform by mesh bone matrix
meshMin = Vector3.Transform(meshMin, meshTransform);
meshMax = Vector3.Transform(meshMax, meshTransform);
// Create the bounding box
return new BoundingBox(meshMin, meshMax);
}
示例6: drawSquarre
public void drawSquarre(VertexPositionNormalTexture[] vertexData, int[] indexData, Camera came, BasicEffect effect, GraphicsDevice graphicsDevice)
{
Texture2D texture = Tools.Quick.groundTexture[BiomeType.SubtropicalDesert];
effect.Projection = projectionMatrix;
effect.Texture = texture;
effect.TextureEnabled = true; ;
graphicsDevice.RasterizerState = WIREFRAME_RASTERIZER_STATE; // draw in wireframe
graphicsDevice.BlendState = BlendState.Opaque; // no alpha this time
// effect.DiffuseColor = Color.Red.ToVector3();
effect.CurrentTechnique.Passes[0].Apply();
effect.View = came.getview();
effect.CurrentTechnique.Passes[0].Apply();
graphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, vertexData, 0, 4, indexData, 0, 2);
/* // Draw wireframe box
graphicsDevice.RasterizerState = WIREFRAME_RASTERIZER_STATE; // draw in wireframe
graphicsDevice.BlendState = BlendState.Opaque; // no alpha this time
effect.TextureEnabled = false;
// effect.DiffuseColor = Color.Black.ToVector3();
effect.CurrentTechnique.Passes[0].Apply();
graphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, vertexData, 0, 4, indexData, 0, 2);
*/
}
示例7: CreateShape
public void CreateShape()
{
double angle = MathHelper.TwoPi / CIRCLE_NUM_POINTS;
_vertices = new VertexPositionNormalTexture[CIRCLE_NUM_POINTS + 1];
_vertices[0] = new VertexPositionNormalTexture(
Vector3.Zero, Vector3.Forward, Vector2.One);
for (int i = 1; i <= CIRCLE_NUM_POINTS; i++)
{
float x = (float)Math.Round(Math.Sin(angle * i), 4);
float y = (float)Math.Round(Math.Cos(angle * i), 4);
Vector3 point = new Vector3(
x,
y,
0.0f);
_vertices[i] = new VertexPositionNormalTexture(
point,
Vector3.Forward,
new Vector2());
}
buffer = new VertexBuffer(graphicsDevice, typeof(VertexPositionNormalTexture), _vertices.Length,
BufferUsage.None);
// Set the vertex buffer data to the array of vertices
buffer.SetData<VertexPositionNormalTexture>(_vertices);
InitializeLineStrip();
}
示例8: Bullet
public Bullet(Game game)
: base(game)
{
vertex = new VertexPositionNormalTexture[12];
// Base
vertex[0] = new VertexPositionNormalTexture(new Vector3(-2.0f, 0.0f, -2.0f), BottomNormal, new Vector2(0.0f, 1.0f));
vertex[1] = new VertexPositionNormalTexture(new Vector3(2.0f, 0.0f, -2.0f), BottomNormal, new Vector2(1.0f, 1.0f));
vertex[2] = new VertexPositionNormalTexture(new Vector3(2.0f, 0.0f, 2.0f), BottomNormal, new Vector2(1.0f, 0.0f));
vertex[3] = new VertexPositionNormalTexture(new Vector3(-2.0f, 0.0f, 2.0f), BottomNormal, new Vector2(0.0f, 0.0f));
// Face 1 and 2
vertex[4] = new VertexPositionNormalTexture(new Vector3(0.0f, 3.0f, 0.0f), TopNormal, new Vector2(0.0f, 0.0f));
vertex[5] = new VertexPositionNormalTexture(new Vector3(2.0f, 0.0f, -2.0f), new Vector3(1, 0, -1), new Vector2(1.0f, 1.0f));
vertex[6] = new VertexPositionNormalTexture(new Vector3(2.0f, 0.0f, 2.0f), new Vector3(1, 0, 1), new Vector2(0.5f, 1.0f));
vertex[7] = new VertexPositionNormalTexture(new Vector3(-2.0f, 0.0f, 2.0f), new Vector3(-1, 0, 1), new Vector2(0.0f, 1.0f));
// Face 3 and 4
vertex[8] = new VertexPositionNormalTexture(new Vector3(0.0f, 3.0f, 0.0f), TopNormal, new Vector2(0.0f, 0.0f));
vertex[9] = new VertexPositionNormalTexture(new Vector3(-2.0f, 0.0f, 2.0f), new Vector3(-1, 0, 1), new Vector2(1.0f, 1.0f));
vertex[10] = new VertexPositionNormalTexture(new Vector3(-2.0f, 0.0f, -2.0f), new Vector3(-1, 0, -1), new Vector2(0.5f, 1.0f));
vertex[11] = new VertexPositionNormalTexture(new Vector3(2.0f, 0.0f, -2.0f), new Vector3(1, 0, -1), new Vector2(0.0f, 1.0f));
triangleListIndices = new short[18] { 0, 2, 1,
0, 3, 2,
4, 5, 6,
4, 6, 7,
8, 9, 10,
8, 10, 11
};
texture_metal = game.Content.Load<Texture2D>("metal3");
}
示例9: CreateVertexBuffer
void CreateVertexBuffer()
{
VertexPositionNormalTexture[] vertices = new VertexPositionNormalTexture[number_of_vertices];
float halfWidth = (number_of_cols - 1) * 0.5f;
float halfDepth = (number_of_rows - 1) * 0.5f;
float du = 1.0f / (number_of_cols - 1);
float dv = 1.0f / (number_of_rows - 1);
for (int i = 0; i < number_of_rows; ++i)
{
float z = halfDepth - i;
for (int j = 0; j < number_of_cols;++j)
{
float x = -halfWidth + j;
float y = getHeight(x, z);
vertices[i * number_of_cols + j].Position = new Vector3(x, y, z);
vertices[i * number_of_cols + j].TextureCoordinate = new Vector2(j * du, i * dv);
Vector3 normal = new Vector3();
normal.X = -0.03f * z * (float)Math.Cos(0.1f * x) - 0.3f * (float)Math.Cos(0.1f * z);
normal.Y = 1;
normal.Z = -0.3f * (float)Math.Sin(0.1f * x) + 0.03f * x *(float)Math.Sin(0.1f * z);
normal.Normalize();
vertices[i * number_of_cols + j].Normal = normal;
}
}
vertexBuffer = new VertexBuffer(GraphicsDevice, VertexPositionNormalTexture.VertexDeclaration, number_of_vertices, BufferUsage.WriteOnly);
vertexBuffer.SetData<VertexPositionNormalTexture>(vertices);
}
示例10: StartDrawing
private unsafe void StartDrawing(VertexFragment vertexFragment, out VertexPositionColor* vertices, out VertexPositionNormalTexture* textures, out short* indices, out short baseIndex)
{
textures = null;
if (vertexFragment.PrimitiveType == PrimitiveType.LineList)
{
if ((this.SortMode == DrawingSortMode.Order) && (this._triangleVertexCount > 0))
{
Flush();
StartLineDrawing(vertexFragment, out vertices, out indices, out baseIndex);
}
else
{
StartLineDrawing(vertexFragment, out vertices, out indices, out baseIndex);
}
}
else if (vertexFragment.PrimitiveType == PrimitiveType.TriangleList)
{
if ((this.SortMode == DrawingSortMode.Order) && (this._lineVertexCount > 0))
{
Flush();
StartTriangleDrawing(vertexFragment, out vertices, out textures, out indices, out baseIndex);
}
else
{
StartTriangleDrawing(vertexFragment, out vertices, out textures, out indices, out baseIndex);
}
}
else
{
throw new NotSupportedException(string.Format("PrimitiveType: {0} is not supported.", vertexFragment.PrimitiveType));
}
}
示例11: Create3DPlane
public Create3DPlane(Vector3 position, float size, Vector3 normal)
{
vertexes = new VertexPositionNormalTexture[6];
//Vértices
//1º triângulo
Vector3 topLeft = new Vector3(position.X - size / 2, position.Y, -position.Z - size / 2);
Vector3 bottomLeft = new Vector3(position.X - size / 2, position.Y, position.Z + size / 2);
Vector3 topRight = new Vector3(position.X + size / 2, position.Y, position.Z - size / 2);
//2º triângulo
//bottomLeft já está definido
Vector3 bottomRight = new Vector3(position.X + size / 2, position.Y, position.Z + size / 2);
//topRight já está definido
// Coordenadas da textura
Vector2 textureTopLeft = new Vector2(0.0f, 0.0f);
Vector2 textureTopRight = new Vector2(1.0f, 0.0f);
Vector2 textureBottomLeft = new Vector2(0.0f, 1.0f);
Vector2 textureBottomRight = new Vector2(1.0f, 1.0f);
vertexes[0] = new VertexPositionNormalTexture(topLeft, normal, textureTopLeft);
vertexes[1] = new VertexPositionNormalTexture(bottomLeft, normal, textureBottomLeft);
vertexes[2] = new VertexPositionNormalTexture(topRight, normal, textureTopRight);
vertexes[3] = new VertexPositionNormalTexture(bottomLeft, normal, textureBottomLeft);
vertexes[4] = new VertexPositionNormalTexture(bottomRight, normal, textureBottomRight);
vertexes[5] = new VertexPositionNormalTexture(topRight, normal, textureTopRight);
}
示例12: GenerateNormalsForTriangleStrip
public static void GenerateNormalsForTriangleStrip( VertexPositionNormalTexture[] verts, int[] indices )
{
// first reset all normals
VertexUtils.ResetAllNormals( verts );
// iterate through and add normals to all vertices for each indexed primitive
// because indexed as triange strip, need to keep track of swap vert winding to get normals pointing in correct direction
bool swapWinding = false;
for ( int i = 2; i < indices.Length; i++ ) {
Vector3 firstVec = verts[indices[i - 1]].Position - verts[indices[i]].Position;
Vector3 secondVec = verts[indices[i - 2]].Position - verts[indices[i]].Position;
Vector3 normal = Vector3.Cross( firstVec, secondVec );
normal.Normalize();
if ( swapWinding ) {
normal *= -1;
}
verts[indices[i]].Normal += normal;
verts[indices[i - 1]].Normal += normal;
verts[indices[i - 2]].Normal += normal;
swapWinding = !swapWinding;
}
VertexUtils.NormalizeAllNormals( verts );
}
示例13: Dot
public Dot(Vector3 position, int scale)
{
if (scale <= 0) throw new ArgumentOutOfRangeException("scale", "Parameter must be grater than zero");
Center = startCenter = position;
startVertices = new VertexPositionNormalTexture[3];
currentVertices = new VertexPositionNormalTexture[3];
lineIndices = new short[6];
triangleIndices = new short[6];
currentVertices[0] = new VertexPositionNormalTexture
(position - 0.01f * scale * Vector3.UnitX + 0.01f * scale * Vector3.UnitZ,
Vector3.Up, Vector2.Zero);
currentVertices[1] = new VertexPositionNormalTexture
(position + 0.01f * scale * Vector3.UnitX + 0.01f * scale * Vector3.UnitZ,
Vector3.Up, Vector2.UnitX);
currentVertices[2] = new VertexPositionNormalTexture
(position - 0.01f * scale * Vector3.UnitZ,
Vector3.Up, Vector2.UnitY);
lineIndices[0] = 0; lineIndices[1] = 1; lineIndices[2] = 1; lineIndices[3] = 2; lineIndices[4] = 2; lineIndices[5] = 0;
triangleIndices[0] = 0; triangleIndices[1] = 1; triangleIndices[2] = 2; triangleIndices[3] = 2; triangleIndices[4] = 1; triangleIndices[5] = 0;
Array.Copy(currentVertices, startVertices, startVertices.Length);
}
示例14: BuildPrimitive
protected override void BuildPrimitive()
{
const float MAGIC_NUMBER = 666f;
vertices = new VertexPositionNormalTexture[6];
int n = 0;
vertices[n++] = new VertexPositionNormalTexture(Vector3.Zero, Vector3.Zero, new Vector2(1, 1));
vertices[n++] = new VertexPositionNormalTexture(Vector3.Zero, Vector3.Zero, new Vector2(1, 0));
vertices[n++] = new VertexPositionNormalTexture(Vector3.Zero, Vector3.Zero, new Vector2(0, 1));
vertices[n++] = new VertexPositionNormalTexture(Vector3.Zero, Vector3.Zero, new Vector2(0, 0));
vertices[n++] = new VertexPositionNormalTexture(Vector3.Zero, Vector3.Zero, new Vector2(0, 1));
vertices[n++] = new VertexPositionNormalTexture(Vector3.Zero, Vector3.Zero, new Vector2(1, 0));
for (int i = 0; i < vertices.Length; ++i)
{
float u = (float)core.art.GetTileSize() / (float)core.art.GetTiles().Width;
float v = (float)core.art.GetTileSize() / (float)core.art.GetTiles().Height;
float integral = (float)Math.Truncate(u * (int)tileType);
float x = u * (int)tileType - integral;
float y = v * integral;
vertices[i].TextureCoordinate = vertices[i].TextureCoordinate * new Vector2(u, v) + new Vector2(x, y) + vertices[i].TextureCoordinate * MAGIC_NUMBER;
}
}
示例15: Bilboard
public Bilboard(Texture2D tex, Matrix scale)
{
vertices = new VertexPositionNormalTexture[4];
vertices[0] = new VertexPositionNormalTexture (new Vector3(-0.5f, -0.5f, 0.0f), new Vector3(0.0f,0.0f,1.0f), new Vector2(0.0f,0.0f));
vertices[1] = new VertexPositionNormalTexture (new Vector3(0.5f, -0.5f, 0.0f), new Vector3(0.0f,0.0f,1.0f), new Vector2(1.0f,0.0f));
vertices[2] = new VertexPositionNormalTexture (new Vector3(-0.5f, 0.5f, 0.0f), new Vector3(0.0f,0.0f,1.0f), new Vector2(0.0f,1.0f));
vertices[3] = new VertexPositionNormalTexture (new Vector3(0.5f, 0.5f, 0.0f), new Vector3(0.0f,0.0f,1.0f), new Vector2(1.0f,1.0f));
offsets = new Vector3[4];
offsets [0] = new Vector3 (-0.5f, -0.5f, 0.0f);
offsets [1] = new Vector3 (0.5f, -0.5f, 0.0f);
offsets [2] = new Vector3 (-0.5f, 0.5f, 0.0f);
offsets [3] = new Vector3 (0.5f, 0.5f, 0.0f);
indices = new short[6];
indices [0] = 0;
indices [1] = 1;
indices [2] = 2;
indices [3] = 1;
indices [4] = 3;
indices [5] = 2;
this.texture = tex;
this.scale = scale;
inUse = false;
}