Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
CapsuleColliderShape.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.Paradox.Graphics;
7 
8 namespace SiliconStudio.Paradox.Physics
9 {
11  {
12  /// <summary>
13  /// Initializes a new instance of the <see cref="CapsuleColliderShape"/> class.
14  /// </summary>
15  /// <param name="is2D">if set to <c>true</c> [is2 d].</param>
16  /// <param name="radius">The radius.</param>
17  /// <param name="height">The height.</param>
18  /// <param name="upAxis">Up axis.</param>
19  public CapsuleColliderShape(bool is2D, float radius, float height, Vector3 upAxis)
20  {
21  Type = ColliderShapeTypes.Capsule;
22  Is2D = is2D;
23 
24  Radius = radius;
25  Height = height;
26  UpAxis = upAxis;
27 
28  BulletSharp.CapsuleShape shape;
29 
30  Matrix rotation;
31 
32  //http://en.wikipedia.org/wiki/Capsule_(geometry)
33  var h = radius * 2 + height;
34 
35  if (upAxis == Vector3.UnitX)
36  {
37  shape = new BulletSharp.CapsuleShapeX(radius, height);
38 
39  rotation = Matrix.RotationZ((float)Math.PI / 2.0f);
40  }
41  else if (upAxis == Vector3.UnitZ)
42  {
43  shape = new BulletSharp.CapsuleShapeZ(radius, height);
44 
45  rotation = Matrix.RotationX((float)Math.PI / 2.0f);
46  }
47  else //default to Y
48  {
49  UpAxis = Vector3.UnitY;
50  shape = new BulletSharp.CapsuleShape(radius, height);
51 
52  rotation = Matrix.Identity;
53  }
54 
55  if (Is2D)
56  {
57  InternalShape = new BulletSharp.Convex2DShape(shape) { LocalScaling = new Vector3(1, 1, 0) };
58  }
59  else
60  {
61  InternalShape = shape;
62  }
63 
64  if (!PhysicsEngine.Singleton.CreateDebugPrimitives) return;
65  DebugPrimitive = GeometricPrimitive.Capsule.New(PhysicsEngine.Singleton.DebugGraphicsDevice);
66  DebugPrimitiveScaling = Matrix.Scaling(new Vector3(radius * 2, h / 2, radius * 2) * 1.01f) * rotation;
67  }
68 
69  /// <summary>
70  /// Gets the radius.
71  /// </summary>
72  /// <value>
73  /// The radius.
74  /// </value>
75  public float Radius { get; private set; }
76 
77  /// <summary>
78  /// Gets the height.
79  /// </summary>
80  /// <value>
81  /// The height.
82  /// </value>
83  public float Height { get; private set; }
84 
85  /// <summary>
86  /// Gets up axis.
87  /// </summary>
88  /// <value>
89  /// Up axis.
90  /// </value>
91  public Vector3 UpAxis { get; private set; }
92  }
93 }
bool CreateDebugPrimitives
Set to true if you want the engine to create the debug primitives
Represents a three dimensional mathematical vector.
Definition: Vector3.cs:42
static readonly Vector3 UnitZ
The Z unit SiliconStudio.Core.Mathematics.Vector3 (0, 0, 1).
Definition: Vector3.cs:67
CapsuleColliderShape(bool is2D, float radius, float height, Vector3 upAxis)
Initializes a new instance of the CapsuleColliderShape class.
static readonly Vector3 UnitX
The X unit SiliconStudio.Core.Mathematics.Vector3 (1, 0, 0).
Definition: Vector3.cs:57
using SiliconStudio.Paradox. Physics
SiliconStudio.Core.Mathematics.Vector3 Vector3
Represents a 4x4 mathematical matrix.
Definition: Matrix.cs:47