Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
CylinderColliderShape.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 using System.Collections.Generic;
5 using System.Linq;
6 using System.Text;
7 using System.Threading.Tasks;
8 
9 using SiliconStudio.Core.Mathematics;
10 using SiliconStudio.Paradox.Graphics;
11 
12 namespace SiliconStudio.Paradox.Physics
13 {
15  {
16  /// <summary>
17  /// Initializes a new instance of the <see cref="CylinderColliderShape"/> class.
18  /// </summary>
19  /// <param name="halfExtents">The half extents.</param>
20  /// <param name="upAxis">Up axis.</param>
21  public CylinderColliderShape(Vector3 halfExtents, Vector3 upAxis)
22  {
23  Type = ColliderShapeTypes.Cylinder;
24  Is2D = false; //always false for cylinders
25 
26  HalfExtents = halfExtents;
27  UpAxis = upAxis;
28 
29  Matrix rotation;
30  Vector3 scaling;
31 
32  if (upAxis == Vector3.UnitX)
33  {
34  InternalShape = new BulletSharp.CylinderShapeX(halfExtents);
35 
36  rotation = Matrix.RotationZ((float)Math.PI / 2.0f);
37  scaling = new Vector3(halfExtents.Y * 2.0f, halfExtents.X * 2.0f, halfExtents.Z * 2.0f);
38  }
39  else if (upAxis == Vector3.UnitZ)
40  {
41  InternalShape = new BulletSharp.CylinderShapeZ(halfExtents);
42 
43  rotation = Matrix.RotationX((float)Math.PI / 2.0f);
44  scaling = new Vector3(halfExtents.X * 2.0f, halfExtents.Z * 2.0f, halfExtents.Y * 2.0f);
45  }
46  else //default to Y
47  {
48  UpAxis = Vector3.UnitY;
49  InternalShape = new BulletSharp.CylinderShape(halfExtents);
50 
51  rotation = Matrix.Identity;
52  scaling = halfExtents * 2.0f;
53  }
54 
55  if (!PhysicsEngine.Singleton.CreateDebugPrimitives) return;
56  DebugPrimitive = GeometricPrimitive.Cylinder.New(PhysicsEngine.Singleton.DebugGraphicsDevice);
57  DebugPrimitiveScaling = Matrix.Scaling(scaling * 1.01f) * rotation;
58  }
59 
60  /// <summary>
61  /// Gets the half extents.
62  /// </summary>
63  /// <value>
64  /// The half extents.
65  /// </value>
66  public Vector3 HalfExtents { get; private set; }
67 
68  public float Radius
69  {
70  get
71  {
72  return ((BulletSharp.CylinderShape)InternalShape).Radius;
73  }
74  }
75 
76  /// <summary>
77  /// Gets up axis.
78  /// </summary>
79  /// <value>
80  /// Up axis.
81  /// </value>
82  public Vector3 UpAxis { get; private set; }
83  }
84 }
float Y
The Y component of the vector.
Definition: Vector3.cs:84
bool CreateDebugPrimitives
Set to true if you want the engine to create the debug primitives
CylinderColliderShape(Vector3 halfExtents, Vector3 upAxis)
Initializes a new instance of the CylinderColliderShape class.
float X
The X component of the vector.
Definition: Vector3.cs:78
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
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
float Z
The Z component of the vector.
Definition: Vector3.cs:90
Represents a 4x4 mathematical matrix.
Definition: Matrix.cs:47