Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
CompoundColliderShape.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using SiliconStudio.Core.Collections;
4 
5 namespace SiliconStudio.Paradox.Physics
6 {
8  {
9  /// <summary>
10  /// Initializes a new instance of the <see cref="CompoundColliderShape"/> class.
11  /// </summary>
13  {
14  Type = ColliderShapeTypes.Compound;
15  Is2D = false;
16 
17  InternalShape = InternalCompoundShape = new BulletSharp.CompoundShape();
18  }
19 
20  /// <summary>
21  /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
22  /// </summary>
23  public override void Dispose()
24  {
25  foreach (var shape in colliderShapes)
26  {
27  InternalCompoundShape.RemoveChildShape(shape.InternalShape);
28  shape.Dispose();
29  }
30  colliderShapes.Clear();
31 
32  base.Dispose();
33  }
34 
35  readonly FastList<ColliderShape> colliderShapes = new FastList<ColliderShape>();
36 
37  BulletSharp.CompoundShape internalCompoundShape;
38  internal BulletSharp.CompoundShape InternalCompoundShape
39  {
40  get
41  {
42  return internalCompoundShape;
43  }
44  set
45  {
46  InternalShape = internalCompoundShape = value;
47  }
48  }
49 
50  /// <summary>
51  /// Adds a child shape.
52  /// </summary>
53  /// <param name="shape">The shape.</param>
54  public void AddChildShape(ColliderShape shape)
55  {
56  colliderShapes.Add(shape);
57 
58  InternalCompoundShape.AddChildShape(shape.PositiveCenterMatrix, shape.InternalShape);
59 
60  shape.Parent = this;
61  }
62 
63  /// <summary>
64  /// Removes a child shape.
65  /// </summary>
66  /// <param name="shape">The shape.</param>
67  public void RemoveChildShape(ColliderShape shape)
68  {
69  colliderShapes.Remove(shape);
70 
71  InternalCompoundShape.RemoveChildShape(shape.InternalShape);
72 
73  shape.Parent = null;
74  }
75 
76  /// <summary>
77  /// Gets the <see cref="ColliderShape"/> with the specified i.
78  /// </summary>
79  /// <value>
80  /// The <see cref="ColliderShape"/>.
81  /// </value>
82  /// <param name="i">The i.</param>
83  /// <returns></returns>
84  public ColliderShape this[int i]
85  {
86  get { return colliderShapes[i]; }
87  }
88 
89  /// <summary>
90  /// Gets the count.
91  /// </summary>
92  /// <value>
93  /// The count.
94  /// </value>
95  public int Count
96  {
97  get
98  {
99  return colliderShapes.Count;
100  }
101  }
102  }
103 }
void RemoveChildShape(ColliderShape shape)
Removes a child shape.
CompoundColliderShape()
Initializes a new instance of the CompoundColliderShape class.
override void Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resourc...
void AddChildShape(ColliderShape shape)
Adds a child shape.
using SiliconStudio.Paradox. Physics