Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
Constraint.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 namespace SiliconStudio.Paradox.Physics
6 {
7  public class Constraint : IDisposable
8  {
9  /// <summary>
10  /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
11  /// </summary>
12  public virtual void Dispose()
13  {
14  if (InternalConstraint == null) return;
15 
16  InternalConstraint.Dispose();
17  InternalConstraint = null;
18 
19  if (RigidBodyA != null && RigidBodyA.LinkedConstraints.Contains(this))
20  {
21  RigidBodyA.LinkedConstraints.Remove(this);
22  }
23 
24  if (RigidBodyB != null && RigidBodyB.LinkedConstraints.Contains(this))
25  {
26  RigidBodyB.LinkedConstraints.Remove(this);
27  }
28  }
29 
30  /// <summary>
31  /// Gets the rigid body a.
32  /// </summary>
33  /// <value>
34  /// The rigid body a.
35  /// </value>
36  public RigidBody RigidBodyA { get; internal set; }
37  /// <summary>
38  /// Gets the rigid body b.
39  /// </summary>
40  /// <value>
41  /// The rigid body b.
42  /// </value>
43  public RigidBody RigidBodyB { get; internal set; }
44 
45  /// <summary>
46  /// Gets or sets a value indicating whether this <see cref="Constraint"/> is enabled.
47  /// </summary>
48  /// <value>
49  /// <c>true</c> if enabled; otherwise, <c>false</c>.
50  /// </value>
51  public bool Enabled
52  {
53  get { return InternalConstraint.IsEnabled; }
54  set { InternalConstraint.IsEnabled = value; }
55  }
56 
57  /// <summary>
58  /// Gets or sets the breaking impulse threshold.
59  /// </summary>
60  /// <value>
61  /// The breaking impulse threshold.
62  /// </value>
63  public float BreakingImpulseThreshold
64  {
65  get { return InternalConstraint.BreakingImpulseThreshold; }
66  set { InternalConstraint.BreakingImpulseThreshold = value; }
67  }
68 
69  bool feedbackEnabled;
70 
71  /// <summary>
72  /// Gets the applied impulse.
73  /// </summary>
74  /// <value>
75  /// The applied impulse.
76  /// </value>
77  public float AppliedImpulse
78  {
79  get
80  {
81  if (feedbackEnabled) return InternalConstraint.AppliedImpulse;
82  InternalConstraint.EnableFeedback(true);
83  feedbackEnabled = true;
84  return InternalConstraint.AppliedImpulse;
85  }
86  }
87 
88  internal PhysicsEngine Engine;
89 
90  internal BulletSharp.TypedConstraint InternalConstraint;
91  }
92 }
virtual void Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resourc...
Definition: Constraint.cs:12
using SiliconStudio.Paradox. Physics