本文整理汇总了C#中IDrawDevice.PreprocessCoords方法的典型用法代码示例。如果您正苦于以下问题:C# IDrawDevice.PreprocessCoords方法的具体用法?C# IDrawDevice.PreprocessCoords怎么用?C# IDrawDevice.PreprocessCoords使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDrawDevice
的用法示例。
在下文中一共展示了IDrawDevice.PreprocessCoords方法的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)
{
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)
//.........这里部分代码省略.........
示例3: PrepareVerticesLight
protected void PrepareVerticesLight(ref VertexC1P3T2A4[] vertices, IDrawDevice device, ColorRgba mainClr, Rect uvRect, DrawTechnique tech)
{
bool perPixel = tech is LightingTechnique;
Vector3 pos = this.GameObj.Transform.Pos;
Vector3 posTemp = pos;
float scaleTemp = 1.0f;
device.PreprocessCoords(ref posTemp, ref scaleTemp);
Vector2 xDot, yDot;
float rotation = this.GameObj.Transform.Angle;
MathF.GetTransformDotVec(rotation, out xDot, out yDot);
Rect rectTemp = this.rect.Transform(this.GameObj.Transform.Scale, this.GameObj.Transform.Scale);
Vector2 edge1 = rectTemp.TopLeft;
Vector2 edge2 = rectTemp.BottomLeft;
Vector2 edge3 = rectTemp.BottomRight;
Vector2 edge4 = rectTemp.TopRight;
MathF.TransformDotVec(ref edge1, ref xDot, ref yDot);
MathF.TransformDotVec(ref edge2, ref xDot, ref yDot);
MathF.TransformDotVec(ref edge3, ref xDot, ref yDot);
MathF.TransformDotVec(ref edge4, ref xDot, ref yDot);
// Using Per-Vertex Lighting? Calculate vertex light values
Vector4[] vertexLight = null;
if (!perPixel)
{
vertexLight = new Vector4[4];
Light.GetLightAtWorldPos(pos + new Vector3(edge1), out vertexLight[0], this.vertexTranslucency);
Light.GetLightAtWorldPos(pos + new Vector3(edge2), out vertexLight[1], this.vertexTranslucency);
Light.GetLightAtWorldPos(pos + new Vector3(edge3), out vertexLight[2], this.vertexTranslucency);
Light.GetLightAtWorldPos(pos + new Vector3(edge4), out vertexLight[3], this.vertexTranslucency);
}
Vector2.Multiply(ref edge1, scaleTemp, out edge1);
Vector2.Multiply(ref edge2, scaleTemp, out edge2);
Vector2.Multiply(ref edge3, scaleTemp, out edge3);
Vector2.Multiply(ref edge4, scaleTemp, out edge4);
// Using Per-Pixel Lighting? Pass objRotation Matrix via vertex attribute.
Vector4 objRotMat = Vector4.Zero;
if (perPixel)
objRotMat = new Vector4((float)Math.Cos(-rotation), -(float)Math.Sin(-rotation), (float)Math.Sin(-rotation), (float)Math.Cos(-rotation));
if (vertices == null || vertices.Length != 4) vertices = new VertexC1P3T2A4[4];
vertices[0].Pos.X = posTemp.X + edge1.X;
vertices[0].Pos.Y = posTemp.Y + edge1.Y;
vertices[0].Pos.Z = posTemp.Z + this.VertexZOffset;
vertices[0].TexCoord.X = uvRect.X;
vertices[0].TexCoord.Y = uvRect.Y;
vertices[0].Color = mainClr;
vertices[0].Attrib = perPixel ? objRotMat : vertexLight[0];
vertices[1].Pos.X = posTemp.X + edge2.X;
vertices[1].Pos.Y = posTemp.Y + edge2.Y;
vertices[1].Pos.Z = posTemp.Z + this.VertexZOffset;
vertices[1].TexCoord.X = uvRect.X;
vertices[1].TexCoord.Y = uvRect.MaximumY;
vertices[1].Color = mainClr;
vertices[1].Attrib = perPixel ? objRotMat : vertexLight[1];
vertices[2].Pos.X = posTemp.X + edge3.X;
vertices[2].Pos.Y = posTemp.Y + edge3.Y;
vertices[2].Pos.Z = posTemp.Z + this.VertexZOffset;
vertices[2].TexCoord.X = uvRect.MaximumX;
vertices[2].TexCoord.Y = uvRect.MaximumY;
vertices[2].Color = mainClr;
vertices[2].Attrib = perPixel ? objRotMat : vertexLight[2];
vertices[3].Pos.X = posTemp.X + edge4.X;
vertices[3].Pos.Y = posTemp.Y + edge4.Y;
vertices[3].Pos.Z = posTemp.Z + this.VertexZOffset;
vertices[3].TexCoord.X = uvRect.MaximumX;
vertices[3].TexCoord.Y = uvRect.Y;
vertices[3].Color = mainClr;
vertices[3].Attrib = perPixel ? objRotMat : vertexLight[3];
}
示例4: PrepareVertices
protected void PrepareVertices(ref VertexC1P3T2[] vertices, IDrawDevice device, ColorRgba mainClr, Rect uvRect)
{
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, scaleTemp, out xDot, out yDot);
Rect rectTemp = this.rect.Transform(this.gameobj.Transform.Scale, this.gameobj.Transform.Scale);
Vector2 edge1 = rectTemp.TopLeft;
Vector2 edge2 = rectTemp.BottomLeft;
Vector2 edge3 = rectTemp.BottomRight;
Vector2 edge4 = rectTemp.TopRight;
MathF.TransformDotVec(ref edge1, ref xDot, ref yDot);
MathF.TransformDotVec(ref edge2, ref xDot, ref yDot);
MathF.TransformDotVec(ref edge3, ref xDot, ref yDot);
MathF.TransformDotVec(ref edge4, ref xDot, ref yDot);
if (vertices == null || vertices.Length != 4) vertices = new VertexC1P3T2[4];
vertices[0].SetVertex(posTemp.X + edge1.X,
posTemp.Y + edge1.Y,
posTemp.Z + this.VertexZOffset,
uvRect.X, uvRect.Y, mainClr);
vertices[1].SetVertex(posTemp.X + edge2.X,
posTemp.Y + edge2.Y,
posTemp.Z + this.VertexZOffset,
uvRect.X, uvRect.MaximumY, mainClr);
vertices[2].SetVertex(posTemp.X + edge3.X,
posTemp.Y + edge3.Y,
posTemp.Z + this.VertexZOffset,
uvRect.MaximumX, uvRect.MaximumY, mainClr);
vertices[3].SetVertex(posTemp.X + edge4.X,
posTemp.Y + edge4.Y,
posTemp.Z + this.VertexZOffset,
uvRect.MaximumX, uvRect.Y, mainClr);
if (this.pixelGrid)
{
vertices[0].Pos.X = MathF.Round(vertices[0].Pos.X);
vertices[1].Pos.X = MathF.Round(vertices[1].Pos.X);
vertices[2].Pos.X = MathF.Round(vertices[2].Pos.X);
vertices[3].Pos.X = MathF.Round(vertices[3].Pos.X);
if (MathF.RoundToInt(device.TargetSize.X) != (MathF.RoundToInt(device.TargetSize.X) / 2) * 2)
{
vertices[0].Pos.X += 0.5f;
vertices[1].Pos.X += 0.5f;
vertices[2].Pos.X += 0.5f;
vertices[3].Pos.X += 0.5f;
}
vertices[0].Pos.Y = MathF.Round(vertices[0].Pos.Y);
vertices[1].Pos.Y = MathF.Round(vertices[1].Pos.Y);
vertices[2].Pos.Y = MathF.Round(vertices[2].Pos.Y);
vertices[3].Pos.Y = MathF.Round(vertices[3].Pos.Y);
if (MathF.RoundToInt(device.TargetSize.Y) != (MathF.RoundToInt(device.TargetSize.Y) / 2) * 2)
{
vertices[0].Pos.Y += 0.5f;
vertices[1].Pos.Y += 0.5f;
vertices[2].Pos.Y += 0.5f;
vertices[3].Pos.Y += 0.5f;
}
}
}
示例5: PrepareVerticesSmooth
protected void PrepareVerticesSmooth(ref VertexC1P3T4A1[] vertices, IDrawDevice device, float curAnimFrameFade, ColorRgba mainClr, Rect uvRect, Rect uvRectNext)
{
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, scaleTemp, out xDot, out yDot);
Rect rectTemp = this.rect.Transformed(this.gameobj.Transform.Scale, this.gameobj.Transform.Scale);
Vector2 edge1 = rectTemp.TopLeft;
Vector2 edge2 = rectTemp.BottomLeft;
Vector2 edge3 = rectTemp.BottomRight;
Vector2 edge4 = rectTemp.TopRight;
MathF.TransformDotVec(ref edge1, ref xDot, ref yDot);
MathF.TransformDotVec(ref edge2, ref xDot, ref yDot);
MathF.TransformDotVec(ref edge3, ref xDot, ref yDot);
MathF.TransformDotVec(ref edge4, ref xDot, ref yDot);
if (vertices == null || vertices.Length != 4) vertices = new VertexC1P3T4A1[4];
vertices[0].Pos.X = posTemp.X + edge1.X;
vertices[0].Pos.Y = posTemp.Y + edge1.Y;
vertices[0].Pos.Z = posTemp.Z + this.VertexZOffset;
vertices[0].TexCoord.X = uvRect.X;
vertices[0].TexCoord.Y = uvRect.Y;
vertices[0].TexCoord.Z = uvRectNext.X;
vertices[0].TexCoord.W = uvRectNext.Y;
vertices[0].Color = mainClr;
vertices[0].Attrib = curAnimFrameFade;
vertices[1].Pos.X = posTemp.X + edge2.X;
vertices[1].Pos.Y = posTemp.Y + edge2.Y;
vertices[1].Pos.Z = posTemp.Z + this.VertexZOffset;
vertices[1].TexCoord.X = uvRect.X;
vertices[1].TexCoord.Y = uvRect.BottomY;
vertices[1].TexCoord.Z = uvRectNext.X;
vertices[1].TexCoord.W = uvRectNext.BottomY;
vertices[1].Color = mainClr;
vertices[1].Attrib = curAnimFrameFade;
vertices[2].Pos.X = posTemp.X + edge3.X;
vertices[2].Pos.Y = posTemp.Y + edge3.Y;
vertices[2].Pos.Z = posTemp.Z + this.VertexZOffset;
vertices[2].TexCoord.X = uvRect.RightX;
vertices[2].TexCoord.Y = uvRect.BottomY;
vertices[2].TexCoord.Z = uvRectNext.RightX;
vertices[2].TexCoord.W = uvRectNext.BottomY;
vertices[2].Color = mainClr;
vertices[2].Attrib = curAnimFrameFade;
vertices[3].Pos.X = posTemp.X + edge4.X;
vertices[3].Pos.Y = posTemp.Y + edge4.Y;
vertices[3].Pos.Z = posTemp.Z + this.VertexZOffset;
vertices[3].TexCoord.X = uvRect.RightX;
vertices[3].TexCoord.Y = uvRect.Y;
vertices[3].TexCoord.Z = uvRectNext.RightX;
vertices[3].TexCoord.W = uvRectNext.Y;
vertices[3].Color = mainClr;
vertices[3].Attrib = curAnimFrameFade;
if (this.pixelGrid)
{
vertices[0].Pos.X = MathF.Round(vertices[0].Pos.X);
vertices[1].Pos.X = MathF.Round(vertices[1].Pos.X);
vertices[2].Pos.X = MathF.Round(vertices[2].Pos.X);
vertices[3].Pos.X = MathF.Round(vertices[3].Pos.X);
if (MathF.RoundToInt(device.TargetSize.X) != (MathF.RoundToInt(device.TargetSize.X) / 2) * 2)
{
vertices[0].Pos.X += 0.5f;
vertices[1].Pos.X += 0.5f;
vertices[2].Pos.X += 0.5f;
vertices[3].Pos.X += 0.5f;
}
vertices[0].Pos.Y = MathF.Round(vertices[0].Pos.Y);
vertices[1].Pos.Y = MathF.Round(vertices[1].Pos.Y);
vertices[2].Pos.Y = MathF.Round(vertices[2].Pos.Y);
vertices[3].Pos.Y = MathF.Round(vertices[3].Pos.Y);
if (MathF.RoundToInt(device.TargetSize.Y) != (MathF.RoundToInt(device.TargetSize.Y) / 2) * 2)
{
vertices[0].Pos.Y += 0.5f;
vertices[1].Pos.Y += 0.5f;
vertices[2].Pos.Y += 0.5f;
vertices[3].Pos.Y += 0.5f;
}
}
}
示例6: 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);
}
示例7: Draw
public void Draw(IDrawDevice device)
{
if( Gid == 0 )
return;
if( Points.Count > 0 )
{
var pos = new Vector3(X, Y, 0.0f);
var scale = 1.0f;
device.PreprocessCoords(ref pos, ref scale);
foreach( var point in Points )
{
}
}
}
示例8: GetVisibleTileRect
/// <summary>
/// Determines the rectangular tile area that is visible to the specified <see cref="IDrawDevice"/>.
/// </summary>
/// <param name="device"></param>
/// <param name="input"></param>
/// <returns></returns>
public static TileOutput GetVisibleTileRect(IDrawDevice device, TileInput input)
{
TileOutput output;
// Determine the view space transform of the tilemap
Vector3 objPos = input.TilemapPos;
float objScale = input.TilemapScale;
float cameraScaleAtObj = 1.0f;
device.PreprocessCoords(ref objPos, ref cameraScaleAtObj);
objScale *= cameraScaleAtObj;
// Early-out, if so small that it might break the math behind rendering a single tile.
if (objScale <= 0.000000001f) return EmptyOutput;
// Determine transformed X and Y axis in view and world space
output.XAxisView = Vector2.UnitX;
output.YAxisView = Vector2.UnitY;
MathF.TransformCoord(ref output.XAxisView.X, ref output.XAxisView.Y, input.TilemapAngle, objScale);
MathF.TransformCoord(ref output.YAxisView.X, ref output.YAxisView.Y, input.TilemapAngle, objScale);
output.XAxisWorld = Vector2.UnitX;
output.YAxisWorld = Vector2.UnitY;
MathF.TransformCoord(ref output.XAxisWorld.X, ref output.XAxisWorld.Y, input.TilemapAngle, input.TilemapScale);
MathF.TransformCoord(ref output.YAxisWorld.X, ref output.YAxisWorld.Y, input.TilemapAngle, input.TilemapScale);
// Determine which tile is in the center of view space.
Point2 viewCenterTile = Point2.Zero;
{
// Project the view center coordinate (view space zero) into the local space of the rendered tilemap
Vector2 viewRenderStartPos = objPos.Xy;
Vector2 localViewCenter = Vector2.Zero - viewRenderStartPos;
localViewCenter = new Vector2(
Vector2.Dot(localViewCenter, output.XAxisView.Normalized),
Vector2.Dot(localViewCenter, output.YAxisView.Normalized)) / objScale;
viewCenterTile = new Point2(
(int)MathF.Floor(localViewCenter.X / input.TileSize.X),
(int)MathF.Floor(localViewCenter.Y / input.TileSize.Y));
}
// Determine the edge length of a square that is big enough to enclose the world space rect of the Camera view
float visualAngle = input.TilemapAngle - device.RefAngle;
Vector2 visualBounds = new Vector2(
device.TargetSize.Y * MathF.Abs(MathF.Sin(visualAngle)) + device.TargetSize.X * MathF.Abs(MathF.Cos(visualAngle)),
device.TargetSize.X * MathF.Abs(MathF.Sin(visualAngle)) + device.TargetSize.Y * MathF.Abs(MathF.Cos(visualAngle)));
Vector2 localVisualBounds = visualBounds / cameraScaleAtObj;
Point2 targetVisibleTileCount = new Point2(
3 + (int)MathF.Ceiling(localVisualBounds.X / (MathF.Min(input.TileSize.X, input.TileSize.Y) * input.TilemapScale)),
3 + (int)MathF.Ceiling(localVisualBounds.Y / (MathF.Min(input.TileSize.X, input.TileSize.Y) * input.TilemapScale)));
// Determine the tile indices (xy) that are visible within that rect
output.VisibleTileStart = new Point2(
MathF.Max(viewCenterTile.X - targetVisibleTileCount.X / 2, 0),
MathF.Max(viewCenterTile.Y - targetVisibleTileCount.Y / 2, 0));
Point2 tileGridEndPos = new Point2(
MathF.Min(viewCenterTile.X + targetVisibleTileCount.X / 2, input.TileCount.X),
MathF.Min(viewCenterTile.Y + targetVisibleTileCount.Y / 2, input.TileCount.Y));
output.VisibleTileCount = new Point2(
MathF.Clamp(tileGridEndPos.X - output.VisibleTileStart.X, 0, input.TileCount.X),
MathF.Clamp(tileGridEndPos.Y - output.VisibleTileStart.Y, 0, input.TileCount.Y));
// Determine start position for rendering
output.RenderOriginView = objPos + new Vector3(
output.VisibleTileStart.X * output.XAxisView * input.TileSize.X +
output.VisibleTileStart.Y * output.YAxisView * input.TileSize.Y);
output.RenderOriginWorld = input.TilemapPos + new Vector3(
output.VisibleTileStart.X * output.XAxisWorld * input.TileSize.X +
output.VisibleTileStart.Y * output.YAxisWorld * input.TileSize.Y);
return output;
}
示例9: CalcPriority
public int CalcPriority(IDrawDevice device)
{
if (!this.IsDirectional)
{
float uniformScale = this.GameObj.Transform.Scale;
Vector3 pos = this.GameObj.Transform.Pos;
float scale = 1.0f;
device.PreprocessCoords(ref pos, ref scale);
float planarDist = (this.GameObj.Transform.Pos.Xy - device.RefCoord.Xy).Length;
float rangeFactor = 1.0f / (this.range * uniformScale);
float distFactor = (MathF.Min(scale, 1.0f) * planarDist);
float spotFactor;
if (this.dir != Vector3.Zero)
spotFactor = 0.5f * (1.0f + Vector3.Dot((device.RefCoord - this.GameObj.Transform.Pos).Normalized, this.dir));
else
spotFactor = 1.0f;
return MathF.RoundToInt(1000000.0f * spotFactor * distFactor * MathF.Pow(rangeFactor, 1.5f) * MathF.Pow(1.0f / this.intensity, 0.5f));
}
else
{
return MathF.RoundToInt(100.0f * MathF.Pow(1.0f / this.intensity, 0.5f));
}
}
示例10: PrepareVertices
protected void PrepareVertices(ref VertexFormat.VertexC1P3T2[] vertices, IDrawDevice device, ColorRgba mainClr, Rect uvRect)
{
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, scaleTemp, out xDot, out yDot);
Rect rectTemp = this.rect.Transform(this.gameobj.Transform.Scale, this.gameobj.Transform.Scale);
Vector2 edge1 = rectTemp.TopLeft;
Vector2 edge2 = rectTemp.BottomLeft;
Vector2 edge3 = rectTemp.BottomRight;
Vector2 edge4 = rectTemp.TopRight;
MathF.TransformDotVec(ref edge1, ref xDot, ref yDot);
MathF.TransformDotVec(ref edge2, ref xDot, ref yDot);
MathF.TransformDotVec(ref edge3, ref xDot, ref yDot);
MathF.TransformDotVec(ref edge4, ref xDot, ref yDot);
if (vertices == null || vertices.Length != 4) vertices = new VertexFormat.VertexC1P3T2[4];
vertices[0].Pos.X = posTemp.X + edge1.X;
vertices[0].Pos.Y = posTemp.Y + edge1.Y;
vertices[0].Pos.Z = posTemp.Z + this.VertexZOffset;
vertices[0].TexCoord.X = uvRect.X;
vertices[0].TexCoord.Y = uvRect.Y;
vertices[0].Color = mainClr;
vertices[1].Pos.X = posTemp.X + edge2.X;
vertices[1].Pos.Y = posTemp.Y + edge2.Y;
vertices[1].Pos.Z = posTemp.Z + this.VertexZOffset;
vertices[1].TexCoord.X = uvRect.X;
vertices[1].TexCoord.Y = uvRect.MaxY;
vertices[1].Color = mainClr;
vertices[2].Pos.X = posTemp.X + edge3.X;
vertices[2].Pos.Y = posTemp.Y + edge3.Y;
vertices[2].Pos.Z = posTemp.Z + this.VertexZOffset;
vertices[2].TexCoord.X = uvRect.MaxX;
vertices[2].TexCoord.Y = uvRect.MaxY;
vertices[2].Color = mainClr;
vertices[3].Pos.X = posTemp.X + edge4.X;
vertices[3].Pos.Y = posTemp.Y + edge4.Y;
vertices[3].Pos.Z = posTemp.Z + this.VertexZOffset;
vertices[3].TexCoord.X = uvRect.MaxX;
vertices[3].TexCoord.Y = uvRect.Y;
vertices[3].Color = mainClr;
}
示例11: Draw
public void Draw( IDrawDevice device )
{
if( GameObj == null || !_loaded || Layers == null || Layers.Count == 0 )
return;
Vector3 tempPos = GameObj.Transform.Pos;
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;
//.........这里部分代码省略.........
示例12: 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]);
}
}
示例13: PrepareVertices
private void PrepareVertices(ref VertexC1P3T2[] vertices, IDrawDevice device, ColorRgba mainClr, Rect uvRect)
{
Transform transform = this.GameObj.Transform;
Vector3 posTemp = transform.Pos;
float scaleTemp = transform.Scale;
device.PreprocessCoords(ref posTemp, ref scaleTemp);
Vector2 xDot, yDot;
MathF.GetTransformDotVec(transform.Angle, scaleTemp, out xDot, out yDot);
Vector2 edge1 = this.rect.TopLeft;
Vector2 edge2 = this.rect.BottomLeft;
Vector2 edge3 = this.rect.BottomRight;
Vector2 edge4 = this.rect.TopRight;
MathF.TransformDotVec(ref edge1, ref xDot, ref yDot);
MathF.TransformDotVec(ref edge2, ref xDot, ref yDot);
MathF.TransformDotVec(ref edge3, ref xDot, ref yDot);
MathF.TransformDotVec(ref edge4, ref xDot, ref yDot);
float uvLeft = uvRect.X;
float uvRight = uvRect.RightX;
float uvTop = uvRect.Y;
float uvBottom = uvRect.BottomY;
if (vertices == null || vertices.Length != 4) vertices = new VertexC1P3T2[4];
vertices[0].Pos.X = posTemp.X + edge1.X;
vertices[0].Pos.Y = posTemp.Y + edge1.Y - this.height;
vertices[0].Pos.Z = posTemp.Z;
vertices[0].TexCoord.X = uvLeft;
vertices[0].TexCoord.Y = uvTop;
vertices[0].Color = mainClr;
vertices[1].Pos.X = posTemp.X + edge2.X;
vertices[1].Pos.Y = posTemp.Y + edge2.Y - this.height;
vertices[1].Pos.Z = posTemp.Z;
vertices[1].TexCoord.X = uvLeft;
vertices[1].TexCoord.Y = uvBottom;
vertices[1].Color = mainClr;
vertices[2].Pos.X = posTemp.X + edge3.X;
vertices[2].Pos.Y = posTemp.Y + edge3.Y - this.height;
vertices[2].Pos.Z = posTemp.Z;
vertices[2].TexCoord.X = uvRight;
vertices[2].TexCoord.Y = uvBottom;
vertices[2].Color = mainClr;
vertices[3].Pos.X = posTemp.X + edge4.X;
vertices[3].Pos.Y = posTemp.Y + edge4.Y - this.height;
vertices[3].Pos.Z = posTemp.Z;
vertices[3].TexCoord.X = uvRight;
vertices[3].TexCoord.Y = uvTop;
vertices[3].Color = mainClr;
// Apply depth offsets
float depthPerUnit = -this.depthScale;
if (this.isVertical)
{
// Vertical actors share the same depth offset on all four vertices
float baseDepthOffset = this.offset + transform.Pos.Y * depthPerUnit;
vertices[0].Pos.Z += baseDepthOffset;
vertices[1].Pos.Z += baseDepthOffset;
vertices[2].Pos.Z += baseDepthOffset;
vertices[3].Pos.Z += baseDepthOffset;
}
else
{
// Flat actors need to apply depth individually per vertex
float worldBaseY = transform.Pos.Y;
vertices[0].Pos.Z += this.offset + (worldBaseY + edge1.Y * transform.Scale / scaleTemp + this.height) * depthPerUnit;
vertices[1].Pos.Z += this.offset + (worldBaseY + edge2.Y * transform.Scale / scaleTemp + this.height) * depthPerUnit;
vertices[2].Pos.Z += this.offset + (worldBaseY + edge3.Y * transform.Scale / scaleTemp + this.height) * depthPerUnit;
vertices[3].Pos.Z += this.offset + (worldBaseY + edge4.Y * transform.Scale / scaleTemp + this.height) * depthPerUnit;
}
}
示例14: 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)
}
示例15: PrepareVertices
protected void PrepareVertices(ref VertexC1P3T2[] vertices, IDrawDevice device, ColorRgba mainClr, Rect uvRect)
{
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, scaleTemp, out xDot, out yDot);
Rect rectTemp = this.rect.Transformed(this.gameobj.Transform.Scale, this.gameobj.Transform.Scale);
Vector2 edge1 = rectTemp.TopLeft;
Vector2 edge2 = rectTemp.BottomLeft;
Vector2 edge3 = rectTemp.BottomRight;
Vector2 edge4 = rectTemp.TopRight;
MathF.TransformDotVec(ref edge1, ref xDot, ref yDot);
MathF.TransformDotVec(ref edge2, ref xDot, ref yDot);
MathF.TransformDotVec(ref edge3, ref xDot, ref yDot);
MathF.TransformDotVec(ref edge4, ref xDot, ref yDot);
float left = uvRect.X;
float right = uvRect.RightX;
float top = uvRect.Y;
float bottom = uvRect.BottomY;
if ((this.flipMode & FlipMode.Horizontal) != FlipMode.None)
MathF.Swap(ref left, ref right);
if ((this.flipMode & FlipMode.Vertical) != FlipMode.None)
MathF.Swap(ref top, ref bottom);
if (vertices == null || vertices.Length != 4) vertices = new VertexC1P3T2[4];
vertices[0].Pos.X = posTemp.X + edge1.X;
vertices[0].Pos.Y = posTemp.Y + edge1.Y;
vertices[0].Pos.Z = posTemp.Z + this.VertexZOffset;
vertices[0].TexCoord.X = left;
vertices[0].TexCoord.Y = top;
vertices[0].Color = mainClr;
vertices[1].Pos.X = posTemp.X + edge2.X;
vertices[1].Pos.Y = posTemp.Y + edge2.Y;
vertices[1].Pos.Z = posTemp.Z + this.VertexZOffset;
vertices[1].TexCoord.X = left;
vertices[1].TexCoord.Y = bottom;
vertices[1].Color = mainClr;
vertices[2].Pos.X = posTemp.X + edge3.X;
vertices[2].Pos.Y = posTemp.Y + edge3.Y;
vertices[2].Pos.Z = posTemp.Z + this.VertexZOffset;
vertices[2].TexCoord.X = right;
vertices[2].TexCoord.Y = bottom;
vertices[2].Color = mainClr;
vertices[3].Pos.X = posTemp.X + edge4.X;
vertices[3].Pos.Y = posTemp.Y + edge4.Y;
vertices[3].Pos.Z = posTemp.Z + this.VertexZOffset;
vertices[3].TexCoord.X = right;
vertices[3].TexCoord.Y = top;
vertices[3].Color = mainClr;
if (this.pixelGrid)
{
vertices[0].Pos.X = MathF.Round(vertices[0].Pos.X);
vertices[1].Pos.X = MathF.Round(vertices[1].Pos.X);
vertices[2].Pos.X = MathF.Round(vertices[2].Pos.X);
vertices[3].Pos.X = MathF.Round(vertices[3].Pos.X);
if (MathF.RoundToInt(device.TargetSize.X) != (MathF.RoundToInt(device.TargetSize.X) / 2) * 2)
{
vertices[0].Pos.X += 0.5f;
vertices[1].Pos.X += 0.5f;
vertices[2].Pos.X += 0.5f;
vertices[3].Pos.X += 0.5f;
}
vertices[0].Pos.Y = MathF.Round(vertices[0].Pos.Y);
vertices[1].Pos.Y = MathF.Round(vertices[1].Pos.Y);
vertices[2].Pos.Y = MathF.Round(vertices[2].Pos.Y);
vertices[3].Pos.Y = MathF.Round(vertices[3].Pos.Y);
if (MathF.RoundToInt(device.TargetSize.Y) != (MathF.RoundToInt(device.TargetSize.Y) / 2) * 2)
{
vertices[0].Pos.Y += 0.5f;
vertices[1].Pos.Y += 0.5f;
vertices[2].Pos.Y += 0.5f;
vertices[3].Pos.Y += 0.5f;
}
}
}