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
27using Scalar = System.Double;
28#else
29using Scalar = System.Single;
30#endif
31using System;
32using Jypeli.Physics;
33
34namespace Jypeli
35{
37 {
41 public int LegacyGroup { get; set; }
42
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
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}
System.Single Scalar
Definition: Clamped.cs:29
Base class for Collision Ignorers to impliment.
Definition: Ignorer.cs:40
JypeliGroupIgnorer(params int[] groups)
override bool CanCollide(IPhysicsBody thisBody, IPhysicsBody otherBody, Ignorer other)
void AddGroup(int groupIndex)
int IgnoreMask
Törmäysmaski: 0 = törmää, 1 = ei törmää.
void RemoveGroup(int groupIndex)
int LegacyGroup
Vanha törmäysryhmä yhteensopivuutta varten.
bool TestGroupIgnore(int groupIndex)
Rajapinta fysiikkamoottorin tietämää fysiikkakappaletta varten.
Definition: IPhysicsBody.cs:10