Jypeli 10
The simple game programming library
Shapes.cs
Siirry tämän tiedoston dokumentaatioon.
1#region MIT License
2/*
3 * Copyright (c) 2009 University of Jyväskylä, Department of Mathematical
4 * Information Technology.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24#endregion
25
26/*
27 * Authors: Tero Jäntti, Tomi Karppinen, Janne Nikkanen, Rami Pasanen.
28 */
29
30using System;
31using System.ComponentModel;
32using System.Linq;
33using Microsoft.Xna.Framework.Graphics;
34
35using XnaRectangle = Microsoft.Xna.Framework.Rectangle;
36using XnaColor = Microsoft.Xna.Framework.Color;
37using System.Reflection;
38using Jypeli.Physics2d;
39using System.Collections.Generic;
40
41namespace Jypeli
42{
46 public abstract class Shape
47 {
53 public abstract bool IsUnitSize { get; }
54
58 public abstract ShapeCache Cache { get; }
59
63 public static readonly Ellipse Circle = new Ellipse();
64
68 public static readonly Ellipse Ellipse = new Ellipse();
69
73 public static readonly Rectangle Rectangle = new Rectangle();
74
78 public static readonly Triangle Triangle = new Triangle();
79
83 public static readonly Heart Heart = new Heart();
84
88 public static readonly Star Star = new Star();
89
93 public static readonly Shape Diamond = new RegularPolygon(4);
94
98 public static readonly Shape Pentagon = new RegularPolygon( 5 );
99
103 public static readonly Shape Hexagon = new RegularPolygon( 6 );
104
108 public static readonly Shape Octagon = new RegularPolygon( 8 );
109
119 public static Shape FromImage(Image image)
120 {
121 List<Vector> vertices = TextureToShapeConverter.DetectVertices(image.GetDataUInt().Cast<uint>().ToArray(), image.Width);
122
123 for (int i = 0; i < vertices.Count; i++)
124 {
125 // Nämä voisi yhdistää, mutta pidetään erillisenä luettavuuden takia.
126 vertices[i] = new Vector(vertices[i].X / image.Width, vertices[i].Y / image.Height);
127 vertices[i] -= new Vector((float)0.5, (float)0.5);
128 vertices[i] = new Vector(vertices[i].X , -vertices[i].Y); // Muoto tulee muuten ylösalaisin
129 }
130
131 Vector[] polygonVertices = new Vector[vertices.Count];
132 for (int i = 0; i < vertices.Count; i++)
133 polygonVertices[i] = new Vector(vertices[i].X, vertices[i].Y);
134
135 ShapeCache cache = new ShapeCache(polygonVertices);
136 return new Polygon(cache);
137 }
138
143 public static Shape FromString( string shapeStr )
144 {
145#if WINDOWS_STOREAPP
146 return typeof( Shape ).GetTypeInfo().GetDeclaredField( shapeStr ).GetValue( null ) as Shape;
147#else
148 Type shapeClass = typeof( Shape );
149 BindingFlags flags = BindingFlags.GetField | BindingFlags.Public | BindingFlags.Static;
150 FieldInfo selectedShape = shapeClass.GetField( shapeStr, flags );
151 return (Shape)selectedShape.GetValue( null );
152#endif
153 }
154
160 public static Shape CreateRegularPolygon( int vertexCount )
161 {
162 if ( vertexCount < 3 ) throw new ArgumentException( "You need at least 3 vertices to create a polygon!" );
163 return new RegularPolygon( vertexCount );
164 }
165
166 internal static ShapeCache CreateRegularPolygonCache( int vertexCount )
167 {
168 double angleStep = 2 * Math.PI / vertexCount;
169 Int16 centerIndex = (Int16)vertexCount;
170
171 Vector[] vertices = new Vector[vertexCount + 1];
172 IndexTriangle[] triangles = new IndexTriangle[vertexCount];
173 Int16[] outlineIndices = new Int16[vertexCount];
174
175 for ( int i = 0; i < vertexCount; i++ )
176 {
177 double a = i * angleStep;
178 vertices[i] = new Vector( 0.5 * Math.Cos( a ), 0.5 * Math.Sin( a ) );
179 outlineIndices[i] = (Int16)i;
180 }
181 vertices[centerIndex] = Vector.Zero;
182
183 for ( int i = 0; i < vertexCount - 1; i++ )
184 {
185 triangles[i] = new IndexTriangle( (Int16)i, centerIndex, (Int16)( i + 1 ) );
186 }
187 triangles[vertexCount - 1] = new IndexTriangle( (Int16)( vertexCount - 1 ), centerIndex, (Int16)0 );
188
189 return new ShapeCache( vertices, triangles, outlineIndices );
190 }
191
192#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
193 protected static bool SameSide( Vector a, Vector b, Vector p1, Vector p2 )
194 {
195 double cp1 = Vector.CrossProduct( b - a, p1 - a );
196 double cp2 = Vector.CrossProduct( b - a, p2 - a );
197 return cp1 * cp2 >= 0;
198 }
199
200 protected static bool IsInsideTriangle( Vector p, Vector a, Vector b, Vector c )
201 {
202 Vector v0 = c - a;
203 Vector v1 = b - a;
204 Vector v2 = p - a;
205
206 // Dot products between each side
207 double dot00 = Vector.DotProduct( v0, v0 );
208 double dot01 = Vector.DotProduct( v0, v1 );
209 double dot02 = Vector.DotProduct( v0, v2 );
210 double dot11 = Vector.DotProduct( v1, v1 );
211 double dot12 = Vector.DotProduct( v1, v2 );
212
213 // Barycentric coordinates
214 double invDenom = 1 / ( dot00 * dot11 - dot01 * dot01 );
215 double u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
216 double v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
217
218 return ( u >= 0 ) && ( v >= 0 ) && ( u + v < 1 );
219 }
220
221 // TODO: Benchmark these two methods and use as default that which is faster
222
223 protected bool IsInsideTriangles( Vector p )
224 {
225 for ( int i = 0; i < Cache.Triangles.Length; i++ )
226 {
230
231 if ( IsInsideTriangle( p, t1, t2, t3 ) )
232 return true;
233 }
234
235 return false;
236 }
237
238 protected bool IsInsideOutlines( Vector p )
239 {
240 Vector a, b;
241
242 for ( int i = 0; i < Cache.OutlineVertices.Length - 1; i++ )
243 {
244 a = Cache.OutlineVertices[i];
245 b = Cache.OutlineVertices[i + 1];
246
247 if ( !SameSide( a, b, p, Vector.Zero ) )
248 return false;
249 }
250
252 b = Cache.OutlineVertices[0];
253 if ( !SameSide( a, b, p, Vector.Zero ) )
254 return false;
255
256 return true;
257 }
258
259 protected bool IsInsideCircle( double x, double y, double r )
260 {
261 return x * x + y * y <= r;
262 }
263#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
264
273 public virtual bool IsInside( double x, double y )
274 {
275 if ( Cache != null && Cache.Triangles != null )
276 {
277 // Use the shape cache triangles
278 return IsInsideTriangles( new Vector( x, y ) );
279 }
280 else if ( Cache != null && Cache.OutlineVertices != null )
281 {
282 // Use the shape cache outlines
283 return IsInsideOutlines( new Vector( x, y ) );
284 }
285 else
286 {
287 // Default: use the equation for a circle
288 return IsInsideCircle( x, y, 1 );
289 }
290 }
291 }
292
296 public class Ellipse : Shape
297 {
299
301 public override ShapeCache Cache
302 {
303 get { return _cache; }
304 }
305
307 public override bool IsUnitSize { get { return true; } }
308
309 internal Ellipse() { }
310
312 public override bool IsInside( double x, double y )
313 {
314 return IsInsideCircle( x, y, 1 );
315 }
316 }
317
321 public class Rectangle : Shape
322 {
323 private static readonly Vector[] vertices = new Vector[]
324 {
325 new Vector( -0.5, -0.5 ),
326 new Vector( -0.5, 0.5 ),
327 new Vector( 0.5, -0.5 ),
328 new Vector( 0.5, 0.5 ),
329 };
330
331 private static readonly IndexTriangle[] triangles = new IndexTriangle[]
332 {
333 new IndexTriangle( 0, 1, 2 ),
334 new IndexTriangle( 2, 1, 3 ),
335 };
336
337 private static readonly Int16[] outlineIndices = new Int16[]
338 {
339 2, 3, 1, 0
340 };
341
342 private static readonly ShapeCache _cache = new ShapeCache( vertices, triangles, outlineIndices );
343
345 public override ShapeCache Cache { get { return _cache; } }
346
348 public override bool IsUnitSize { get { return true; } }
349
350 internal Rectangle() { }
351
353 public override bool IsInside( double x, double y )
354 {
355 return ( Math.Abs( x ) <= 1 && Math.Abs( y ) <= 1 );
356 }
357 }
358
362 public class Heart : Shape
363 {
364 private static readonly Vector[] vertices = new Vector[]
365 {
366 new Vector( 0, -0.5 ),
367 new Vector( 0.5, 0.2 ),
368 new Vector( 0.4, 0.4 ),
369 new Vector( 0.25, 0.5 ),
370 new Vector( 0.1, 0.4 ),
371 new Vector( 0, 0.2 ),
372 new Vector( -0.1, 0.4 ),
373 new Vector( -0.25, 0.5 ),
374 new Vector( -0.4, 0.4 ),
375 new Vector( -0.5, 0.2 )
376 };
377
378 private static readonly IndexTriangle[] triangles = new IndexTriangle[]
379 {
380 new IndexTriangle( 0, 9, 5 ),
381 new IndexTriangle( 8, 7, 6 ),
382 new IndexTriangle( 8, 6, 5 ),
383 new IndexTriangle( 9, 8, 5 ),
384 new IndexTriangle( 3, 2, 4 ),
385 new IndexTriangle( 4, 2, 5 ),
386 new IndexTriangle( 2, 1, 5 ),
387 new IndexTriangle( 5, 1, 0 ),
388 };
389
390 private static readonly ShapeCache _cache = new ShapeCache( vertices, triangles );
391
393 public override ShapeCache Cache { get { return _cache; } }
394
396 public override bool IsUnitSize { get { return true; } }
397
398 internal Heart() { }
399 }
400
404 public class Star : Shape
405 {
406 private static readonly Vector[] vertices = new Vector[]
407 {
408 new Vector( -0.5, -0.5 ),
409 new Vector( -0.25, 0 ),
410 new Vector( 0, -0.16 ),
411 new Vector( -0.5, 0.2 ),
412 new Vector( -0.15, 0.2 ),
413 new Vector( 0, 0.5 ),
414 new Vector( 0.15, 0.2 ),
415 new Vector( 0.5, 0.2 ),
416 new Vector( 0.25, 0 ),
417 new Vector( 0.5, -0.5 ),
418 };
419
420 private static readonly IndexTriangle[] triangles = new IndexTriangle[]
421 {
422 new IndexTriangle( 0, 1, 2 ),
423 new IndexTriangle( 1, 3, 4 ),
424 new IndexTriangle( 1, 5, 8 ),
425 new IndexTriangle( 8, 6, 7 ),
426 new IndexTriangle( 9, 2, 8 ),
427 new IndexTriangle( 1, 8, 2 ),
428 };
429
430 private static readonly Int16[] outlineIndices = new Int16[]
431 {
432 2, 9, 8, 7, 6, 5, 4, 3, 1, 0
433 };
434
435 private static readonly ShapeCache _cache = new ShapeCache( vertices, triangles, outlineIndices );
436
438 public override ShapeCache Cache { get { return _cache; } }
439
441 public override bool IsUnitSize { get { return true; } }
442
443 internal Star() { }
444 }
445
449 public class Triangle : Shape
450 {
451 private static readonly Vector[] vertices = new Vector[]
452 {
453 new Vector( 0, 0.5 ),
454 new Vector( 0.5, -0.5 ),
455 new Vector( -0.5, -0.5 ),
456 };
457
458 private static readonly IndexTriangle[] triangles = new IndexTriangle[]
459 {
460 new IndexTriangle( 0, 1, 2 ),
461 };
462
463 private static readonly Int16[] outlineIndices = new Int16[]
464 {
465 2, 1, 0
466 };
467
468 private static readonly ShapeCache _cache = new ShapeCache( vertices, triangles, outlineIndices );
469
471 public override ShapeCache Cache { get { return _cache; } }
472
474 public override bool IsUnitSize { get { return true; } }
475
476 internal Triangle() { }
477
479 public override bool IsInside( double x, double y )
480 {
481 return IsInsideTriangle( new Vector( x, y ), vertices[0], vertices[1], vertices[2] );
482 }
483 }
484
488 public class RaySegment : Shape
489 {
491 public override ShapeCache Cache
492 {
493 get {
494 // throw new Exception( "Cache is not defined for RaySegment" ); what is the point of crashing the game?
495 return null;
496 }
497 }
498
500 public override bool IsUnitSize { get { return false; } }
501
506
511
515 public double Length;
516
523 public RaySegment( Vector origin, Vector direction, double length )
524 {
525 this.Origin = origin;
526 this.Direction = direction;
527 this.Length = length;
528 }
529 }
530
534 public class Polygon : Shape
535 {
536 private bool isUnitSize = true;
538
544 public override bool IsUnitSize
545 {
546 get { return isUnitSize; }
547 }
548
550 public override ShapeCache Cache
551 {
552 get { return _cache; }
553 }
554
560 public Polygon( ShapeCache cache )
561 : this( cache, true )
562 {
563 }
564
571 public Polygon( ShapeCache cache, bool isUnitSize )
572 {
573 this._cache = cache;
574 this.isUnitSize = isUnitSize;
575 }
576 }
577
581 internal class RegularPolygon : Polygon
582 {
583 public int CornerCount { get; internal set; }
584 public override bool IsUnitSize { get { return true; } }
585
586 public RegularPolygon( int vertexCount )
587 : base( CreateRegularPolygonCache( vertexCount ) )
588 {
589 CornerCount = vertexCount;
590 }
591 }
592
596 [EditorBrowsable( EditorBrowsableState.Never )]
597 public struct IndexTriangle
598 {
602 public Int16 i1, i2, i3;
603
607 public IndexTriangle( Int16 i1, Int16 i2, Int16 i3 )
608 {
609 this.i1 = i1;
610 this.i2 = i2;
611 this.i3 = i3;
612 }
613
617 public IndexTriangle( int i1, int i2, int i3 )
618 : this( (Int16)i1, (Int16)i2, (Int16)i3 )
619 {
620 }
621 }
622
626 [EditorBrowsable( EditorBrowsableState.Never )]
627 public class ShapeCache
628 {
629 // The vertices are in counter-clockwise order
630 // because that is what the polygon shape of the physics
631 // engine expects.
632
636 public readonly Vector[] OutlineVertices;
637
641 public readonly Vector[] Vertices;
642
646 public readonly IndexTriangle[] Triangles;
647
654 public ShapeCache( Vector[] outlineVertices, IndexTriangle[] triangles )
655 {
656 this.Vertices = this.OutlineVertices = outlineVertices;
657 Triangles = triangles;
658 }
659
665 public ShapeCache( Vector[] outlineVertices )
666 {
667 this.Vertices = this.OutlineVertices = outlineVertices;
668 this.Triangles = null;
669 }
670
677 public ShapeCache( Vector[] vertices, IndexTriangle[] triangles, Int16[] outlineIndices )
678 {
679 Vertices = vertices;
680 Triangles = triangles;
681
682 OutlineVertices = new Vector[outlineIndices.Length];
683 for ( int i = 0; i < outlineIndices.Length; i++ )
684 {
685 OutlineVertices[i] = vertices[outlineIndices[i]];
686 }
687 }
688 }
689
694 internal class TextureBitmap : IBitmap
695 {
699 protected bool[,] bitmap;
700
706 public TextureBitmap( Texture2D texture, Predicate<XnaColor> isOpaque )
707 {
708 XnaColor[] scanline = new XnaColor[texture.Width];
709 XnaRectangle srcRect = new XnaRectangle( 0, 0, texture.Width, 1 );
710
711 bitmap = new bool[texture.Width, texture.Height];
712
713 for ( int i = 0; i < texture.Height; i++ )
714 {
715 // Scan a line from the texture
716 srcRect.Y = i;
717 texture.GetData<XnaColor>( 0, srcRect, scanline, 0, texture.Width );
718
719 for ( int j = 0; j < texture.Width; j++ )
720 {
721 // Flip the y-coordinates because the y-coordinates of the texture
722 // increase downwards.
723 bitmap[j, texture.Height - i - 1] = isOpaque( scanline[j] );
724 }
725 }
726 }
727
733 public TextureBitmap( Texture2D texture )
734 : this( texture, IsOpaqueColor )
735 {
736 }
737
741 public int Width
742 {
743 get { return bitmap.GetLength( 0 ); }
744 }
745
749 public int Height
750 {
751 get { return bitmap.GetLength( 1 ); }
752 }
753
757 public bool this[int x, int y]
758 {
759 get
760 {
761 if ( x < 0 || y < 0 || x >= Width || y >= Height ) { return false; }
762 return bitmap[x, y];
763 }
764 }
765
772 public static bool IsOpaqueColor( XnaColor c )
773 {
774 return ( c.A >= 127 );
775 }
776 }
777}
Microsoft.Xna.Framework.Rectangle XnaRectangle
Definition: Shapes.cs:35
Microsoft.Xna.Framework.Rectangle XnaRectangle
Microsoft.Xna.Framework.Color XnaColor
Ympyrä.
Definition: Shapes.cs:297
static ShapeCache _cache
Definition: Shapes.cs:298
override bool IsUnitSize
Definition: Shapes.cs:307
override ShapeCache Cache
Definition: Shapes.cs:302
override bool IsInside(double x, double y)
Onko piste muodon sisällä. Pisteen koordinaatiston origo on muodon keskellä. Muoto on kokoa 1x1 jos I...
Definition: Shapes.cs:312
Sydän.
Definition: Shapes.cs:363
override bool IsUnitSize
Definition: Shapes.cs:396
static readonly ShapeCache _cache
Definition: Shapes.cs:390
static readonly Vector[] vertices
Definition: Shapes.cs:364
override ShapeCache Cache
Definition: Shapes.cs:393
static readonly IndexTriangle[] triangles
Definition: Shapes.cs:378
Kuva.
Definition: Image.cs:30
uint[,] GetDataUInt(int ox=0, int oy=0, int w=int.MaxValue, int h=int.MaxValue)
Palalutetaan kuvan pikselit ARGB-uint[,] -taulukkona
Definition: Image.cs:237
int Width
Leveys pikseleinä.
Definition: Image.cs:374
int Height
Korkeus pikseleinä.
Definition: Image.cs:382
Monikulmio.
Definition: Shapes.cs:535
override bool IsUnitSize
If true, the shape must be scaled by the size of the object that has the shape. Typically,...
Definition: Shapes.cs:545
Polygon(ShapeCache cache, bool isUnitSize)
Monikulmio. Muodostamiseen kannattaa mielummin käyttää Shape.CreateRegularPolygon -metodia.
Definition: Shapes.cs:571
override ShapeCache Cache
Definition: Shapes.cs:551
bool isUnitSize
Definition: Shapes.cs:536
Polygon(ShapeCache cache)
Monikulmio. Muodostamiseen kannattaa mielummin käyttää Shape.CreateRegularPolygon -metodia.
Definition: Shapes.cs:560
ShapeCache _cache
Definition: Shapes.cs:537
Vector Origin
Lähtöpiste
Definition: Shapes.cs:505
override bool IsUnitSize
Definition: Shapes.cs:500
double Length
Pituus
Definition: Shapes.cs:515
override ShapeCache Cache
Definition: Shapes.cs:492
RaySegment(Vector origin, Vector direction, double length)
Säde
Definition: Shapes.cs:523
Vector Direction
Suunta
Definition: Shapes.cs:510
Suorakulmio.
Definition: Shapes.cs:322
static readonly ShapeCache _cache
Definition: Shapes.cs:342
static readonly Vector[] vertices
Definition: Shapes.cs:323
override bool IsInside(double x, double y)
Onko piste muodon sisällä. Pisteen koordinaatiston origo on muodon keskellä. Muoto on kokoa 1x1 jos I...
Definition: Shapes.cs:353
static readonly IndexTriangle[] triangles
Definition: Shapes.cs:331
override bool IsUnitSize
Definition: Shapes.cs:348
override ShapeCache Cache
Definition: Shapes.cs:345
static readonly Int16[] outlineIndices
Definition: Shapes.cs:337
Säännöllinen monikulmio.
Definition: Shapes.cs:582
override bool IsUnitSize
Definition: Shapes.cs:584
RegularPolygon(int vertexCount)
Definition: Shapes.cs:586
Sisältää valmiiksi lasketut kolmiot, joiden avulla piirtäminen on suoraviivaista.
Definition: Shapes.cs:628
readonly Vector[] OutlineVertices
Ulkoreunan verteksit, lueteltuna vastapäivään.
Definition: Shapes.cs:636
readonly IndexTriangle[] Triangles
Kolmiot, joiden avulla kuvio voidaan täyttää värillä.
Definition: Shapes.cs:646
ShapeCache(Vector[] outlineVertices, IndexTriangle[] triangles)
Luo kuvion kolmioilla, joiden avulla kuvio voidaan täyttää värillä. Kaikkien verteksien tulee olla ku...
Definition: Shapes.cs:654
ShapeCache(Vector[] outlineVertices)
Luo kuvion pelkillä reuna-vertekseillä. Kuviolle ei tule tietoa kolmioista, näin ollen sitä ei voi tä...
Definition: Shapes.cs:665
readonly Vector[] Vertices
Kaikki verteksit, ml. kolmioiden kulmapisteet.
Definition: Shapes.cs:641
ShapeCache(Vector[] vertices, IndexTriangle[] triangles, Int16[] outlineIndices)
Luo kuvion, joka voidaan piirtää täytettynä värillä.
Definition: Shapes.cs:677
Kuvio.
Definition: Shapes.cs:47
static readonly Rectangle Rectangle
Suorakulmio.
Definition: Shapes.cs:73
static readonly Ellipse Circle
Ympyrä tai ellipsi.
Definition: Shapes.cs:63
static Shape CreateRegularPolygon(int vertexCount)
Luo säännöllisen monikulmion (polygonin)
Definition: Shapes.cs:160
abstract bool IsUnitSize
If true, the shape must be scaled by the size of the object that has the shape. Typically,...
Definition: Shapes.cs:53
static readonly Triangle Triangle
Tasasivuinen kolmio.
Definition: Shapes.cs:78
abstract ShapeCache Cache
Muodon verteksit sisällään pitävä olio.
Definition: Shapes.cs:58
bool IsInsideCircle(double x, double y, double r)
Definition: Shapes.cs:259
static readonly Ellipse Ellipse
Ellipsi tai ympyrä.
Definition: Shapes.cs:68
virtual bool IsInside(double x, double y)
Onko piste muodon sisällä. Pisteen koordinaatiston origo on muodon keskellä. Muoto on kokoa 1x1 jos I...
Definition: Shapes.cs:273
static readonly Shape Octagon
Oktagoni eli kahdeksankulmio.
Definition: Shapes.cs:108
static Shape FromString(string shapeStr)
Luo muodon merkkijonosta, esim. "Circle"
Definition: Shapes.cs:143
static readonly Star Star
Tähti.
Definition: Shapes.cs:88
static bool IsInsideTriangle(Vector p, Vector a, Vector b, Vector c)
Definition: Shapes.cs:200
static readonly Shape Diamond
Timantti- / salmiakkikuvio
Definition: Shapes.cs:93
static readonly Shape Hexagon
Heksagoni eli kuusikulmio.
Definition: Shapes.cs:103
static Shape FromImage(Image image)
Luo kuvion annetusta kuvasta. Kuvassa tulee olla vain yksi yhtenäinen muoto (toisin sanoen kuvio ei v...
Definition: Shapes.cs:119
static readonly Heart Heart
Sydän.
Definition: Shapes.cs:83
static ShapeCache CreateRegularPolygonCache(int vertexCount)
Definition: Shapes.cs:166
bool IsInsideTriangles(Vector p)
Definition: Shapes.cs:223
bool IsInsideOutlines(Vector p)
Definition: Shapes.cs:238
static bool SameSide(Vector a, Vector b, Vector p1, Vector p2)
Definition: Shapes.cs:193
static readonly Shape Pentagon
Pentagoni eli viisikulmio.
Definition: Shapes.cs:98
Tähti.
Definition: Shapes.cs:405
static readonly IndexTriangle[] triangles
Definition: Shapes.cs:420
static readonly Int16[] outlineIndices
Definition: Shapes.cs:430
override bool IsUnitSize
Definition: Shapes.cs:441
static readonly ShapeCache _cache
Definition: Shapes.cs:435
override ShapeCache Cache
Definition: Shapes.cs:438
static readonly Vector[] vertices
Definition: Shapes.cs:406
Tekstuuribittikartta muotojen luomiseen tekstuureista. Sisältää tekstuurin tiedot väritaulukkona.
Definition: Shapes.cs:695
int Height
Bittikartan korkeus pikseleinä.
Definition: Shapes.cs:750
int Width
Bittikartan leveys pikseleinä.
Definition: Shapes.cs:742
bool[,] bitmap
Bittikarttadata.
Definition: Shapes.cs:699
TextureBitmap(Texture2D texture)
Luo uuden bittikartan tekstuurin pohjalta oletusläpinäkyvyysehdoilla. Ks. IsOpaqueColor
Definition: Shapes.cs:733
TextureBitmap(Texture2D texture, Predicate< XnaColor > isOpaque)
Luo uuden bittikartan tekstuurin pohjalta.
Definition: Shapes.cs:706
static bool IsOpaqueColor(XnaColor c)
Päättelee pikselin läpinäkyvyyden sen värin perusteella. Tässä tapauksessa alfa-arvon tulee olla suur...
Definition: Shapes.cs:772
Muuttaa tekstuurin yhdeksi tai useammaksi listaksi verteksejä. Mahdollistaa myös reikien sisällyttämi...
static List< Vector > DetectVertices(uint[] data, int width)
Detects the vertices of the supplied texture data. (PolygonDetectionType.Integrated)
Tasasivuinen kolmio.
Definition: Shapes.cs:450
static readonly IndexTriangle[] triangles
Definition: Shapes.cs:458
override ShapeCache Cache
Definition: Shapes.cs:471
static readonly Int16[] outlineIndices
Definition: Shapes.cs:463
override bool IsInside(double x, double y)
Onko piste muodon sisällä. Pisteen koordinaatiston origo on muodon keskellä. Muoto on kokoa 1x1 jos I...
Definition: Shapes.cs:479
static readonly Vector[] vertices
Definition: Shapes.cs:451
static readonly ShapeCache _cache
Definition: Shapes.cs:468
override bool IsUnitSize
Definition: Shapes.cs:474
Muotojen määrityksessä käytettävä kolmio.
Definition: Shapes.cs:598
Int16 i1
Kulmapisteet.
Definition: Shapes.cs:602
IndexTriangle(int i1, int i2, int i3)
Luo uuden kolmion. Parametreina kulmapisteiden indeksit lueteltuna myötäpäivään.
Definition: Shapes.cs:617
IndexTriangle(Int16 i1, Int16 i2, Int16 i3)
Luo uuden kolmion. Parametreina kulmapisteiden indeksit lueteltuna myötäpäivään.
Definition: Shapes.cs:607
2D-vektori.
Definition: Vector.cs:67
static readonly Vector Zero
Nollavektori.
Definition: Vector.cs:71
static double DotProduct(Vector left, Vector right)
Pistetulo.
Definition: Vector.cs:155
static double CrossProduct(Vector left, Vector right)
Ristitulo. Palauttaa kohtisuoraan vektoreita vastaan olevan uuden vektorin pituuden....
Definition: Vector.cs:168