本文整理汇总了C#中Texture.getPixel方法的典型用法代码示例。如果您正苦于以下问题:C# Texture.getPixel方法的具体用法?C# Texture.getPixel怎么用?C# Texture.getPixel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Texture
的用法示例。
在下文中一共展示了Texture.getPixel方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: drawTriange
public void drawTriange(Vertex[] vertexList, int[] index, Buffer<Color4> outPutBuffer, Buffer<float> zBuffer, Texture t)
{
Vertex v1 = vertexList[index[0]];
Vertex v2 = vertexList[index[1]];
Vertex v3 = vertexList[index[2]];
float tMinX =v1.pos.X;
float tMinY = v1.pos.Y;
float tMaxX = v1.pos.X;
float tMaxY = v1.pos.Y;
for (int i = 0; i < 3; i++)
{
Vertex v = vertexList[index[i]];
if (v.pos.X < tMinX)
tMinX = v.pos.X;
if (v.pos.Y < tMinY)
tMinY = v.pos.Y;
if (v.pos.X > tMaxX)
tMaxX = v.pos.X;
if (v.pos.Y > tMaxY)
tMaxY = v.pos.Y;
}
int minX = (int)Math.Floor(tMinX);
int maxX = (int)Math.Ceiling(tMaxX);
int minY = (int)Math.Floor(tMinY);
int maxY = (int)Math.Ceiling(tMaxY);
for (int posX = minX; posX <= maxX; posX++)
{
for (int posY = minY; posY <= maxY; posY++)
{
float posX0 = v1.pos.X;
float posX1 = v2.pos.X;
float posX2 = v3.pos.X;
float posY0 = v1.pos.Y;
float posY1 = v2.pos.Y;
float posY2 = v3.pos.Y;
float index0 = ((posY1 - posY2) * posX + (posX2 - posX1) * posY + posX1 * posY2 - posX2 * posY1) /
((posY1 - posY2) * posX0 + (posX2 - posX1) * posY0 + posX1 * posY2 - posX2 * posY1);
float index1 = ((posY2 - posY0) * posX + (posX0 - posX2) * posY + posX2 * posY0 - posX0 * posY2) /
((posY2 - posY0) * posX1 + (posX0 - posX2) * posY1 + posX2 * posY0 - posX0 * posY2);
float index2 = ((posY0 - posY1) * posX + (posX1 - posX0) * posY + posX0 * posY1 - posX1 * posY0) /
((posY0 - posY1) * posX2 + (posX1 - posX0) * posY2 + posX0 * posY1 - posX1 * posY0);
if (index0 > 0 && index1 > 0 && index2 > 0)
{
Color4 c = new Color4();
c.Alpha = v1.color.Alpha * index0 + v2.color.Alpha * index1 + v3.color.Alpha * index2;
c.Red = v1.color.Red * index0 + v2.color.Red * index1 + v3.color.Red * index2;
c.Green = v1.color.Green * index0 + v2.color.Green * index1 + v3.color.Green * index2;
c.Blue = v1.color.Blue * index0 + v2.color.Blue * index1 + v3.color.Blue * index2;
float z = v1.pos.Z * index0 + v2.pos.Z * index1 + v3.pos.Z * index2;
bool offScreen = posX < 0 || posX >= SRDevice.Device.GetWidth() || posY < 0 || posY >= SRDevice.Device.GetHeight();
if (!offScreen)
{
float curZ = zBuffer.readOneData(posX, posY);
if (z < curZ)
{
zBuffer.writeOneData(posX, posY, z);
if (t != null)
{
float u = v1.uv.X * index0 + v2.uv.X * index1 + v3.uv.X * index2;
float v = v1.uv.Y * index0 + v2.uv.Y * index1 + v3.uv.Y * index2;
Math.Min(Math.Max(u, 0.0f), 1.0f);
Math.Min(Math.Max(v, 0.0f), 1.0f);
outPutBuffer.writeOneData(posX, posY, t.getPixel(u, v));
}
else
{
outPutBuffer.writeOneData(posX, posY, c);
}
}
}
}
}
}
}