Jypeli 10
The simple game programming library
Ray.cs
Siirry tämän tiedoston dokumentaatioon.
1
2#region MIT License
3/*
4 * Copyright (c) 2005-2008 Jonathan Mark Porter. http://physics2d.googlepages.com/
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 to
9 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10 * the Software, and to permit persons to whom the Software is furnished to do so,
11 * subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
17 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
18 * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 * OTHER DEALINGS IN THE SOFTWARE.
22 */
23#endregion
24
25
26
27
28#if UseDouble
29using Scalar = System.Double;
30#else
31using Scalar = System.Single;
32#endif
33using System;
34using System.Runtime.InteropServices;
37{
38 [StructLayout(LayoutKind.Sequential, Size = Ray.Size)]
39#if !CompactFramework && !WindowsCE && !PocketPC && !XBOX360 && !SILVERLIGHT && !WINDOWS_PHONE && !NETFX_CORE
40 [Serializable]
41 [System.ComponentModel.TypeConverter(typeof(AdvTypeConverter<Ray>))]
42#endif
43 [AdvBrowsableOrder("Origin,Direction")]
44 public struct Ray : IEquatable<Ray>
45 {
46 public const int Size = Vector2D.Size * 2;
47
48 [AdvBrowsable]
50 [AdvBrowsable]
52
53 [InstanceConstructor("Origin,Direction")]
54 public Ray(Vector2D origin, Vector2D direction)
55 {
56 this.Origin = origin;
57 this.Direction = direction;
58 }
59
61 {
62 Scalar result;
63 rect.Intersects(ref this, out result);
64 return result;
65 }
66 public Scalar Intersects(Line line)
67 {
68 Scalar result;
69 line.Intersects(ref this, out result);
70 return result;
71 }
73 {
74 Scalar result;
75 line.Intersects(ref this, out result);
76 return result;
77 }
79 {
80 Scalar result;
81 circle.Intersects(ref this, out result);
82 return result;
83 }
85 {
86 if (polygon == null) { throw new ArgumentNullException("polygon"); }
87 Scalar result;
88 polygon.Intersects(ref this, out result);
89 return result;
90 }
91
92 public void Intersects(ref BoundingRectangle rect, out Scalar result)
93 {
94 rect.Intersects(ref this, out result);
95 }
96 public void Intersects(ref Line line, out Scalar result)
97 {
98 line.Intersects(ref this, out result);
99 }
100 public void Intersects(ref LineSegment line, out Scalar result)
101 {
102 line.Intersects(ref this, out result);
103 }
104 public void Intersects(ref BoundingCircle circle, out Scalar result)
105 {
106 circle.Intersects(ref this, out result);
107 }
108 public void Intersects(ref BoundingPolygon polygon, out Scalar result)
109 {
110 if (polygon == null) { throw new ArgumentNullException("polygon"); }
111 polygon.Intersects(ref this, out result);
112 }
113
114 public override string ToString()
115 {
116 return string.Format("O: {0} D: {1}", Origin, Direction);
117 }
118 public override int GetHashCode()
119 {
121 }
122 public override bool Equals(object obj)
123 {
124 return obj is Ray && Equals((Ray)obj);
125 }
126 public bool Equals(Ray other)
127 {
128 return Equals(ref this, ref other);
129 }
130 public static bool Equals(Ray ray1, Ray ray2)
131 {
132 return Equals(ref ray1, ref ray2);
133 }
134 public static bool Equals(ref Ray ray1, ref Ray ray2)
135 {
136 return Vector2D.Equals(ref ray1.Origin, ref ray2.Origin) && Vector2D.Equals(ref ray1.Direction, ref ray2.Direction);
137 }
138
139 public static bool operator ==(Ray ray1, Ray ray2)
140 {
141 return Equals(ref ray1, ref ray2);
142 }
143 public static bool operator !=(Ray ray1, Ray ray2)
144 {
145 return !Equals(ref ray1, ref ray2);
146 }
147 }
148}
System.Single Scalar
Definition: Clamped.cs:29
static bool Intersects(Vector2D[] vertexes1, Vector2D[] vertexes2)
Scalar Intersects(Ray ray)
Definition: Line.cs:120
static void Intersects(ref Vector2D v1, ref Vector2D v2, ref Vector2D v3, ref Vector2D v4, out bool result)
Definition: LineSegment.cs:47
void Intersects(ref Line line, out Scalar result)
Definition: Ray.cs:96
static bool Equals(Ray ray1, Ray ray2)
Definition: Ray.cs:130
void Intersects(ref BoundingCircle circle, out Scalar result)
Definition: Ray.cs:104
static bool operator!=(Ray ray1, Ray ray2)
Definition: Ray.cs:143
Ray(Vector2D origin, Vector2D direction)
Definition: Ray.cs:54
Scalar Intersects(LineSegment line)
Definition: Ray.cs:72
override bool Equals(object obj)
Definition: Ray.cs:122
void Intersects(ref BoundingRectangle rect, out Scalar result)
Definition: Ray.cs:92
void Intersects(ref LineSegment line, out Scalar result)
Definition: Ray.cs:100
static bool Equals(ref Ray ray1, ref Ray ray2)
Definition: Ray.cs:134
void Intersects(ref BoundingPolygon polygon, out Scalar result)
Definition: Ray.cs:108
Scalar Intersects(BoundingPolygon polygon)
Definition: Ray.cs:84
static bool operator==(Ray ray1, Ray ray2)
Definition: Ray.cs:139
Scalar Intersects(BoundingCircle circle)
Definition: Ray.cs:78
bool Equals(Ray other)
Definition: Ray.cs:126
Vector2D Direction
Definition: Ray.cs:51
Scalar Intersects(BoundingRectangle rect)
Definition: Ray.cs:60
override string ToString()
Definition: Ray.cs:114
override int GetHashCode()
Definition: Ray.cs:118
Scalar Intersects(Line line)
Definition: Ray.cs:66
This is the Vector Class.
Definition: Vector2D.cs:50
const int Size
The Size of the class in bytes;
Definition: Vector2D.cs:59
override int GetHashCode()
Provides a unique hash code based on the member variables of this class. This should be done because ...
Definition: Vector2D.cs:1249
override bool Equals(object obj)
Compares this Vector to another object. This should be done because the equality operators (==,...
Definition: Vector2D.cs:1259