本文整理汇总了C#中Vertices.Scale方法的典型用法代码示例。如果您正苦于以下问题:C# Vertices.Scale方法的具体用法?C# Vertices.Scale怎么用?C# Vertices.Scale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vertices
的用法示例。
在下文中一共展示了Vertices.Scale方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TextureFromVertices
public Texture2D TextureFromVertices(Vertices vertices, MaterialType type, Color color, float materialScale)
{
// copy vertices
Vertices verts = new Vertices(vertices);
// scale to display units (i.e. pixels) for rendering to texture
Vector2 scale = ConvertUnits.ToDisplayUnits(Vector2.One);
verts.Scale(ref scale);
// translate the boundingbox center to the texture center
// because we use an orthographic projection for rendering later
AABB vertsBounds = verts.GetCollisionBox();
verts.Translate(-vertsBounds.Center);
List<Vertices> decomposedVerts;
if (!verts.IsConvex())
{
decomposedVerts = EarclipDecomposer.ConvexPartition(verts);
}
else
{
decomposedVerts = new List<Vertices>();
decomposedVerts.Add(verts);
}
List<VertexPositionColorTexture[]> verticesFill =
new List<VertexPositionColorTexture[]>(decomposedVerts.Count);
materialScale /= _materials[type].Width;
for (int i = 0; i < decomposedVerts.Count; ++i)
{
verticesFill.Add(new VertexPositionColorTexture[3 * (decomposedVerts[i].Count - 2)]);
for (int j = 0; j < decomposedVerts[i].Count - 2; ++j)
{
// fill vertices
verticesFill[i][3 * j].Position = new Vector3(decomposedVerts[i][0], 0f);
verticesFill[i][3 * j + 1].Position = new Vector3(decomposedVerts[i].NextVertex(j), 0f);
verticesFill[i][3 * j + 2].Position = new Vector3(decomposedVerts[i].NextVertex(j + 1), 0f);
verticesFill[i][3 * j].TextureCoordinate = decomposedVerts[i][0] * materialScale;
verticesFill[i][3 * j + 1].TextureCoordinate = decomposedVerts[i].NextVertex(j) * materialScale;
verticesFill[i][3 * j + 2].TextureCoordinate = decomposedVerts[i].NextVertex(j + 1) * materialScale;
verticesFill[i][3 * j].Color =
verticesFill[i][3 * j + 1].Color = verticesFill[i][3 * j + 2].Color = color;
}
}
// calculate outline
VertexPositionColor[] verticesOutline = new VertexPositionColor[2 * verts.Count];
for (int i = 0; i < verts.Count; ++i)
{
verticesOutline[2 * i].Position = new Vector3(verts[i], 0f);
verticesOutline[2 * i + 1].Position = new Vector3(verts.NextVertex(i), 0f);
verticesOutline[2 * i].Color = verticesOutline[2 * i + 1].Color = Color.Black;
}
Vector2 vertsSize = new Vector2(vertsBounds.UpperBound.X - vertsBounds.LowerBound.X,
vertsBounds.UpperBound.Y - vertsBounds.LowerBound.Y);
return RenderTexture((int)vertsSize.X, (int)vertsSize.Y,
_materials[type], verticesFill, verticesOutline);
}
示例2: Initialize
public override void Initialize()
{
//load texture that will represent the physics body
_polygonTexture = GameInstance.Content.Load<Texture2D>("Texture");
//Create an array to hold the data from the texture
uint[] data = new uint[_polygonTexture.Width*_polygonTexture.Height];
//Transfer the texture data to the array
_polygonTexture.GetData(data);
//Find the vertices that makes up the outline of the shape in the texture
_verts = PolygonTools.CreatePolygon(data, _polygonTexture.Width, _polygonTexture.Height, false);
//For now we need to scale the vertices (result is in pixels, we use meters)
Vector2 scale = new Vector2(0.07f, 0.07f);
_verts.Scale(ref scale);
//Since it is a concave polygon, we need to partition it into several smaller convex polygons
_list = BayazitDecomposer.ConvexPartition(_verts);
//Create a single body with multiple fixtures
List<Fixture> compund = FixtureFactory.CreateCompoundPolygon(World, _list, 1);
compund[0].Body.BodyType = BodyType.Dynamic;
List<Fixture> fixtures = FixtureFactory.CreateCapsule(World, 3, 1, 1);
fixtures[0].Body.Position = new Vector2(-10, 15);
fixtures[0].Body.BodyType = BodyType.Dynamic;
FixtureFactory.CreateRoundedRectangle(World, 3, 3, 0.25F, 0.25F, 2, 1, new Vector2(-10, 10));
base.Initialize();
}
示例3: GetSizeFromVertices
/// <summary>
/// Gets the size from vertices.
/// </summary>
/// <param name="vertices">The vertices.</param>
/// <returns></returns>
public static Vector2 GetSizeFromVertices( Vertices vertices )
{
Vertices verts = new Vertices( vertices );
Vector2 scale = ConvertUnits.ToDisplayUnits( Vector2.One );
verts.Scale( ref scale );
AABB vertsBounds = verts.GetAABB();
verts.Translate( -vertsBounds.Center );
return new Vector2( vertsBounds.UpperBound.X - vertsBounds.LowerBound.X,
vertsBounds.UpperBound.Y - vertsBounds.LowerBound.Y );
}
示例4: CreateFixtureFromSize
public virtual void CreateFixtureFromSize()
{
Sprite.Origin = new Vector2(Sprite.Size.X / 2, Sprite.Size.Y / 2);
Vector2 size = Sprite.Size * (Sprite.Scale);
float hx = (size.X / 2f);
float hy = (size.Y / 2f);
Vertices v = new Vertices(new Vector2[] {
new Vector2(-hx, -hy),
new Vector2(hx, -hy),
new Vector2(hx, hy),
new Vector2(-hx, hy)
});
Vector2 scale = new Vector2(Core.MetersPerPixel, Core.MetersPerPixel);
v.Scale(ref scale);
CreateFixture(new PolygonShape(v, 1));
}
示例5: ScaleToSimUnits
public static void ScaleToSimUnits(ref Vertices vertices)
{
Vector2 scale = ToSimUnits(1,0);
vertices.Scale(ref scale);
}
示例6: TextureFromVertices
public Texture2D TextureFromVertices(IEnumerable<Vector2> vertices, string textureRef, Color color, float materialScale)
{
Texture2D texture = null;
if (this.IsInitialized)
{
// copy vertices
Vertices verts = new Vertices(vertices);
// scale to display units (i.e. pixels) for rendering to texture
Vector2 scale = ConvertUnits.ToDisplayUnits(Vector2.One);
verts.Scale(ref scale);
// translate the boundingbox center to the texture center
// because we use an orthographic projection for rendering later
AABB vertsBounds = verts.GetAABB();
verts.Translate(-vertsBounds.Center);
List<Vertices> decomposedVerts;
if (!verts.IsConvex())
{
decomposedVerts = Triangulate.ConvexPartition(verts, TriangulationAlgorithm.Delauny);
}
else
{
decomposedVerts = new List<Vertices>();
decomposedVerts.Add(verts);
}
List<VertexPositionColorTexture[]> verticesFill = new List<VertexPositionColorTexture[]>(decomposedVerts.Count);
Texture2D material = ContentController.Instance.GetTextureMaterial(this.device, textureRef);
materialScale /= material.Width;
for (int i = 0; i < decomposedVerts.Count; ++i)
{
verticesFill.Add(new VertexPositionColorTexture[3 * (decomposedVerts[i].Count - 2)]);
for (int j = 0; j < decomposedVerts[i].Count - 2; ++j)
{
// fill vertices
verticesFill[i][3 * j].Position = new Vector3(decomposedVerts[i][0], 0f);
verticesFill[i][(3 * j) + 1].Position = new Vector3(decomposedVerts[i].NextVertex(j), 0f);
verticesFill[i][(3 * j) + 2].Position = new Vector3(decomposedVerts[i].NextVertex(j + 1), 0f);
verticesFill[i][3 * j].TextureCoordinate = decomposedVerts[i][0] * materialScale;
verticesFill[i][(3 * j) + 1].TextureCoordinate = decomposedVerts[i].NextVertex(j) * materialScale;
verticesFill[i][(3 * j) + 2].TextureCoordinate = decomposedVerts[i].NextVertex(j + 1) * materialScale;
verticesFill[i][3 * j].Color = verticesFill[i][(3 * j) + 1].Color = verticesFill[i][(3 * j) + 2].Color = color;
}
}
/* calculate outline
VertexPositionColor[] verticesOutline = new VertexPositionColor[2 * verts.Count];
for (int i = 0; i < verts.Count; ++i)
{
verticesOutline[2 * i].Position = new Vector3(verts[i], 0f);
verticesOutline[(2 * i) + 1].Position = new Vector3(verts.NextVertex(i), 0f);
verticesOutline[2 * i].Color = verticesOutline[(2 * i) + 1].Color = Color.Black;
}
*/
Vector2 vertsSize = new Vector2(vertsBounds.UpperBound.X - vertsBounds.LowerBound.X, vertsBounds.UpperBound.Y - vertsBounds.LowerBound.Y);
texture = this.RenderTexture((int)Math.Ceiling(vertsSize.X), (int)Math.Ceiling(vertsSize.Y), material, verticesFill);
}
return texture;
}
示例7: BreakableTextureFragments
public static List<Texture2D> BreakableTextureFragments(BreakableBody body, string textureName)
{
List<Texture2D> result = new List<Texture2D>();
if (_contentWrapper != null)
{
Vector2 scale = ConvertUnits.ToDisplayUnits(Vector2.One);
foreach (Fixture f in body.Parts)
{
Vertices v = null;
if (f.Shape is PolygonShape)
{
v = new Vertices(((PolygonShape)f.Shape).Vertices);
v.Scale(ref scale);
}
if (v != null)
{
AABB polygonBounds = v.GetAABB();
List<Vertices> decomposedVertices;
if (!v.IsConvex())
{
decomposedVertices = Triangulate.ConvexPartition(v, TriangulationAlgorithm.Bayazit);
}
else
{
decomposedVertices = new List<Vertices>();
decomposedVertices.Add(v);
}
List<VertexPositionColorTexture[]> verticesFill = new List<VertexPositionColorTexture[]>(decomposedVertices.Count);
for (int i = 0; i < decomposedVertices.Count; i++)
{
verticesFill.Add(new VertexPositionColorTexture[3 * (decomposedVertices[i].Count - 2)]);
for (int j = 0; j < decomposedVertices[i].Count - 2; j++)
{
// fill vertices
verticesFill[i][3 * j].Position = new Vector3(decomposedVertices[i][0] - polygonBounds.Center, 0f);
verticesFill[i][3 * j + 1].Position = new Vector3(decomposedVertices[i].NextVertex(j) - polygonBounds.Center, 0f);
verticesFill[i][3 * j + 2].Position = new Vector3(decomposedVertices[i].NextVertex(j + 1) - polygonBounds.Center, 0f);
verticesFill[i][3 * j].TextureCoordinate = new Vector2(decomposedVertices[i][0].X / _textureList[textureName].Width, decomposedVertices[i][0].Y / _textureList[textureName].Height - 1f);
verticesFill[i][3 * j + 1].TextureCoordinate = new Vector2(decomposedVertices[i].NextVertex(j).X / _textureList[textureName].Width, decomposedVertices[i].NextVertex(j).Y / _textureList[textureName].Height - 1f);
verticesFill[i][3 * j + 2].TextureCoordinate = new Vector2(decomposedVertices[i].NextVertex(j + 1).X / _textureList[textureName].Width, decomposedVertices[i].NextVertex(j + 1).Y / _textureList[textureName].Height - 1f);
verticesFill[i][3 * j].Color = verticesFill[i][3 * j + 1].Color = verticesFill[i][3 * j + 2].Color = Color.Transparent;
}
}
Vector2 vertsSize = new Vector2(polygonBounds.UpperBound.X - polygonBounds.LowerBound.X, polygonBounds.UpperBound.Y - polygonBounds.LowerBound.Y);
result.Add(_contentWrapper.RenderTexture((int)vertsSize.X, (int)vertsSize.Y, _textureList.ContainsKey(textureName) ? _textureList[textureName] : null, Color.White, verticesFill, new VertexPositionColor[0]));
}
else
{
result.Add(_textureList["Blank"]);
}
}
}
return result;
}
示例8: PolygonTexture
public static Texture2D PolygonTexture(Vertices vertices, string pattern, Color mainColor, Color patternColor, Color outlineColor, float materialScale)
{
if (_contentWrapper != null)
{
// copy vertices
Vertices scaledVertices = new Vertices(vertices);
// scale to display units (i.e. pixels) for rendering to texture
Vector2 scale = ConvertUnits.ToDisplayUnits(Vector2.One);
scaledVertices.Scale(ref scale);
// translate the boundingbox center to the texture center
// because we use an orthographic projection for rendering later
AABB verticesBounds = scaledVertices.GetAABB();
scaledVertices.Translate(-verticesBounds.Center);
List<Vertices> decomposedVertices;
if (!scaledVertices.IsConvex())
{
decomposedVertices = Triangulate.ConvexPartition(scaledVertices, TriangulationAlgorithm.Earclip);
}
else
{
decomposedVertices = new List<Vertices>();
decomposedVertices.Add(scaledVertices);
}
List<VertexPositionColorTexture[]> verticesFill = new List<VertexPositionColorTexture[]>(decomposedVertices.Count);
if (_textureList.ContainsKey(pattern))
{
materialScale /= _textureList[pattern].Width;
}
else
{
materialScale = 1f;
}
for (int i = 0; i < decomposedVertices.Count; i++)
{
verticesFill.Add(new VertexPositionColorTexture[3 * (decomposedVertices[i].Count - 2)]);
for (int j = 0; j < decomposedVertices[i].Count - 2; j++)
{
// fill vertices
verticesFill[i][3 * j].Position = new Vector3(decomposedVertices[i][0], 0f);
verticesFill[i][3 * j + 1].Position = new Vector3(decomposedVertices[i].NextVertex(j), 0f);
verticesFill[i][3 * j + 2].Position = new Vector3(decomposedVertices[i].NextVertex(j + 1), 0f);
verticesFill[i][3 * j].TextureCoordinate = decomposedVertices[i][0] * materialScale;
verticesFill[i][3 * j + 1].TextureCoordinate = decomposedVertices[i].NextVertex(j) * materialScale;
verticesFill[i][3 * j + 2].TextureCoordinate = decomposedVertices[i].NextVertex(j + 1) * materialScale;
verticesFill[i][3 * j].Color = verticesFill[i][3 * j + 1].Color = verticesFill[i][3 * j + 2].Color = mainColor;
}
}
// calculate outline
VertexPositionColor[] verticesOutline = new VertexPositionColor[2 * scaledVertices.Count];
for (int i = 0; i < scaledVertices.Count; i++)
{
verticesOutline[2 * i].Position = new Vector3(scaledVertices[i], 0f);
verticesOutline[2 * i + 1].Position = new Vector3(scaledVertices.NextVertex(i), 0f);
verticesOutline[2 * i].Color = verticesOutline[2 * i + 1].Color = outlineColor;
}
Vector2 vertsSize = new Vector2(verticesBounds.UpperBound.X - verticesBounds.LowerBound.X, verticesBounds.UpperBound.Y - verticesBounds.LowerBound.Y);
return _contentWrapper.RenderTexture((int)vertsSize.X, (int)vertsSize.Y, _textureList.ContainsKey(pattern) ? _textureList[pattern] : null, patternColor, verticesFill, verticesOutline);
}
return null;
}
示例9: InitOuterWall
private void InitOuterWall(Vertices vertices)
{
if (vertices.Count < 3)
{
Console.WriteLine("Too few vertices " + vertices.Count);
return;
}
Vertices drawingVertices = new Vertices(vertices);
float scale = _thickness / drawingVertices.GetRadius() + 1;
Vector2 scaleVector = new Vector2(scale);
Vector2 translation = drawingVertices.GetCentroid();
drawingVertices.Translate(-translation);
drawingVertices.Scale(ref scaleVector);
drawingVertices.Translate(translation);
_wallVerts = new VertexPositionTexture[vertices.Count * 2 + 2];
for (int i = 0; i < vertices.Count; ++i)
{
int j = i * 2;
_wallVerts[j].Position.X = vertices[i].X;
_wallVerts[j].Position.Y = vertices[i].Y;
_wallVerts[j].Position.Z = 0;
_wallVerts[j].TextureCoordinate = vertices[i] / _textureScaling;
_wallVerts[j + 1].Position.X = drawingVertices[i].X;
_wallVerts[j + 1].Position.Y = drawingVertices[i].Y;
_wallVerts[j + 1].Position.Z = 0;
_wallVerts[j + 1].TextureCoordinate = drawingVertices[i] / _textureScaling;
}
int lastIndex = vertices.Count * 2;
_wallVerts[lastIndex].Position.X = vertices[0].X;
_wallVerts[lastIndex].Position.Y = vertices[0].Y;
_wallVerts[lastIndex].Position.Z = 0;
_wallVerts[lastIndex].TextureCoordinate = vertices[0] / _textureScaling;
_wallVerts[lastIndex + 1].Position.X = drawingVertices[0].X;
_wallVerts[lastIndex + 1].Position.Y = drawingVertices[0].Y;
_wallVerts[lastIndex + 1].Position.Z = 0;
_wallVerts[lastIndex + 1].TextureCoordinate = drawingVertices[0] / _textureScaling;
}