Jypeli
10
The simple game programming library
JypeliGroupIgnorer.cs
Siirry tämän tiedoston dokumentaatioon.
1
#region MIT License
2
/*
3
* Copyright (c) 2005-2008 Jonathan Mark Porter. http://physics2d.googlepages.com/
4
*
5
* Permission is hereby granted, free of charge, to any person obtaining a copy
6
* of this software and associated documentation files (the "Software"), to deal
7
* in the Software without restriction, including without limitation the rights to
8
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
* the Software, and to permit persons to whom the Software is furnished to do so,
10
* subject to the following conditions:
11
*
12
* The above copyright notice and this permission notice shall be
13
* included in all copies or substantial portions of the Software.
14
*
15
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
17
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20
* OTHER DEALINGS IN THE SOFTWARE.
21
*/
22
#endregion
23
24
25
26
#if UseDouble
27
using
Scalar
=
System
.Double;
28
#else
29
using
Scalar
=
System
.Single;
30
#endif
31
using
System
;
32
using
Jypeli
.
Physics
;
33
34
namespace
Jypeli
35
{
36
public
class
JypeliGroupIgnorer
:
Ignorer
37
{
41
public
int
LegacyGroup
{
get
;
set
; }
42
46
int
IgnoreMask
;
47
48
public
override
bool
BothNeeded
49
{
50
get
{
return
true
; }
51
}
52
53
public
override
bool
CanCollide
(
IPhysicsBody
thisBody,
IPhysicsBody
otherBody,
Ignorer
other )
54
{
55
JypeliGroupIgnorer
jOther = other as
JypeliGroupIgnorer
;
56
if
( jOther ==
null
)
return
true
;
57
58
return
( this.
LegacyGroup
== 0 || jOther.
LegacyGroup
== 0 ||
this
.LegacyGroup != jOther.
LegacyGroup
) && ( this.IgnoreMask & jOther.
IgnoreMask
) == 0;
59
}
60
61
public
JypeliGroupIgnorer
()
62
{
63
}
64
65
public
JypeliGroupIgnorer
( params
int
[] groups )
66
{
67
for
(
int
i = 0; i < groups.Length; i++ )
68
AddGroup
( groups[i] );
69
}
70
71
public
void
AddGroup
(
int
groupIndex )
72
{
73
if
( groupIndex > 32 )
74
throw
new
ArgumentException(
"A maximum of 32 groups is supported."
);
75
76
if
( groupIndex <= 0 )
77
throw
new
ArgumentException(
"Collision group indexes start from 1."
);
78
79
IgnoreMask
|= ( 1 << ( groupIndex - 1 ) );
80
}
81
82
public
void
RemoveGroup
(
int
groupIndex )
83
{
84
if
( groupIndex > 32 )
85
throw
new
ArgumentException(
"A maximum of 32 groups is supported."
);
86
87
if
( groupIndex <= 0 )
88
throw
new
ArgumentException(
"Collision group indexes start from 1."
);
89
90
IgnoreMask
&= (int)( uint.MaxValue - ( 1 << ( groupIndex - 1 ) ) );
91
}
92
93
public
bool
TestGroupIgnore
(
int
groupIndex )
94
{
95
if
(
LegacyGroup
!= 0 &&
LegacyGroup
== groupIndex )
96
return
true
;
97
98
if
( groupIndex > 32 )
99
throw
new
ArgumentException(
"A maximum of 32 groups is supported."
);
100
101
if
( groupIndex <= 0 )
102
throw
new
ArgumentException(
"Collision group indexes start from 1."
);
103
104
return
( this.IgnoreMask & ( 1 << ( groupIndex - 1 ) ) ) != 0;
105
}
106
}
107
}
Scalar
System.Single Scalar
Definition:
Clamped.cs:29
Jypeli.Ignorer
Base class for Collision Ignorers to impliment.
Definition:
Ignorer.cs:40
Jypeli.JypeliGroupIgnorer
Definition:
JypeliGroupIgnorer.cs:37
Jypeli.JypeliGroupIgnorer.JypeliGroupIgnorer
JypeliGroupIgnorer(params int[] groups)
Definition:
JypeliGroupIgnorer.cs:65
Jypeli.JypeliGroupIgnorer.JypeliGroupIgnorer
JypeliGroupIgnorer()
Definition:
JypeliGroupIgnorer.cs:61
Jypeli.JypeliGroupIgnorer.BothNeeded
override bool BothNeeded
Definition:
JypeliGroupIgnorer.cs:49
Jypeli.JypeliGroupIgnorer.CanCollide
override bool CanCollide(IPhysicsBody thisBody, IPhysicsBody otherBody, Ignorer other)
Definition:
JypeliGroupIgnorer.cs:53
Jypeli.JypeliGroupIgnorer.AddGroup
void AddGroup(int groupIndex)
Definition:
JypeliGroupIgnorer.cs:71
Jypeli.JypeliGroupIgnorer.IgnoreMask
int IgnoreMask
Törmäysmaski: 0 = törmää, 1 = ei törmää.
Definition:
JypeliGroupIgnorer.cs:46
Jypeli.JypeliGroupIgnorer.RemoveGroup
void RemoveGroup(int groupIndex)
Definition:
JypeliGroupIgnorer.cs:82
Jypeli.JypeliGroupIgnorer.LegacyGroup
int LegacyGroup
Vanha törmäysryhmä yhteensopivuutta varten.
Definition:
JypeliGroupIgnorer.cs:41
Jypeli.JypeliGroupIgnorer.TestGroupIgnore
bool TestGroupIgnore(int groupIndex)
Definition:
JypeliGroupIgnorer.cs:93
Jypeli.Physics.IPhysicsBody
Rajapinta fysiikkamoottorin tietämää fysiikkakappaletta varten.
Definition:
IPhysicsBody.cs:10
Jypeli.Physics
Definition:
Collision.cs:5
Jypeli
Definition:
Automobile.cs:5
System
Definition:
CFFauxAttributes.cs:29
Jypeli
Physics
Ignorers
JypeliGroupIgnorer.cs
Generoinut projektille Jypeli Tue Sep 14 2021 15:57:42
1.9.2