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