diff options
Stage 1 of adding Darok's bulletX plugin: adding the ModifiedBulletX project (which is based on the BulletXNA project, but modified to not use XNA).
Diffstat (limited to 'libraries/ModifiedBulletX/ModifiedBulletX/Dynamics/ConstraintSolver/SolverBody.cs')
-rw-r--r-- | libraries/ModifiedBulletX/ModifiedBulletX/Dynamics/ConstraintSolver/SolverBody.cs | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/libraries/ModifiedBulletX/ModifiedBulletX/Dynamics/ConstraintSolver/SolverBody.cs b/libraries/ModifiedBulletX/ModifiedBulletX/Dynamics/ConstraintSolver/SolverBody.cs new file mode 100644 index 0000000..09b73cc --- /dev/null +++ b/libraries/ModifiedBulletX/ModifiedBulletX/Dynamics/ConstraintSolver/SolverBody.cs | |||
@@ -0,0 +1,78 @@ | |||
1 | /* | ||
2 | Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru | ||
3 | Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com | ||
4 | |||
5 | This software is provided 'as-is', without any express or implied | ||
6 | warranty. In no event will the authors be held liable for any damages | ||
7 | arising from the use of this software. | ||
8 | |||
9 | Permission is granted to anyone to use this software for any purpose, | ||
10 | including commercial applications, and to alter it and redistribute it | ||
11 | freely, subject to the following restrictions: | ||
12 | |||
13 | 1. The origin of this software must not be misrepresented; you must not | ||
14 | claim that you wrote the original software. If you use this software | ||
15 | in a product, an acknowledgment in the product documentation would be | ||
16 | appreciated but is not required. | ||
17 | 2. Altered source versions must be plainly marked as such, and must not be | ||
18 | misrepresented as being the original software. | ||
19 | 3. This notice may not be removed or altered from any source distribution. | ||
20 | */ | ||
21 | |||
22 | using System; | ||
23 | using System.Collections.Generic; | ||
24 | using System.Text; | ||
25 | using MonoXnaCompactMaths; | ||
26 | using System.Runtime.InteropServices; | ||
27 | |||
28 | namespace XnaDevRu.BulletX.Dynamics | ||
29 | { | ||
30 | public class SolverBody | ||
31 | { | ||
32 | private Vector3 _centerOfMassPosition = new Vector3(); | ||
33 | private Vector3 _linearVelocity = new Vector3(); | ||
34 | private Vector3 _angularVelocity = new Vector3(); | ||
35 | private RigidBody _originalBody = null; | ||
36 | private float _invMass; | ||
37 | private float _friction; | ||
38 | private float _angularFactor; | ||
39 | |||
40 | public Vector3 CenterOfMassPosition { get { return _centerOfMassPosition; } set { _centerOfMassPosition = value; } } | ||
41 | public Vector3 LinearVelocity { get { return _linearVelocity; } set { _linearVelocity = value; } } | ||
42 | public Vector3 AngularVelocity { get { return _angularVelocity; } set { _angularVelocity = value; } } | ||
43 | public RigidBody OriginalBody { get { return _originalBody; } set { _originalBody = value; } } | ||
44 | public float InvMass { get { return _invMass; } set { _invMass = value; } } | ||
45 | public float Friction { get { return _friction; } set { _friction = value; } } | ||
46 | public float AngularFactor { get { return _angularFactor; } set { _angularFactor = value; } } | ||
47 | |||
48 | public void GetVelocityInLocalPoint(Vector3 relPos, out Vector3 velocity) | ||
49 | { | ||
50 | velocity = _linearVelocity + Vector3.Cross(_angularVelocity, relPos); | ||
51 | } | ||
52 | |||
53 | public void WriteBackVelocity() | ||
54 | { | ||
55 | if (_invMass != 0) | ||
56 | { | ||
57 | _originalBody.LinearVelocity = _linearVelocity; | ||
58 | _originalBody.AngularVelocity = _angularVelocity; | ||
59 | } | ||
60 | } | ||
61 | |||
62 | public void ReadVelocity() | ||
63 | { | ||
64 | if (_invMass != 0) | ||
65 | { | ||
66 | _linearVelocity = _originalBody.LinearVelocity; | ||
67 | _angularVelocity = _originalBody.AngularVelocity; | ||
68 | } | ||
69 | } | ||
70 | |||
71 | //Optimization for the iterative solver: avoid calculating constant terms involving inertia, normal, relative position | ||
72 | internal void ApplyImpulse(Vector3 linearComponent, Vector3 angularComponent, float impulseMagnitude) | ||
73 | { | ||
74 | _linearVelocity += linearComponent * impulseMagnitude; | ||
75 | _angularVelocity += angularComponent * impulseMagnitude * _angularFactor; | ||
76 | } | ||
77 | } | ||
78 | } | ||