52 static readonly VertexPositionTexture[]
textureVertices =
new VertexPositionTexture[]
54 new VertexPositionTexture(
new XnaV3(-0.5f, 0.5f, 0),
new XnaV2(0.0f, 0.0f) ),
55 new VertexPositionTexture(
new XnaV3(-0.5f, -0.5f, 0),
new XnaV2(0.0f, 1.0f) ),
56 new VertexPositionTexture(
new XnaV3(0.5f, 0.5f, 0),
new XnaV2(1.0f, 0.0f) ),
57 new VertexPositionTexture(
new XnaV3(0.5f, -0.5f, 0),
new XnaV2(1.0f, 1.0f) )
73 ColorWriteChannels = ColorWriteChannels.None,
80 StencilFunction = CompareFunction.Equal,
81 StencilPass = StencilOperation.IncrementSaturation,
88 StencilFunction = CompareFunction.LessEqual,
89 StencilPass = StencilOperation.Keep,
97 VertexPositionTexture[] tempVertices =
new VertexPositionTexture[
textureVertices.Length];
103 float px = MathHelper.Clamp( (
float)wrapSize.
X, -1, 1 );
104 float py = MathHelper.Clamp( (
float)wrapSize.
Y, -1, 1 );
109 float left = -(float)Math.Sign( wrapSize.
X ) / 2 + 0.5f;
110 float right = left + px;
111 float top = -(float)Math.Sign( wrapSize.
Y ) / 2 + 0.5f;
112 float bottom = top + py;
114 tempVertices[0].TextureCoordinate =
new XnaV2( left, top );
115 tempVertices[1].TextureCoordinate =
new XnaV2( left, bottom );
116 tempVertices[2].TextureCoordinate =
new XnaV2( right, top );
117 tempVertices[3].TextureCoordinate =
new XnaV2( right, bottom );
124 if ( wrapSize.
X == 0 || wrapSize.
Y == 0 )
return;
129 device.RasterizerState = RasterizerState.CullClockwise;
132 device.RasterizerState = RasterizerState.CullNone;
135 device.BlendState = BlendState.AlphaBlend;
137 float wrapX = (float)Math.Abs( wrapSize.
X );
138 float wrapY = (float)Math.Abs( wrapSize.
Y );
140 if ( wrapX <= 1 && wrapY <= 1 )
147 float wx = (float)( Math.Sign( wrapSize.
X ) );
148 float wy = (float)( Math.Sign( wrapSize.
Y ) );
149 float tileW = 1 / wrapX;
150 float tileH = 1 / wrapY;
151 float topLeftX = -0.5f + 0.5f * tileW;
152 float topLeftY = 0.5f - 0.5f * tileH;
153 float partX = wrapX - (int)wrapX;
154 float partY = wrapY - (int)wrapY;
156 for (
int y = 0; y < (int)wrapY; y++ )
158 for (
int x = 0; x < (int)wrapX; x++ )
161 Matrix.CreateScale( 1 / wrapX, 1 / wrapY, 1 ) *
162 Matrix.CreateTranslation( topLeftX + x * tileW, topLeftY - y * tileH, 0 ) *
171 Matrix.CreateScale( partX, 1, 1 ) *
172 Matrix.CreateScale( 1 / wrapX, 1 / wrapY, 1 ) *
173 Matrix.CreateTranslation( -tileW / 2 + tileW * partX / 2, 0, 0 ) *
174 Matrix.CreateTranslation( topLeftX + (
int)wrapX * tileW, topLeftY - y * tileH, 0 ) *
183 for (
int x = 0; x < (int)wrapX; x++ )
187 Matrix.CreateScale( 1, partY, 1 ) *
188 Matrix.CreateScale( 1 / wrapX, 1 / wrapY, 1 ) *
189 Matrix.CreateTranslation( 0, tileH / 2 - tileH * partY / 2, 0 ) *
190 Matrix.CreateTranslation( topLeftX + x * tileW, topLeftY - (
int)wrapY * tileH, 0 ) *
200 Matrix.CreateScale( partX, partY, 1 ) *
201 Matrix.CreateScale( 1 / wrapX, 1 / wrapY, 1 ) *
202 Matrix.CreateTranslation( -tileW / 2 + tileW * partX / 2, tileH / 2 - tileH * partY / 2, 0 ) *
203 Matrix.CreateTranslation( topLeftX + (
int)wrapX * tileW, topLeftY - (
int)wrapY * tileH, 0 ) *
216 foreach ( EffectPass pass
in effect.CurrentTechnique.Passes )
220 PrimitiveType.TriangleList,
221 tempVertices, 0, tempVertices.Length,
241 throw new ArgumentException(
"The shape must have triangles" );
243 throw new Exception(
"EndDrawingInsideShape must be called before calling this function again" );
259 throw new Exception(
"BeginDrawingInsideShape must be called first" );
274 Vector2 textSize = font.
XnaFont.MeasureString(text);
296 spriteBatch.Begin( SpriteSortMode.FrontToBack, BlendState.AlphaBlend, SamplerState.LinearClamp,
currentStencilState, RasterizerState.CullCounterClockwise,
null, m );
307 DrawImage( texture, ref textureTransformation, textureWrapSize );
333 VertexPositionColor[] colorVertices =
new VertexPositionColor[2];
334 colorVertices[0].Position =
new Vector3( (
float)segment.
Origin.
X, (
float)segment.
Origin.
Y, 0 );
336 colorVertices[1].Position =
new Vector3( (
float)endPoint.
X, (
float)endPoint.
Y, 0 );
340 effect.World = matrix;
342 foreach ( EffectPass pass
in effect.CurrentTechnique.Passes )
345 device.DrawUserPrimitives<VertexPositionColor>( PrimitiveType.LineStrip, colorVertices, 0, 1 );
367 DrawFilledShape( cache, ref matrix, color, BlendState.NonPremultiplied );
374 VertexPositionColor[] vertices =
new VertexPositionColor[cache.
Vertices.Length];
375 for (
int i = 0; i < vertices.Length; i++ )
378 vertices[i] =
new VertexPositionColor(
new XnaV3( (
float)v.
X, (
float)v.
Y, 0 ), color.
AsXnaColor() );
381 Int16[] indices =
new Int16[cache.
Triangles.Length * 3];
382 for (
int i = 0; i < cache.
Triangles.Length; i++ )
389 device.RasterizerState = RasterizerState.CullCounterClockwise;
390 device.BlendState = blendState;
393 device.RasterizerState = RasterizerState.CullNone;
398 foreach ( EffectPass pass
in effect.CurrentTechnique.Passes )
401 device.DrawUserIndexedPrimitives<VertexPositionColor>(
402 PrimitiveType.TriangleList,
403 vertices, 0, vertices.Length,
404 indices, 0, indices.Length / 3
412 if ( vertices.Length < 3 )
413 throw new ArgumentException(
"Polygon must have at least three vertices" );
417 VertexPositionColor[] colorVertices =
new VertexPositionColor[vertices.Length];
418 for (
int i = 0; i < colorVertices.Length; i++ )
421 colorVertices[i] =
new VertexPositionColor(
422 new XnaV3( (
float)p.
X, (
float)p.
Y, 0 ),
427 int n = colorVertices.Length;
428 Int16[] indices =
new Int16[2 * n];
429 for (
int i = 0; i < ( n - 1 ); i++ )
431 indices[2 * i] = (Int16)i;
432 indices[2 * i + 1] = (Int16)( i + 1 );
434 indices[2 * ( n - 1 )] = (Int16)( n - 1 );
435 indices[2 * ( n - 1 ) + 1] = (Int16)0;
439 foreach ( EffectPass pass
in effect.CurrentTechnique.Passes )
442 device.DrawUserIndexedPrimitives<VertexPositionColor>(
443 PrimitiveType.LineStrip,
444 colorVertices, 0, colorVertices.Length,
445 indices, 0, indices.Length - 1
455 VertexPositionColor[] pointVertices =
new VertexPositionColor[vertices.Length];
456 for (
int i = 0; i < pointVertices.Length; i++ )
459 pointVertices[i] =
new VertexPositionColor(
460 new XnaV3( (
float)p.
X, (
float)p.
Y, 0 ),
469 effect.World = matrix;
471 foreach ( var pass
in effect.CurrentTechnique.Passes )
474 device.DrawUserPrimitives<VertexPositionColor>(
475 PrimitiveType.LineList,
476 pointVertices, 0, pointVertices.Length