本文整理汇总了C#中IDrawDevice.AddVertices方法的典型用法代码示例。如果您正苦于以下问题:C# IDrawDevice.AddVertices方法的具体用法?C# IDrawDevice.AddVertices怎么用?C# IDrawDevice.AddVertices使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDrawDevice
的用法示例。
在下文中一共展示了IDrawDevice.AddVertices方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Draw
public override void Draw(IDrawDevice device)
{
// Perform Camera space transformation
Vector3 posBefore = this.GameObj.Transform.Pos;
Vector3 posTemp = posBefore;
float scaleTemp = 1.0f;
device.PreprocessCoords(this, ref posTemp, ref scaleTemp);
// Draw debug text
VertexC1P3T2[] textVertices;
textVertices = null;
Font.GenericMonospace10.Res.EmitTextVertices(
string.Format("Position (world): {0:0}, {1:0}, {2:0}", posBefore.X, posBefore.Y, posBefore.Z),
ref textVertices, posTemp.X, posTemp.Y, posTemp.Z);
device.AddVertices(Font.GenericMonospace10.Res.Material, BeginMode.Quads, textVertices);
textVertices = null;
Font.GenericMonospace10.Res.EmitTextVertices(
string.Format("Position (cam): {0:0}, {1:0}, {2:0}", posTemp.X, posTemp.Y, posTemp.Z),
ref textVertices, posTemp.X, posTemp.Y + 10, posTemp.Z);
device.AddVertices(Font.GenericMonospace10.Res.Material, BeginMode.Quads, textVertices);
textVertices = null;
Font.GenericMonospace10.Res.EmitTextVertices(
string.Format("Scale: {0:F}", scaleTemp),
ref textVertices, posTemp.X, posTemp.Y + 20, posTemp.Z);
device.AddVertices(Font.GenericMonospace10.Res.Material, BeginMode.Quads, textVertices);
// Draw position indicator
device.AddVertices(new BatchInfo(DrawTechnique.Alpha, ColorRgba.Red.WithAlpha(0.25f)), BeginMode.Quads, new VertexP3[] {
new VertexP3(posTemp.X - 50.0f * scaleTemp, posTemp.Y - 50.0f * scaleTemp, posTemp.Z),
new VertexP3(posTemp.X + 50.0f * scaleTemp, posTemp.Y - 50.0f * scaleTemp, posTemp.Z),
new VertexP3(posTemp.X + 50.0f * scaleTemp, posTemp.Y + 50.0f * scaleTemp, posTemp.Z),
new VertexP3(posTemp.X - 50.0f * scaleTemp, posTemp.Y + 50.0f * scaleTemp, posTemp.Z) });
}
示例2: Draw
public override void Draw(IDrawDevice device)
{
Texture mainTex = this.RetrieveMainTex();
ColorRgba mainClr = this.RetrieveMainColor();
DrawTechnique tech = this.RetrieveDrawTechnique();
Rect uvRect;
if (mainTex != null)
{
if (this.rectMode == UVMode.WrapBoth)
uvRect = new Rect(mainTex.UVRatio.X * this.rect.W / mainTex.PixelWidth, mainTex.UVRatio.Y * this.rect.H / mainTex.PixelHeight);
else if (this.rectMode == UVMode.WrapHorizontal)
uvRect = new Rect(mainTex.UVRatio.X * this.rect.W / mainTex.PixelWidth, mainTex.UVRatio.Y);
else if (this.rectMode == UVMode.WrapVertical)
uvRect = new Rect(mainTex.UVRatio.X, mainTex.UVRatio.Y * this.rect.H / mainTex.PixelHeight);
else
uvRect = new Rect(mainTex.UVRatio.X, mainTex.UVRatio.Y);
}
else
uvRect = new Rect(1.0f, 1.0f);
this.PrepareVerticesLight(ref this.verticesLight, device, mainClr, uvRect, tech);
if (this.customMat != null) device.AddVertices(this.customMat, VertexMode.Quads, this.verticesLight);
else device.AddVertices(this.sharedMat, VertexMode.Quads, this.verticesLight);
}
示例3: Draw
public override void Draw(IDrawDevice device)
{
var mainClr = RetrieveMainColor();
PrepareVertices(device, mainClr);
device.AddVertices(sharedMat, VertexMode.Quads, _vertices);
}
示例4: Draw
public override void Draw(IDrawDevice device)
{
Texture mainTex = this.RetrieveMainTex();
ColorRgba mainClr = this.RetrieveMainColor();
DrawTechnique tech = this.RetrieveDrawTechnique();
Rect uvRect;
Rect uvRectNext;
bool smoothShaderInput = tech != null && tech.PreferredVertexFormat == VertexC1P3T4A4A1.Declaration;
this.GetAnimData(mainTex, tech, smoothShaderInput, out uvRect, out uvRectNext);
if (!smoothShaderInput)
{
this.PrepareVerticesLight(ref this.verticesLight, device, mainClr, uvRect, tech);
if (this.customMat != null) device.AddVertices(this.customMat, VertexMode.Quads, this.verticesLight);
else device.AddVertices(this.sharedMat, VertexMode.Quads, this.verticesLight);
}
else
{
this.PrepareVerticesLightSmooth(ref this.verticesLightSmooth, device, this.CurrentFrameProgress, mainClr, uvRect, uvRectNext, tech);
if (this.customMat != null) device.AddVertices(this.customMat, VertexMode.Quads, this.verticesLightSmooth);
else device.AddVertices(this.sharedMat, VertexMode.Quads, this.verticesLightSmooth);
}
}
示例5: Draw
//.........这里部分代码省略.........
// Determine and adjust data for Z offset generation
float depthPerTile = -cullingIn.TileSize.Y * cullingIn.TilemapScale * this.tileDepthScale;
if (this.tileDepthMode == TileDepthOffsetMode.Flat)
depthPerTile = 0.0f;
float originDepthOffset = Rect.Align(this.origin, 0, 0, 0, tileCount.Y * depthPerTile).Y;
if (this.tileDepthMode == TileDepthOffsetMode.World)
originDepthOffset += (this.GameObj.Transform.Pos.Y / (float)tileSize.Y) * depthPerTile;
cullingOut.RenderOriginView.Z += this.offset + this.tileDepthOffset * depthPerTile + originDepthOffset;
// Prepare vertex generation data
Vector2 tileXStep = cullingOut.XAxisView * cullingIn.TileSize.X;
Vector2 tileYStep = cullingOut.YAxisView * cullingIn.TileSize.Y;
Vector3 renderPos = cullingOut.RenderOriginView;
Point2 tileGridPos = cullingOut.VisibleTileStart;
// Prepare vertex data array for batch-submitting
IReadOnlyGrid<Tile> tiles = tilemap.Tiles;
TileInfo[] tileData = tileset.TileData.Data;
int submittedTileCount = 0;
int vertexBaseIndex = 0;
for (int tileIndex = 0; tileIndex < renderedTileCount; tileIndex++)
{
Tile tile = tiles[tileGridPos.X, tileGridPos.Y];
if (tile.Index < tileData.Length)
{
Rect uvRect = tileData[tile.Index].TexCoord0;
bool visualEmpty = tileData[tile.Index].IsVisuallyEmpty;
int tileBaseOffset = tileData[tile.Index].DepthOffset;
float localDepthOffset = (tile.DepthOffset + tileBaseOffset) * depthPerTile;
if (!visualEmpty)
{
vertexData[vertexBaseIndex + 0].Pos.X = renderPos.X;
vertexData[vertexBaseIndex + 0].Pos.Y = renderPos.Y;
vertexData[vertexBaseIndex + 0].Pos.Z = renderPos.Z + localDepthOffset;
vertexData[vertexBaseIndex + 0].TexCoord.X = uvRect.X;
vertexData[vertexBaseIndex + 0].TexCoord.Y = uvRect.Y;
vertexData[vertexBaseIndex + 0].Color = mainColor;
vertexData[vertexBaseIndex + 1].Pos.X = renderPos.X + tileYStep.X;
vertexData[vertexBaseIndex + 1].Pos.Y = renderPos.Y + tileYStep.Y;
vertexData[vertexBaseIndex + 1].Pos.Z = renderPos.Z + localDepthOffset + depthPerTile;
vertexData[vertexBaseIndex + 1].TexCoord.X = uvRect.X;
vertexData[vertexBaseIndex + 1].TexCoord.Y = uvRect.Y + uvRect.H;
vertexData[vertexBaseIndex + 1].Color = mainColor;
vertexData[vertexBaseIndex + 2].Pos.X = renderPos.X + tileXStep.X + tileYStep.X;
vertexData[vertexBaseIndex + 2].Pos.Y = renderPos.Y + tileXStep.Y + tileYStep.Y;
vertexData[vertexBaseIndex + 2].Pos.Z = renderPos.Z + localDepthOffset + depthPerTile;
vertexData[vertexBaseIndex + 2].TexCoord.X = uvRect.X + uvRect.W;
vertexData[vertexBaseIndex + 2].TexCoord.Y = uvRect.Y + uvRect.H;
vertexData[vertexBaseIndex + 2].Color = mainColor;
vertexData[vertexBaseIndex + 3].Pos.X = renderPos.X + tileXStep.X;
vertexData[vertexBaseIndex + 3].Pos.Y = renderPos.Y + tileXStep.Y;
vertexData[vertexBaseIndex + 3].Pos.Z = renderPos.Z + localDepthOffset;
vertexData[vertexBaseIndex + 3].TexCoord.X = uvRect.X + uvRect.W;
vertexData[vertexBaseIndex + 3].TexCoord.Y = uvRect.Y;
vertexData[vertexBaseIndex + 3].Color = mainColor;
bool vertical = tileData[tile.Index].IsVertical;
if (vertical)
{
vertexData[vertexBaseIndex + 0].Pos.Z += depthPerTile;
vertexData[vertexBaseIndex + 3].Pos.Z += depthPerTile;
}
submittedTileCount++;
vertexBaseIndex += 4;
}
}
tileGridPos.X++;
renderPos.X += tileXStep.X;
renderPos.Y += tileXStep.Y;
if ((tileGridPos.X - cullingOut.VisibleTileStart.X) >= cullingOut.VisibleTileCount.X)
{
tileGridPos.X = cullingOut.VisibleTileStart.X;
tileGridPos.Y++;
renderPos = cullingOut.RenderOriginView;
renderPos.X += tileYStep.X * (tileGridPos.Y - cullingOut.VisibleTileStart.Y);
renderPos.Y += tileYStep.Y * (tileGridPos.Y - cullingOut.VisibleTileStart.Y);
renderPos.Z += tileGridPos.Y * depthPerTile;
}
}
// Submit all the vertices as one draw batch
device.AddVertices(
material,
VertexMode.Quads,
vertexData,
submittedTileCount * 4);
Profile.AddToStat(@"Duality\Stats\Render\Tilemaps\NumTiles", renderedTileCount);
Profile.AddToStat(@"Duality\Stats\Render\Tilemaps\NumVertices", submittedTileCount * 4);
}
示例6: Draw
public override void Draw(IDrawDevice device)
{
Vector3 posTemp = this.gameobj.Transform.Pos;
float scaleTemp = 1.0f;
device.PreprocessCoords(ref posTemp, ref scaleTemp);
Vector2 xDot, yDot;
MathF.GetTransformDotVec(this.GameObj.Transform.Angle, this.gameobj.Transform.Scale * scaleTemp, out xDot, out yDot);
// Apply block alignment
Vector2 textOffset = Vector2.Zero;
Vector2 textSize = this.text.Size;
if (this.text.MaxWidth > 0) textSize.X = this.text.MaxWidth;
this.blockAlign.ApplyTo(ref textOffset, textSize);
MathF.TransformDotVec(ref textOffset, ref xDot, ref yDot);
posTemp.X += textOffset.X;
posTemp.Y += textOffset.Y;
if (this.text.Fonts != null && this.text.Fonts.Any(r => r.IsAvailable && r.Res.IsPixelGridAligned))
{
posTemp.X = MathF.Round(posTemp.X);
posTemp.Y = MathF.Round(posTemp.Y);
if (MathF.RoundToInt(device.TargetSize.X) != (MathF.RoundToInt(device.TargetSize.X) / 2) * 2)
posTemp.X += 0.5f;
if (MathF.RoundToInt(device.TargetSize.Y) != (MathF.RoundToInt(device.TargetSize.Y) / 2) * 2)
posTemp.Y += 0.5f;
}
// Draw design time metrics data
if (DualityApp.ExecContext == DualityApp.ExecutionContext.Editor)
{
bool showLimits = true;
bool showLines = false;
bool showElements = false;
Vector3 metricsOffset = new Vector3(0.0f, 0.0f, 0.01f);
Vector3 lineOffset = new Vector3(0.5f, 0.5f, 0.0f);
Vector3 tUnitX = Vector3.UnitX;
Vector3 tUnitY = Vector3.UnitY;
MathF.TransformDotVec(ref tUnitX, ref xDot, ref yDot);
MathF.TransformDotVec(ref tUnitY, ref xDot, ref yDot);
// Actual text size and maximum text size
if (showLimits)
{
Vector3 textWidth = tUnitX * this.text.Size.X;
Vector3 textHeight = tUnitY * this.text.Size.Y;
Vector3 textMaxWidth = tUnitX * this.text.MaxWidth;
Vector3 textMaxHeight = tUnitY * MathF.Max(this.text.MaxHeight, this.text.Size.Y);
ColorRgba clrSize = ColorRgba.Green.WithAlpha(128);
ColorRgba clrMaxSize = ColorRgba.Red.WithAlpha(128);
device.AddVertices(new BatchInfo(DrawTechnique.Alpha, ColorRgba.White), VertexMode.LineLoop,
new VertexC1P3(metricsOffset + lineOffset + posTemp, clrSize),
new VertexC1P3(metricsOffset + lineOffset + posTemp + textWidth, clrSize),
new VertexC1P3(metricsOffset + lineOffset + posTemp + textWidth + textHeight, clrSize),
new VertexC1P3(metricsOffset + lineOffset + posTemp + textHeight, clrSize));
device.AddVertices(new BatchInfo(DrawTechnique.Alpha, ColorRgba.White), VertexMode.LineLoop,
new VertexC1P3(metricsOffset + lineOffset + posTemp, clrMaxSize),
new VertexC1P3(metricsOffset + lineOffset + posTemp + textMaxWidth, clrMaxSize),
new VertexC1P3(metricsOffset + lineOffset + posTemp + textMaxWidth + textMaxHeight, clrMaxSize),
new VertexC1P3(metricsOffset + lineOffset + posTemp + textMaxHeight, clrMaxSize));
}
// Individual line sizes
if (showLines)
{
ColorRgba clrLineBg = (ColorRgba.Blue + ColorRgba.Red).WithAlpha(64);
for (int i = 0; i < this.text.TextMetrics.LineBounds.Count; i++)
{
Rect lineRect = this.text.TextMetrics.LineBounds[i];
device.AddVertices(new BatchInfo(DrawTechnique.Alpha, ColorRgba.White), VertexMode.Quads,
new VertexC1P3(metricsOffset + posTemp + lineRect.TopLeft.X * tUnitX + lineRect.TopLeft.Y * tUnitY, clrLineBg),
new VertexC1P3(metricsOffset + posTemp + lineRect.BottomLeft.X * tUnitX + lineRect.BottomLeft.Y * tUnitY, clrLineBg),
new VertexC1P3(metricsOffset + posTemp + lineRect.BottomRight.X * tUnitX + lineRect.BottomRight.Y * tUnitY, clrLineBg),
new VertexC1P3(metricsOffset + posTemp + lineRect.TopRight.X * tUnitX + lineRect.TopRight.Y * tUnitY, clrLineBg));
}
}
// Individual line sizes
if (showElements)
{
ColorRgba clrElementBg = (ColorRgba.Blue + ColorRgba.Green).WithAlpha(128);
for (int i = 0; i < this.text.TextMetrics.ElementBounds.Count; i++)
{
Rect elemRect = this.text.TextMetrics.ElementBounds[i];
device.AddVertices(new BatchInfo(DrawTechnique.Alpha, ColorRgba.White), VertexMode.LineLoop,
new VertexC1P3(metricsOffset + lineOffset + posTemp + elemRect.TopLeft.X * tUnitX + elemRect.TopLeft.Y * tUnitY, clrElementBg),
new VertexC1P3(metricsOffset + lineOffset + posTemp + elemRect.BottomLeft.X * tUnitX + elemRect.BottomLeft.Y * tUnitY, clrElementBg),
new VertexC1P3(metricsOffset + lineOffset + posTemp + elemRect.BottomRight.X * tUnitX + elemRect.BottomRight.Y * tUnitY, clrElementBg),
new VertexC1P3(metricsOffset + lineOffset + posTemp + elemRect.TopRight.X * tUnitX + elemRect.TopRight.Y * tUnitY, clrElementBg));
}
}
}
ColorRgba matColor = this.customMat != null ? this.customMat.MainColor : ColorRgba.White;
int[] vertLen = this.text.EmitVertices(ref this.vertFont, ref this.vertIcon, posTemp.X, posTemp.Y, posTemp.Z, this.colorTint * matColor, xDot, yDot);
if (this.text.Fonts != null)
{
for (int i = 0; i < this.text.Fonts.Length; i++)
{
if (this.text.Fonts[i] != null && this.text.Fonts[i].IsAvailable)
//.........这里部分代码省略.........
示例7: Draw
public override void Draw(IDrawDevice device)
{
Texture mainTex = this.RetrieveMainTex();
ColorRgba mainClr = this.RetrieveMainColor();
DrawTechnique tech = this.RetrieveDrawTechnique();
Rect uvRect;
if (mainTex != null) uvRect = new Rect(mainTex.UVRatio.X, mainTex.UVRatio.Y);
else uvRect = new Rect(1.0f, 1.0f);
this.PrepareVerticesLight(ref this.verticesLight, device, mainClr, uvRect, tech);
if (this.customMat != null) device.AddVertices(this.customMat, VertexMode.Quads, this.verticesLight);
else device.AddVertices(this.sharedMat, VertexMode.Quads, this.verticesLight);
}
示例8: Draw
public override void Draw(IDrawDevice device)
{
Texture mainTex = this.RetrieveMainTex();
ColorRgba mainClr = this.RetrieveMainColor();
DrawTechnique tech = this.RetrieveDrawTechnique();
Rect uvRect;
Rect uvRectNext;
bool smoothShaderInput = tech != null && tech.PreferredVertexFormat == DrawTechnique.VertexType_C1P3T4A1;
this.GetAnimData(mainTex, tech, smoothShaderInput, out uvRect, out uvRectNext);
if (!smoothShaderInput)
{
this.PrepareVertices(ref this.vertices, device, mainClr, uvRect);
if (this.customMat != null) device.AddVertices(this.customMat, VertexMode.Quads, this.vertices);
else device.AddVertices(this.sharedMat, VertexMode.Quads, this.vertices);
}
else
{
this.PrepareVerticesSmooth(ref this.verticesSmooth, device, this.curAnimFrameFade, mainClr, uvRect, uvRectNext);
if (this.customMat != null) device.AddVertices(this.customMat, VertexMode.Quads, this.verticesSmooth);
else device.AddVertices(this.sharedMat, VertexMode.Quads, this.verticesSmooth);
}
}
示例9: Draw
public override void Draw(IDrawDevice device)
{
this.PrepareVertices(ref this.vertices, device);
device.AddVertices(this.sharedMat, BeginMode.Quads, this.vertices);
}
示例10: Draw
//.........这里部分代码省略.........
float tempScale = 1f;
device.PreprocessCoords( ref tempPos, ref tempScale );
int halfMapW = W / 2;
int halfMapH = H / 2;
for (var i = Layers.Values.GetEnumerator(); i.MoveNext();) {
var layer = i.Current;
if (!layer.Visible)
continue;
for (int y = 0; y < H; y++) {
for (int x = 0; x < W; x++) {
// Is renderable tile available?
int gid = layer.GetTile(x, y);
if (gid <= 0)
continue;
// Get the correct tileset for this GID
var tileset = FindTilesetByGID(gid);
if (tileset == null)
continue;
// Remove tileset's FirstGID from the tile ID
// so we get the correct position in the image.
int tileX = (gid - tileset.FirstGID) % tileset.W;
int tileY = (gid - tileset.FirstGID) / tileset.W;
// Let 'em float...
float tx = (float)tileX;
float ty = (float)tileY;
float tw = (float)TileW;
float th = (float)TileH;
float twp = (float)tileset.WPixel;
float thp = (float)tileset.HPixel;
var vertices = new VertexC1P3T2[4];
// Get tileset main color and set layer's opacity on it
var color = tileset.Image.Res.MainColor.WithAlpha( layer.Opacity );
var uvRatio = tileset.Image.Res.MainTexture.Res.UVRatio;
// Texture coordinates
var uvRect = new Rect(
uvRatio.X * (tx * tw) / twp,
uvRatio.Y * (ty * th) / thp,
uvRatio.X * tw / twp,
uvRatio.Y * th / thp
);
// Position
float posX = tempPos.X + ((float)x - (float)halfMapW) * (float)TileW;
float posY = tempPos.Y + ((float)y - (float)halfMapH) * (float)TileH;
// Bottom-left
vertices[0] = new VertexC1P3T2();
vertices[0].Pos.X = (posX - tw / 2) * tempScale;
vertices[0].Pos.Y = (posY + th / 2) * tempScale;
vertices[0].Pos.Z = tempPos.Z;
vertices[0].TexCoord.X = uvRect.LeftX;
vertices[0].TexCoord.Y = uvRect.BottomY;
vertices[0].Color = color;
// Top-left
vertices[1] = new VertexC1P3T2();
vertices[1].Pos.X = (posX - tw / 2) * tempScale;
vertices[1].Pos.Y = (posY - th / 2) * tempScale;
vertices[1].Pos.Z = tempPos.Z;
vertices[1].TexCoord.X = uvRect.LeftX;
vertices[1].TexCoord.Y = uvRect.TopY;
vertices[1].Color = color;
// Top-right
vertices[2] = new VertexC1P3T2();
vertices[2].Pos.X = (posX + tw / 2) * tempScale;
vertices[2].Pos.Y = (posY - th / 2) * tempScale;
vertices[2].Pos.Z = tempPos.Z;
vertices[2].TexCoord.X = uvRect.RightX;
vertices[2].TexCoord.Y = uvRect.TopY;
vertices[2].Color = color;
// Bottom-right
vertices[3] = new VertexC1P3T2();
vertices[3].Pos.X = (posX + tw / 2) * tempScale;
vertices[3].Pos.Y = (posY + th / 2) * tempScale;
vertices[3].Pos.Z = tempPos.Z;
vertices[3].TexCoord.X = uvRect.RightX;
vertices[3].TexCoord.Y = uvRect.BottomY;
vertices[3].Color = color;
device.AddVertices(tileset.Image, VertexMode.Quads, vertices);
}
}
}
}
示例11: Draw
public override void Draw(IDrawDevice device)
{
Vector3 posTemp = this.gameobj.Transform.Pos;
float scaleTemp = 1.0f;
device.PreprocessCoords(ref posTemp, ref scaleTemp);
Vector2 xDot, yDot;
MathF.GetTransformDotVec(this.GameObj.Transform.Angle, this.gameobj.Transform.Scale * scaleTemp, out xDot, out yDot);
// Apply block alignment
Vector2 textOffset = Vector2.Zero;
Vector2 textSize = this.text.Size;
if (this.text.MaxWidth > 0) textSize.X = this.text.MaxWidth;
this.blockAlign.ApplyTo(ref textOffset, textSize);
MathF.TransformDotVec(ref textOffset, ref xDot, ref yDot);
posTemp.X += textOffset.X;
posTemp.Y += textOffset.Y;
if (this.text.Fonts != null && this.text.Fonts.Any(r => r.IsAvailable && r.Res.IsPixelGridAligned))
{
posTemp.X = MathF.Round(posTemp.X);
posTemp.Y = MathF.Round(posTemp.Y);
if (MathF.RoundToInt(device.TargetSize.X) != (MathF.RoundToInt(device.TargetSize.X) / 2) * 2)
posTemp.X += 0.5f;
if (MathF.RoundToInt(device.TargetSize.Y) != (MathF.RoundToInt(device.TargetSize.Y) / 2) * 2)
posTemp.Y += 0.5f;
}
ColorRgba matColor = this.customMat != null ? this.customMat.MainColor : ColorRgba.White;
int[] vertLen = this.text.EmitVertices(ref this.vertFont, ref this.vertIcon, posTemp.X, posTemp.Y, posTemp.Z + this.VertexZOffset, this.colorTint * matColor, xDot, yDot);
if (this.text.Fonts != null)
{
for (int i = 0; i < this.text.Fonts.Length; i++)
{
if (this.text.Fonts[i] != null && this.text.Fonts[i].IsAvailable)
{
if (this.customMat == null)
{
device.AddVertices(this.text.Fonts[i].Res.Material, VertexMode.Quads, this.vertFont[i], vertLen[i + 1]);
}
else
{
BatchInfo cm = new BatchInfo(this.customMat);
cm.Textures = this.text.Fonts[i].Res.Material.Textures;
device.AddVertices(cm, VertexMode.Quads, this.vertFont[i], vertLen[i + 1]);
}
}
}
}
if (this.text.Icons != null && this.iconMat.IsAvailable)
{
device.AddVertices(this.iconMat, VertexMode.Quads, this.vertIcon, vertLen[0]);
}
}
示例12: Draw
public override void Draw(IDrawDevice device)
{
Texture mainTex = this.RetrieveMainTex();
ColorRgba mainClr = this.RetrieveMainColor();
Rect uvRect;
if (mainTex != null)
{
if (this.spriteIndex < 0)
uvRect = new Rect(mainTex.UVRatio.X, mainTex.UVRatio.Y);
else
mainTex.LookupAtlas(this.spriteIndex, out uvRect);
}
else
{
uvRect = new Rect(1.0f, 1.0f);
}
this.PrepareVertices(ref this.vertices, device, mainClr, uvRect);
if (this.customMat != null)
device.AddVertices(this.customMat, VertexMode.Quads, this.vertices);
else
device.AddVertices(this.sharedMat, VertexMode.Quads, this.vertices);
}
示例13: Draw
public override void Draw(IDrawDevice device)
{
if (this.camComp.DrawDevice != device) return;
List<VertexC1P3> vertices = new List<VertexC1P3>((2 * this.layerCount * this.starsPerLayer) * 2);
float screenBoundRad = this.camComp.ViewBoundingRadius;
float minZDist = this.camComp.NearZ + this.camComp.ParallaxRefDist / 50.0f;
float stepTemp = this.TileSize;
Vector2 minPos = new Vector2(-screenBoundRad, -screenBoundRad);
Vector2 maxPos = new Vector2(screenBoundRad, screenBoundRad);
// Iterate over star layers
for (int layerIndex = 0; layerIndex < this.layerCount; layerIndex++)
{
StarLayer layer = this.starLayers[layerIndex];
// Determine the layers Z value & perform layer culling if too near
float layerZ = this.layerDepth * ((float)layerIndex / (float)this.layerCount) - this.GameObj.Transform.Pos.Z;
if (layerZ < 0.0f) layerZ += this.layerDepth * (float)(1 + (int)(-layerZ / this.layerDepth));
layerZ = layerZ % this.layerDepth;
if (layerZ <= this.GameObj.Transform.Pos.Z + minZDist) continue;
// Calculate transform data
Vector3 posTemp = this.GameObj.Transform.Pos + Vector3.UnitZ * layerZ;
Vector3 posTempTrail = this.GameObj.Transform.Pos + Vector3.UnitZ * (layerZ + this.GameObj.Transform.Vel.Z * this.trailLength);
float scaleTemp = 1.0f;
float scaleTempTrail = 1.0f;
device.PreprocessCoords(this, ref posTemp, ref scaleTemp);
device.PreprocessCoords(this, ref posTempTrail, ref scaleTempTrail);
posTempTrail += new Vector3(this.GameObj.Transform.Vel.Xy * this.trailLength);
// Prepare this layers transformation to calculate a stars trail position.
Vector2 starPosTempTrailDotX;
Vector2 starPosTempTrailDotY;
MathF.GetTransformDotVec(this.GameObj.Transform.AngleVel * this.trailLength, scaleTempTrail, out starPosTempTrailDotX, out starPosTempTrailDotY);
// Iterate over stars
for (int starIndex = 0; starIndex < layer.stars.Length; starIndex++)
{
// Since it's an endless starfield, each star may show up on multiple positions at once. It's tiled.
StarInfo star = layer.stars[starIndex];
Vector2 starPosBase = star.pos - this.GameObj.Transform.Pos.Xy;
// Move the topleft tiling corner to somewhere near the screens top left
if (starPosBase.X > minPos.X) starPosBase.X -= stepTemp * MathF.Ceiling((starPosBase.X - minPos.X) / stepTemp);
else if (starPosBase.X < minPos.X - stepTemp) starPosBase.X -= stepTemp * MathF.Ceiling((starPosBase.X - minPos.X) / stepTemp);
if (starPosBase.Y > minPos.Y) starPosBase.Y -= stepTemp * MathF.Ceiling((starPosBase.Y - minPos.Y) / stepTemp);
else if (starPosBase.Y < minPos.Y - stepTemp) starPosBase.Y -= stepTemp * MathF.Ceiling((starPosBase.Y - minPos.Y) / stepTemp);
// Tiling!
Vector2 startPos = starPosBase;
while (starPosBase.X <= maxPos.X && starPosBase.Y <= maxPos.Y)
{
// Determine star pos and perform culling
Vector3 starPosTemp = posTemp + new Vector3(starPosBase) * scaleTemp;
if (starPosTemp.X > -screenBoundRad && starPosTemp.Y > -screenBoundRad &&
starPosTemp.X < screenBoundRad && starPosTemp.Y < screenBoundRad)
{
// Determine trail pos
Vector3 starPosTempTrail = posTempTrail + new Vector3(starPosBase);
MathF.TransformDotVec(ref starPosTempTrail, ref starPosTempTrailDotX, ref starPosTempTrailDotY);
// Calculate length factor for the star's alpha value. Reduce alpha if too small or too big
float lenTemp = (starPosTemp - starPosTempTrail).Length;
if (lenTemp < 1.0f)
lenTemp = MathF.Max(0.25f, MathF.Sqrt(lenTemp));
else if (lenTemp > 1.0f)
lenTemp = 1.0f / MathF.Pow(lenTemp, 0.25f);
// Determine the star's alpha value and generate its vertices (star and trail)
float alpha = star.brightness * this.brightness * lenTemp * (1.0f - ((layerZ - minZDist) / (this.layerDepth - minZDist)));
vertices.Add(new VertexC1P3(starPosTemp, ColorRgba.White.WithAlpha(alpha)));
vertices.Add(new VertexC1P3(starPosTempTrail, ColorRgba.White.WithAlpha(alpha * 0.5f)));
}
// Advance X / Y grid
starPosBase.X += stepTemp;
if (starPosBase.X > maxPos.X)
{
starPosBase.X = startPos.X;
starPosBase.Y += stepTemp;
}
}
}
}
// Draw the stars all at once. Since they're not on the same Z layer, this may lead to wronz Z sorting
// when interacting with a complex environment that needs Z-Sorting itsself. For this application, it should be sufficient.
device.AddVertices(new BatchInfo(DrawTechnique.Add, ColorRgba.White), BeginMode.Lines, vertices.ToArray());
// (Can be fixed by drawing each layer in its own batch because they can be properly Z-sorted by Duality)
}
示例14: Draw
public override void Draw(IDrawDevice device)
{
ColorRgba mainClr = this.RetrieveMainColor();
List<Texture> texList = this.RetrieveMainTex();
for (int i = 0; i < texList.Count; i++)
{
Rect uvRect;
if (texList[i] != null)
{
if (this.rectMode == UVMode.WrapBoth)
uvRect = new Rect(texList[i].UVRatio.X * this.rect.W / texList[i].PixelWidth, texList[i].UVRatio.Y * this.rect.H / texList[i].PixelHeight);
else if (this.rectMode == UVMode.WrapHorizontal)
uvRect = new Rect(texList[i].UVRatio.X * this.rect.W / texList[i].PixelWidth, texList[i].UVRatio.Y);
else if (this.rectMode == UVMode.WrapVertical)
uvRect = new Rect(texList[i].UVRatio.X, texList[i].UVRatio.Y * this.rect.H / texList[i].PixelHeight);
else
uvRect = new Rect(texList[i].UVRatio.X, texList[i].UVRatio.Y);
}
else
uvRect = new Rect(1.0f, 1.0f);
this.PrepareVertices(ref this.vertices, device, mainClr, uvRect);
foreach (var item in this.sharedMat)
{
device.AddVertices(item, VertexMode.Quads, this.vertices);
}
}
}
示例15: Draw
public override void Draw(IDrawDevice device)
{
if (this.particles == null) return;
Texture tex = this.RetrieveTexture();
if (tex == null) return;
Vector2 particleHalfSize = this.particleSize * 0.5f;
float objAngle;
float objScale;
Vector3 objPos;
if (this.worldSpace)
{
objAngle = 0.0f;
objScale = 1.0f;
objPos = Vector3.Zero;
}
else
{
objAngle = this.GameObj.Transform.Angle;
objScale = this.GameObj.Transform.Scale;
objPos = this.GameObj.Transform.Pos;
}
Vector2 objXDot, objYDot;
MathF.GetTransformDotVec(objAngle, objScale, out objXDot, out objYDot);
if (this.vertexBuffer == null) this.vertexBuffer = new RawList<VertexC1P3T2>(this.particles.Count * 4);
this.vertexBuffer.Count = this.vertexBuffer.Count = this.particles.Count * 4;
VertexC1P3T2[] vertexData = this.vertexBuffer.Data;
Particle[] particleData = this.particles.Data;
int particleCount = this.particles.Count;
for (int i = 0; i < particleCount; i++)
{
ColorRgba color = particleData[i].Color;
float alpha = (float)color.A / 255.0f;
if (this.fadeOutAt < 1.0f) alpha *= MathF.Clamp((1.0f - particleData[i].AgeFactor) / this.fadeOutAt, 0.0f, 1.0f);
if (this.fadeInAt > 0.0f) alpha *= MathF.Clamp(particleData[i].AgeFactor / this.fadeInAt, 0.0f, 1.0f);
color.A = (byte)(alpha * 255.0f);
Rect uvRect;
tex.LookupAtlas(particleData[i].SpriteIndex, out uvRect);
Vector3 particlePos = particleData[i].Position;
MathF.TransformDotVec(ref particlePos, ref objXDot, ref objYDot);
particlePos += objPos;
float particleAngle = objAngle + particleData[i].Angle;
float particleScale = objScale;
device.PreprocessCoords(ref particlePos, ref particleScale);
Vector2 xDot, yDot;
MathF.GetTransformDotVec(particleAngle, particleScale, out xDot, out yDot);
Vector2 edgeTopLeft = new Vector2(-particleHalfSize.X, -particleHalfSize.Y);
Vector2 edgeBottomLeft = new Vector2(-particleHalfSize.X, particleHalfSize.Y);
Vector2 edgeBottomRight = new Vector2(particleHalfSize.X, particleHalfSize.Y);
Vector2 edgeTopRight = new Vector2(particleHalfSize.X, -particleHalfSize.Y);
MathF.TransformDotVec(ref edgeTopLeft, ref xDot, ref yDot);
MathF.TransformDotVec(ref edgeBottomLeft, ref xDot, ref yDot);
MathF.TransformDotVec(ref edgeBottomRight, ref xDot, ref yDot);
MathF.TransformDotVec(ref edgeTopRight, ref xDot, ref yDot);
int vertexBaseIndex = i * 4;
vertexData[vertexBaseIndex + 0].Pos.X = particlePos.X + edgeTopLeft.X;
vertexData[vertexBaseIndex + 0].Pos.Y = particlePos.Y + edgeTopLeft.Y;
vertexData[vertexBaseIndex + 0].Pos.Z = particlePos.Z;
vertexData[vertexBaseIndex + 0].TexCoord.X = uvRect.X;
vertexData[vertexBaseIndex + 0].TexCoord.Y = uvRect.Y;
vertexData[vertexBaseIndex + 0].Color = color;
vertexData[vertexBaseIndex + 1].Pos.X = particlePos.X + edgeBottomLeft.X;
vertexData[vertexBaseIndex + 1].Pos.Y = particlePos.Y + edgeBottomLeft.Y;
vertexData[vertexBaseIndex + 1].Pos.Z = particlePos.Z;
vertexData[vertexBaseIndex + 1].TexCoord.X = uvRect.X;
vertexData[vertexBaseIndex + 1].TexCoord.Y = uvRect.BottomY;
vertexData[vertexBaseIndex + 1].Color = color;
vertexData[vertexBaseIndex + 2].Pos.X = particlePos.X + edgeBottomRight.X;
vertexData[vertexBaseIndex + 2].Pos.Y = particlePos.Y + edgeBottomRight.Y;
vertexData[vertexBaseIndex + 2].Pos.Z = particlePos.Z;
vertexData[vertexBaseIndex + 2].TexCoord.X = uvRect.RightX;
vertexData[vertexBaseIndex + 2].TexCoord.Y = uvRect.BottomY;
vertexData[vertexBaseIndex + 2].Color = color;
vertexData[vertexBaseIndex + 3].Pos.X = particlePos.X + edgeTopRight.X;
vertexData[vertexBaseIndex + 3].Pos.Y = particlePos.Y + edgeTopRight.Y;
vertexData[vertexBaseIndex + 3].Pos.Z = particlePos.Z;
vertexData[vertexBaseIndex + 3].TexCoord.X = uvRect.RightX;
vertexData[vertexBaseIndex + 3].TexCoord.Y = uvRect.Y;
vertexData[vertexBaseIndex + 3].Color = color;
}
device.AddVertices(this.material, VertexMode.Quads, vertexData, this.vertexBuffer.Count);
}