33using Microsoft.Xna.Framework;
34using Microsoft.Xna.Framework.Graphics;
36using XnaV2 = Microsoft.Xna.Framework.Vector2;
37using XnaV3 = Microsoft.Xna.Framework.Vector3;
54 static readonly VertexPositionTexture[]
textureVertices =
new VertexPositionTexture[]
56 new VertexPositionTexture(
new XnaV3(-0.5f, 0.5f, 0),
new XnaV2(0.0f, 0.0f) ),
57 new VertexPositionTexture(
new XnaV3(-0.5f, -0.5f, 0),
new XnaV2(0.0f, 1.0f) ),
58 new VertexPositionTexture(
new XnaV3(0.5f, 0.5f, 0),
new XnaV2(1.0f, 0.0f) ),
59 new VertexPositionTexture(
new XnaV3(0.5f, -0.5f, 0),
new XnaV2(1.0f, 1.0f) )
78 ColorWriteChannels = ColorWriteChannels.None,
85 StencilFunction = CompareFunction.Equal,
86 StencilPass = StencilOperation.IncrementSaturation,
93 StencilFunction = CompareFunction.LessEqual,
94 StencilPass = StencilOperation.Keep,
102 VertexPositionTexture[] tempVertices =
new VertexPositionTexture[
textureVertices.Length];
108 float px = MathHelper.Clamp( (
float)wrapSize.
X, -1, 1 );
109 float py = MathHelper.Clamp( (
float)wrapSize.
Y, -1, 1 );
114 float left = -(float)Math.Sign( wrapSize.
X ) / 2 + 0.5f;
115 float right = left + px;
116 float top = -(float)Math.Sign( wrapSize.
Y ) / 2 + 0.5f;
117 float bottom = top + py;
119 tempVertices[0].TextureCoordinate =
new XnaV2( left, top );
120 tempVertices[1].TextureCoordinate =
new XnaV2( left, bottom );
121 tempVertices[2].TextureCoordinate =
new XnaV2( right, top );
122 tempVertices[3].TextureCoordinate =
new XnaV2( right, bottom );
135 if ( wrapSize.
X == 0 || wrapSize.
Y == 0 )
return;
140 device.RasterizerState = RasterizerState.CullClockwise;
143 device.RasterizerState = RasterizerState.CullNone;
146 device.BlendState = BlendState.AlphaBlend;
148 float wrapX = (float)Math.Abs( wrapSize.
X );
149 float wrapY = (float)Math.Abs( wrapSize.
Y );
151 if ( wrapX <= 1 && wrapY <= 1 )
158 float wx = (float)( Math.Sign( wrapSize.
X ) );
159 float wy = (float)( Math.Sign( wrapSize.
Y ) );
160 float tileW = 1 / wrapX;
161 float tileH = 1 / wrapY;
162 float topLeftX = -0.5f + 0.5f * tileW;
163 float topLeftY = 0.5f - 0.5f * tileH;
164 float partX = wrapX - (int)wrapX;
165 float partY = wrapY - (int)wrapY;
167 for (
int y = 0; y < (int)wrapY; y++ )
169 for (
int x = 0; x < (int)wrapX; x++ )
172 Matrix.CreateScale( 1 / wrapX, 1 / wrapY, 1 ) *
173 Matrix.CreateTranslation( topLeftX + x * tileW, topLeftY - y * tileH, 0 ) *
182 Matrix.CreateScale( partX, 1, 1 ) *
183 Matrix.CreateScale( 1 / wrapX, 1 / wrapY, 1 ) *
184 Matrix.CreateTranslation( -tileW / 2 + tileW * partX / 2, 0, 0 ) *
185 Matrix.CreateTranslation( topLeftX + (
int)wrapX * tileW, topLeftY - y * tileH, 0 ) *
194 for (
int x = 0; x < (int)wrapX; x++ )
198 Matrix.CreateScale( 1, partY, 1 ) *
199 Matrix.CreateScale( 1 / wrapX, 1 / wrapY, 1 ) *
200 Matrix.CreateTranslation( 0, tileH / 2 - tileH * partY / 2, 0 ) *
201 Matrix.CreateTranslation( topLeftX + x * tileW, topLeftY - (
int)wrapY * tileH, 0 ) *
211 Matrix.CreateScale( partX, partY, 1 ) *
212 Matrix.CreateScale( 1 / wrapX, 1 / wrapY, 1 ) *
213 Matrix.CreateTranslation( -tileW / 2 + tileW * partX / 2, tileH / 2 - tileH * partY / 2, 0 ) *
214 Matrix.CreateTranslation( topLeftX + (
int)wrapX * tileW, topLeftY - (
int)wrapY * tileH, 0 ) *
227 foreach ( EffectPass pass
in effect.CurrentTechnique.Passes )
231 PrimitiveType.TriangleList,
232 tempVertices, 0, tempVertices.Length,
252 throw new ArgumentException(
"The shape must have triangles" );
254 throw new Exception(
"EndDrawingInsideShape must be called before calling this function again" );
273 throw new Exception(
"BeginDrawingInsideShape must be called first" );
310 spriteBatch.Begin( SpriteSortMode.FrontToBack, BlendState.AlphaBlend, SamplerState.LinearClamp,
currentStencilState, RasterizerState.CullCounterClockwise,
null, m );
328 spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend, SamplerState.LinearClamp,
currentStencilState, RasterizerState.CullCounterClockwise,
null, m);
339 DrawImage( texture, ref textureTransformation, textureWrapSize );
377 VertexPositionColor[] colorVertices =
new VertexPositionColor[2];
378 colorVertices[0].Position =
new Vector3( (
float)segment.
Origin.
X, (
float)segment.
Origin.
Y, 0 );
380 colorVertices[1].Position =
new Vector3( (
float)endPoint.
X, (
float)endPoint.
Y, 0 );
384 effect.World = matrix;
386 foreach ( EffectPass pass
in effect.CurrentTechnique.Passes )
389 device.DrawUserPrimitives<VertexPositionColor>( PrimitiveType.LineStrip, colorVertices, 0, 1 );
411 DrawFilledShape( cache, ref matrix, color, BlendState.NonPremultiplied );
418 VertexPositionColor[] vertices =
new VertexPositionColor[cache.
Vertices.Length];
419 for (
int i = 0; i < vertices.Length; i++ )
422 vertices[i] =
new VertexPositionColor(
new XnaV3( (
float)v.
X, (
float)v.
Y, 0 ), color.
AsXnaColor() );
425 Int16[] indices =
new Int16[cache.
Triangles.Length * 3];
426 for (
int i = 0; i < cache.
Triangles.Length; i++ )
433 device.RasterizerState = RasterizerState.CullCounterClockwise;
434 device.BlendState = blendState;
437 device.RasterizerState = RasterizerState.CullNone;
442 foreach ( EffectPass pass
in effect.CurrentTechnique.Passes )
445 device.DrawUserIndexedPrimitives<VertexPositionColor>(
446 PrimitiveType.TriangleList,
447 vertices, 0, vertices.Length,
448 indices, 0, indices.Length / 3
462 if ( vertices.Length < 3 )
463 throw new ArgumentException(
"Polygon must have at least three vertices" );
467 VertexPositionColor[] colorVertices =
new VertexPositionColor[vertices.Length];
468 for (
int i = 0; i < colorVertices.Length; i++ )
471 colorVertices[i] =
new VertexPositionColor(
472 new XnaV3( (
float)p.
X, (
float)p.
Y, 0 ),
477 int n = colorVertices.Length;
478 Int16[] indices =
new Int16[2 * n];
479 for (
int i = 0; i < ( n - 1 ); i++ )
481 indices[2 * i] = (Int16)i;
482 indices[2 * i + 1] = (Int16)( i + 1 );
484 indices[2 * ( n - 1 )] = (Int16)( n - 1 );
485 indices[2 * ( n - 1 ) + 1] = (Int16)0;
489 foreach ( EffectPass pass
in effect.CurrentTechnique.Passes )
492 device.DrawUserIndexedPrimitives<VertexPositionColor>(
493 PrimitiveType.LineStrip,
494 colorVertices, 0, colorVertices.Length,
495 indices, 0, indices.Length - 1
505 VertexPositionColor[] pointVertices =
new VertexPositionColor[vertices.Length];
506 for (
int i = 0; i < pointVertices.Length; i++ )
509 pointVertices[i] =
new VertexPositionColor(
510 new XnaV3( (
float)p.
X, (
float)p.
Y, 0 ),
519 effect.World = matrix;
521 foreach ( var pass
in effect.CurrentTechnique.Passes )
524 device.DrawUserPrimitives<VertexPositionColor>(
525 PrimitiveType.LineList,
526 pointVertices, 0, pointVertices.Length
Microsoft.Xna.Framework.Vector2 XnaV2
System.Numerics.Vector2 Vector2
Microsoft.Xna.Framework.Vector3 XnaV3
DynamicSpriteFont XnaFont
static new GraphicsDevice GraphicsDevice
XNA:n grafiikkakortti.
static ScreenView Screen
Näytön dimensiot, eli koko ja reunat.
Contains graphics resources.
static void SetSamplerState()
static Effect GetColorEffect(ref Matrix worldMatrix, bool lightingEnabled)
static SpriteBatch SpriteBatch
static void ResetSamplerState()
static Effect GetTextureEffect(ref Matrix worldMatrix, Texture2D texture, bool lightingEnabled)
static BasicEffect BasicColorEffect
static FontStashSharp.Renderer FontRenderer
Luokka, joka sisältää metodeita kuvioiden ja tekstuurien piirtämiseen 2D-tasossa.
static void DrawPolygon(Vector[] vertices, ref Matrix matrix, Color color)
Piirtää monikulmion ruudulle
static DepthStencilState currentStencilState
static void DrawShape(Shape shape, ref Matrix transformation, ref Matrix textureTransformation, Image texture, Vector textureWrapSize, Color color)
Piirtää kuvion niin, että tekstuuri täyttää sen.
static readonly DepthStencilState drawShapeToStencilBufferState
static VertexPositionTexture[] MakeTextureVertices(Vector wrapSize)
static void DrawFilledShape(ShapeCache cache, ref Matrix matrix, Color color, BlendState blendState)
static void DrawImageTexture(Image texture, Matrix matrix, GraphicsDevice device, VertexPositionTexture[] tempVertices)
static void DrawRectangle(ref Matrix matrix, Color color)
Piirtää suorakulmion.
static void EndDrawingInsideShape()
Lopettaa muodon sisälle piirtämisen
static void DrawShape(Shape shape, ref Matrix matrix, Color color)
Piirtää muodon ruudulle
static void DrawImage(Image texture, ref Matrix matrix, Vector wrapSize)
Piirtää kuvan
static void DrawText(string text, ref Matrix transformation, Font font, Color color)
Piirtää tekstiä ruudulle
static void DrawRaySegment(RaySegment segment, ref Matrix matrix, Color color)
Piirtää säteen ruudulle
static readonly DepthStencilState drawAccordingToStencilBufferState
static readonly BlendState NoDrawingToScreenBufferBlendState
static void DrawVertices(Vector[] vertices, Matrix matrix, Color color)
static void BeginDrawingInsideShape(Shape shape, ref Matrix transformation)
Makes all the subsequent draw calls until EndDrawingInsideShape limit the drawing inside shape (trans...
static bool isDrawingInsideShape
static void DrawText(string text, Vector position, Font font, Color color)
Piirtää tekstiä ruudulle
static void DrawFilledShape(ShapeCache cache, ref Matrix matrix, Color color)
static readonly Int16[] textureTriangleIndices
Indices that form two triangles from the vertex array.
static void DrawText(string text, ref Matrix transformation, Font font, Color[] colors)
Piirtää tekstiä ruudulle
static readonly VertexPositionTexture[] textureVertices
Vertices that form a rectangle on which to draw textures.
static bool LightingEnabled
Onko valaistus käytössä
Sisältää näytön leveyden ja korkeuden sekä reunojen koordinaatit. Y-koordinaatti kasvaa ylöspäin....
static Vector2 ToXnaCoords(Vector position, Vector screenSize, Vector objectSize)
Muuntaa Jypelin ruutukoordinaateista XNA:n ruutukoordinaateiksi.
Vector Size
Näytön koko vektorina.
Sisältää valmiiksi lasketut kolmiot, joiden avulla piirtäminen on suoraviivaista.
readonly Vector[] OutlineVertices
Ulkoreunan verteksit, lueteltuna vastapäivään.
readonly IndexTriangle[] Triangles
Kolmiot, joiden avulla kuvio voidaan täyttää värillä.
readonly Vector[] Vertices
Kaikki verteksit, ml. kolmioiden kulmapisteet.
abstract ShapeCache Cache
Muodon verteksit sisällään pitävä olio.
Microsoft.Xna.Framework.Vector2 XnaV2
Microsoft.Xna.Framework.Matrix Matrix
static readonly Color White
Valkoinen.
static readonly Color Black
Musta.
static readonly Color Red
Punainen.
double Y
Vektorin Y-komponentti
double X
Vektorin X-komponentti.