本文整理汇总了C#中IRenderContext.EnableVertexColors方法的典型用法代码示例。如果您正苦于以下问题:C# IRenderContext.EnableVertexColors方法的具体用法?C# IRenderContext.EnableVertexColors怎么用?C# IRenderContext.EnableVertexColors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IRenderContext
的用法示例。
在下文中一共展示了IRenderContext.EnableVertexColors方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RenderWireframeCube
public void RenderWireframeCube(
IRenderContext renderContext,
IBoundingBox boundingBox,
Color? color = null)
{
if (color == null) color = Color.White;
var vertexes = new[]
{
new VertexPositionColor(new Vector3(0, 0, 0), color.Value),
new VertexPositionColor(new Vector3(0, 0, 1), color.Value),
new VertexPositionColor(new Vector3(0, 1, 0), color.Value),
new VertexPositionColor(new Vector3(0, 1, 1), color.Value),
new VertexPositionColor(new Vector3(1, 0, 0), color.Value),
new VertexPositionColor(new Vector3(1, 0, 1), color.Value),
new VertexPositionColor(new Vector3(1, 1, 0), color.Value),
new VertexPositionColor(new Vector3(1, 1, 1), color.Value)
};
var indicies = new short[]
{
0, 1, 0, 2, 1, 3, 2, 3,
4, 5, 4, 6, 5, 7, 6, 7,
0, 4, 1, 5, 2, 6, 3, 7
};
renderContext.EnableVertexColors();
var world = renderContext.World;
var xnaBoundingBox = boundingBox.ToXna();
renderContext.World =
Matrix.CreateScale(xnaBoundingBox.Max - xnaBoundingBox.Min) *
Matrix.CreateTranslation(xnaBoundingBox.Min);
foreach (var pass in renderContext.Effect.CurrentTechnique.Passes)
{
pass.Apply();
renderContext.GraphicsDevice.DrawUserIndexedPrimitives(
PrimitiveType.LineList,
vertexes,
0,
vertexes.Length,
indicies,
0,
vertexes.Length / 2);
}
renderContext.World = world;
}
示例2: RenderCircle
public void RenderCircle(IRenderContext context,
Matrix transform, Vector2 center, int radius, Color color, bool filled = false)
{
if (!context.Is3DContext)
{
throw new InvalidOperationException("Can't use 3D rendering utilities in 2D context.");
}
var points = 8;
double angle = MathHelper.TwoPi / points;
var vertexesList = new List<VertexPositionColor>();
var indicesList = new List<short>();
vertexesList.Add(new VertexPositionColor(new Vector3(center, 0), color));
for (int i = 1; i <= points; i++)
{
var pos = new Vector2(
(float)Math.Round(Math.Sin(angle * i), 4) * radius,
(float)Math.Round(Math.Cos(angle * i), 4) * radius);
vertexesList.Add(new VertexPositionColor(new Vector3(center + pos, 0), color));
}
if (filled)
{
for (int i = 1; i < points; i++)
{
indicesList.Add(0);
indicesList.Add((short)(i + 1));
indicesList.Add((short) i);
}
indicesList.Add(0);
indicesList.Add(1);
indicesList.Add((short) points);
}
else
{
for (int i = 1; i <= points; i++)
{
indicesList.Add((short) i);
}
indicesList.Add((short)1);
}
var vertexes = vertexesList.ToArray();
var indicies = indicesList.ToArray();
context.EnableVertexColors();
var world = context.World;
context.World = transform;
foreach (var pass in context.Effect.CurrentTechnique.Passes)
{
pass.Apply();
context.GraphicsDevice.DrawUserIndexedPrimitives(
filled ? PrimitiveType.TriangleList : PrimitiveType.LineStrip,
vertexes,
0,
vertexes.Length,
indicies,
0,
indicies.Length / 3);
}
context.World = world;
}
示例3: RenderPlane
/// <summary>
/// Renders a 2D plane from 0, 0, 0 to 1, 0, 1, applying the specified transformation.
/// </summary>
/// <param name="context">
/// The rendering context.
/// </param>
/// <param name="transform">
/// The transformation to apply.
/// </param>
/// <param name="color">
/// The color of the plane.
/// </param>
public void RenderPlane(IRenderContext context, Matrix transform, Color color)
{
if (!context.Is3DContext)
{
throw new InvalidOperationException("Can't use 3D rendering utilities in 2D context.");
}
var vertexes = new[]
{
new VertexPositionColor(new Vector3(0, 0, 0), color),
new VertexPositionColor(new Vector3(0, 0, 1), color),
new VertexPositionColor(new Vector3(1, 0, 0), color),
new VertexPositionColor(new Vector3(1, 0, 1), color),
};
var indicies = new short[]
{
0, 2, 1,
3, 1, 2,
};
context.EnableVertexColors();
var world = context.World;
context.World = transform;
foreach (var pass in context.Effect.CurrentTechnique.Passes)
{
pass.Apply();
context.GraphicsDevice.DrawUserIndexedPrimitives(
PrimitiveType.TriangleList,
vertexes,
0,
vertexes.Length,
indicies,
0,
indicies.Length / 3);
}
context.World = world;
}
示例4: RenderLine
/// <summary>
/// The render line.
/// </summary>
/// <param name="context">
/// The context.
/// </param>
/// <param name="start">
/// The start.
/// </param>
/// <param name="end">
/// The end.
/// </param>
/// <param name="color">
/// The color.
/// </param>
/// <exception cref="InvalidOperationException">
/// </exception>
public void RenderLine(IRenderContext context, Vector3 start, Vector3 end, Color color)
{
if (!context.Is3DContext)
{
throw new InvalidOperationException("Can't use 3D rendering utilities in 2D context.");
}
context.EnableVertexColors();
var vertexes = new[] { new VertexPositionColor(start, color), new VertexPositionColor(end, color) };
var indicies = new short[] { 0, 1 };
foreach (var pass in context.Effect.CurrentTechnique.Passes)
{
pass.Apply();
context.GraphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.LineList, vertexes, 0, 2, indicies, 0, 1);
}
}
示例5: RenderXY
private void RenderXY(IRenderContext renderContext, int gridX, int gridY, int gridZ, int horRange, int vertRange, int verticalSelection, Color baseColor, Color gridColor)
{
var vertexes = new List<VertexPositionColor>();
var indicies = new List<short>();
for (var x = gridX - horRange; x < gridX + horRange; x++)
{
var color = baseColor;
if (x % 20 == 0)
{
color = gridColor;
}
if (x > gridX + horRange - 5)
{
var b = (1f / 5f) * (5 - (x - (gridX + horRange - 5)));
color *= b;
}
for (var y = 0; y < 5; y++)
{
var b = (1f / 5f) * y;
var endColor = color * b;
vertexes.Add(new VertexPositionColor(new Vector3(x, gridY + vertRange - y, gridZ - horRange), endColor));
vertexes.Add(new VertexPositionColor(new Vector3(x, gridY + vertRange - y - 1, gridZ - horRange), endColor));
indicies.Add((short)(vertexes.Count - 2));
indicies.Add((short)(vertexes.Count - 1));
}
vertexes.Add(new VertexPositionColor(new Vector3(x, gridY, gridZ - horRange), color));
vertexes.Add(new VertexPositionColor(new Vector3(x, gridY + horRange - 5, gridZ - horRange), color));
indicies.Add((short)(vertexes.Count - 2));
indicies.Add((short)(vertexes.Count - 1));
}
for (var y = gridY; y < gridY + vertRange; y++)
{
var color = baseColor;
if (y % 10 == 0)
{
color = gridColor;
}
if (y == gridY + verticalSelection || y == gridY)
{
color = new Color(127, 127, 127);
}
if (y > gridY + vertRange - 5)
{
var b = (1f / 5f) * (5 - (y - (gridY + vertRange - 5)));
color *= b;
}
for (var x = 0; x < 5; x++)
{
vertexes.Add(new VertexPositionColor(new Vector3(gridX - horRange + x, y, gridZ - horRange), color));
vertexes.Add(new VertexPositionColor(new Vector3(gridX - horRange + x + 1, y, gridZ - horRange), color));
indicies.Add((short)(vertexes.Count - 2));
indicies.Add((short)(vertexes.Count - 1));
}
for (var x = 0; x < 5; x++)
{
var b = (1f / 5f) * x;
var endColor = color * b;
vertexes.Add(new VertexPositionColor(new Vector3(gridX + horRange - x, y, gridZ - horRange), endColor));
vertexes.Add(new VertexPositionColor(new Vector3(gridX + horRange - x - 1, y, gridZ - horRange), endColor));
indicies.Add((short)(vertexes.Count - 2));
indicies.Add((short)(vertexes.Count - 1));
}
vertexes.Add(new VertexPositionColor(new Vector3(gridX - horRange + 5, y, gridZ - horRange), color));
vertexes.Add(new VertexPositionColor(new Vector3(gridX + horRange - 5, y, gridZ - horRange), color));
indicies.Add((short)(vertexes.Count - 2));
indicies.Add((short)(vertexes.Count - 1));
}
renderContext.EnableVertexColors();
foreach (var pass in renderContext.Effect.CurrentTechnique.Passes)
{
pass.Apply();
renderContext.GraphicsDevice.DrawUserIndexedPrimitives(
PrimitiveType.LineList,
vertexes.ToArray(),
0,
vertexes.Count,
indicies.ToArray(),
0,
indicies.Count / 2);
}
}
示例6: RenderXZ
//.........这里部分代码省略.........
if (x > gridX + horRange - 5)
{
var b = (1f / 5f) * (5 - (x - (gridX + horRange - 5)));
color *= b;
}
for (var z = 0; z < 5; z++)
{
vertexes.Add(
new VertexPositionColor(new Vector3(x, gridY, gridZ - horRange + z), color));
vertexes.Add(
new VertexPositionColor(new Vector3(x, gridY, gridZ - horRange + z + 1), color));
indicies.Add((short)(vertexes.Count - 2));
indicies.Add((short)(vertexes.Count - 1));
}
for (var z = 0; z < 5; z++)
{
var b = (1f / 5f) * z;
var endColor = color * b;
vertexes.Add(
new VertexPositionColor(new Vector3(x, gridY, gridZ + horRange - z), endColor));
vertexes.Add(
new VertexPositionColor(new Vector3(x, gridY, gridZ + horRange - z - 1), endColor));
indicies.Add((short)(vertexes.Count - 2));
indicies.Add((short)(vertexes.Count - 1));
}
vertexes.Add(
new VertexPositionColor(new Vector3(x, gridY, gridZ - horRange + 5), color));
vertexes.Add(
new VertexPositionColor(new Vector3(x, gridY, gridZ + horRange - 5), color));
indicies.Add((short)(vertexes.Count - 2));
indicies.Add((short)(vertexes.Count - 1));
}
for (var z = gridZ - horRange; z < gridZ + horRange; z++)
{
var color = baseColor;
if (z % 20 == 0)
{
color = gridColor;
}
if (z > gridZ + horRange - 5)
{
var b = (1f / 5f) * (5 - (z - (gridZ + horRange - 5)));
color *= b;
}
for (var x = 0; x < 5; x++)
{
vertexes.Add(
new VertexPositionColor(new Vector3(gridX - horRange + x, gridY, z), color));
vertexes.Add(
new VertexPositionColor(new Vector3(gridX - horRange + x + 1, gridY, z), color));
indicies.Add((short)(vertexes.Count - 2));
indicies.Add((short)(vertexes.Count - 1));
}
for (var x = 0; x < 5; x++)
{
var b = (1f / 5f) * x;
var endColor = color * b;
vertexes.Add(
new VertexPositionColor(new Vector3(gridX + horRange - x, gridY, z), endColor));
vertexes.Add(
new VertexPositionColor(new Vector3(gridX + horRange - x - 1, gridY, z), endColor));
indicies.Add((short)(vertexes.Count - 2));
indicies.Add((short)(vertexes.Count - 1));
}
vertexes.Add(
new VertexPositionColor(new Vector3(gridX - horRange + 5, gridY, z), color));
vertexes.Add(
new VertexPositionColor(new Vector3(gridX + horRange - 5, gridY, z), color));
indicies.Add((short)(vertexes.Count - 2));
indicies.Add((short)(vertexes.Count - 1));
}
renderContext.EnableVertexColors();
foreach (var pass in renderContext.Effect.CurrentTechnique.Passes)
{
pass.Apply();
renderContext.GraphicsDevice.DrawUserIndexedPrimitives(
PrimitiveType.LineList,
vertexes.ToArray(),
0,
vertexes.Count,
indicies.ToArray(),
0,
indicies.Count / 2);
}
}