Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ColliderShape.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 System;
4 
5 using SiliconStudio.Core.Mathematics;
6 using SiliconStudio.Core.Serialization.Converters;
7 using SiliconStudio.Paradox.Graphics;
8 
9 namespace SiliconStudio.Paradox.Physics
10 {
11  public class ColliderShape : IDisposable
12  {
13  /// <summary>
14  /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
15  /// </summary>
16  public virtual void Dispose()
17  {
18  if (InternalShape == null) return;
19  InternalShape.Dispose();
20  InternalShape = null;
21  }
22 
23  /// <summary>
24  /// Gets or sets the type.
25  /// </summary>
26  /// <value>
27  /// The type.
28  /// </value>
29  public ColliderShapeTypes Type { get; protected set; }
30 
31  /// <summary>
32  /// The local offset
33  /// </summary>
35 
36  /// <summary>
37  /// The local rotation
38  /// </summary>
39  public Quaternion LocalRotation = Quaternion.Identity;
40 
41  /// <summary>
42  /// Updates the local transformations, required if you change LocalOffset and/or LocalRotation.
43  /// </summary>
45  {
46  var inverseRotation = LocalRotation;
47  inverseRotation.Invert();
48 
49  PositiveCenterMatrix = Matrix.RotationQuaternion(LocalRotation) * Matrix.Translation(LocalOffset);
50  NegativeCenterMatrix = Matrix.RotationQuaternion(inverseRotation) * Matrix.Translation(-LocalOffset);
51 
52  //if we are part of a compund we should update the transformation properly
53  if (Parent == null) return;
54  var childs = Parent.InternalCompoundShape.ChildList;
55  for (var i = 0; i < childs.Count; i++)
56  {
57  if (childs[i].ChildShape == InternalShape)
58  {
59  Parent.InternalCompoundShape.UpdateChildTransform(i, PositiveCenterMatrix, true);
60  }
61  }
62  }
63 
64  /// <summary>
65  /// Gets the positive center matrix.
66  /// </summary>
67  /// <value>
68  /// The positive center matrix.
69  /// </value>
70  public Matrix PositiveCenterMatrix { get; private set; }
71 
72  /// <summary>
73  /// Gets the negative center matrix.
74  /// </summary>
75  /// <value>
76  /// The negative center matrix.
77  /// </value>
78  public Matrix NegativeCenterMatrix { get; private set; }
79 
80  /// <summary>
81  /// Gets or sets the scaling.
82  /// Make sure that you manually created and assigned an exclusive ColliderShape to the Collider otherwise since the engine shares shapes among many Colliders, all the colliders will be scaled.
83  /// Please note that this scaling has no relation to the TransformationComponent scaling.
84  /// </summary>
85  /// <value>
86  /// The scaling.
87  /// </value>
88  public Vector3 Scaling
89  {
90  get
91  {
92  return InternalShape.LocalScaling;
93  }
94  set
95  {
96  DebugPrimitiveScaling *= Matrix.Scaling(value);
97  InternalShape.LocalScaling = value;
98  }
99  }
100 
101  /// <summary>
102  /// Gets a value indicating whether the collider shape is 2D.
103  /// </summary>
104  /// <value>
105  /// <c>true</c> if [is2 d]; otherwise, <c>false</c>.
106  /// </value>
107  public bool Is2D { get; internal set; }
108 
109  internal BulletSharp.CollisionShape InternalShape;
110 
111  internal CompoundColliderShape Parent;
112 
113  internal GeometricPrimitive DebugPrimitive;
114 
115  internal Matrix DebugPrimitiveScaling;
116 
117  internal bool NeedsCustomCollisionCallback;
118  }
119 }
A geometric primitive. Use Cube, Cylinder, GeoSphere, Plane, Sphere, Teapot, Torus. See Draw+vertices to learn how to use it.
Represents a three dimensional mathematical vector.
Definition: Vector3.cs:42
static void Translation(ref Vector3 value, out Matrix result)
Creates a translation matrix using the specified offsets.
Definition: Matrix.cs:2672
void UpdateLocalTransformations()
Updates the local transformations, required if you change LocalOffset and/or LocalRotation.
Represents a four dimensional mathematical quaternion.
Definition: Quaternion.cs:45
using SiliconStudio.Paradox. Physics
virtual void Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resourc...
Represents a 4x4 mathematical matrix.
Definition: Matrix.cs:47