~ubuntu-branches/ubuntu/intrepid/blender/intrepid-updates

« back to all changes in this revision

Viewing changes to extern/bullet/BulletDynamics/ConstraintSolver/Point2PointConstraint.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Cyril Brulebois
  • Date: 2008-08-08 02:45:40 UTC
  • mfrom: (12.1.14 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080808024540-kkjp7ekfivzhuw3l
Tags: 2.46+dfsg-4
* Fix python syntax warning in import_dxf.py, which led to nasty output
  in installation/upgrade logs during byte-compilation, using a patch
  provided by the script author (Closes: #492280):
   - debian/patches/45_fix_python_syntax_warning

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
Bullet Continuous Collision Detection and Physics Library
3
 
Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
4
 
 
5
 
This software is provided 'as-is', without any express or implied warranty.
6
 
In no event will the authors be held liable for any damages arising from the use of this software.
7
 
Permission is granted to anyone to use this software for any purpose, 
8
 
including commercial applications, and to alter it and redistribute it freely, 
9
 
subject to the following restrictions:
10
 
 
11
 
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
12
 
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13
 
3. This notice may not be removed or altered from any source distribution.
14
 
*/
15
 
 
16
 
 
17
 
#include "Point2PointConstraint.h"
18
 
#include "Dynamics/RigidBody.h"
19
 
#include "Dynamics/MassProps.h"
20
 
 
21
 
 
22
 
 
23
 
 
24
 
Point2PointConstraint::Point2PointConstraint()
25
 
{
26
 
}
27
 
 
28
 
Point2PointConstraint::Point2PointConstraint(RigidBody& rbA,RigidBody& rbB, const SimdVector3& pivotInA,const SimdVector3& pivotInB)
29
 
:TypedConstraint(rbA,rbB),m_pivotInA(pivotInA),m_pivotInB(pivotInB)
30
 
{
31
 
 
32
 
}
33
 
 
34
 
 
35
 
Point2PointConstraint::Point2PointConstraint(RigidBody& rbA,const SimdVector3& pivotInA)
36
 
:TypedConstraint(rbA),m_pivotInA(pivotInA),m_pivotInB(rbA.getCenterOfMassTransform()(pivotInA))
37
 
{
38
 
        
39
 
}
40
 
 
41
 
void    Point2PointConstraint::BuildJacobian()
42
 
{
43
 
        m_appliedImpulse = 0.f;
44
 
 
45
 
        SimdVector3     normal(0,0,0);
46
 
 
47
 
        for (int i=0;i<3;i++)
48
 
        {
49
 
                normal[i] = 1;
50
 
                new (&m_jac[i]) JacobianEntry(
51
 
                        m_rbA.getCenterOfMassTransform().getBasis().transpose(),
52
 
                        m_rbB.getCenterOfMassTransform().getBasis().transpose(),
53
 
                        m_rbA.getCenterOfMassTransform()*m_pivotInA - m_rbA.getCenterOfMassPosition(),
54
 
                        m_rbB.getCenterOfMassTransform()*m_pivotInB - m_rbB.getCenterOfMassPosition(),
55
 
                        normal,
56
 
                        m_rbA.getInvInertiaDiagLocal(),
57
 
                        m_rbA.getInvMass(),
58
 
                        m_rbB.getInvInertiaDiagLocal(),
59
 
                        m_rbB.getInvMass());
60
 
                normal[i] = 0;
61
 
        }
62
 
 
63
 
}
64
 
 
65
 
void    Point2PointConstraint::SolveConstraint(SimdScalar       timeStep)
66
 
{
67
 
        SimdVector3 pivotAInW = m_rbA.getCenterOfMassTransform()*m_pivotInA;
68
 
        SimdVector3 pivotBInW = m_rbB.getCenterOfMassTransform()*m_pivotInB;
69
 
 
70
 
 
71
 
        SimdVector3 normal(0,0,0);
72
 
        
73
 
 
74
 
//      SimdVector3 angvelA = m_rbA.getCenterOfMassTransform().getBasis().transpose() * m_rbA.getAngularVelocity();
75
 
//      SimdVector3 angvelB = m_rbB.getCenterOfMassTransform().getBasis().transpose() * m_rbB.getAngularVelocity();
76
 
 
77
 
        for (int i=0;i<3;i++)
78
 
        {               
79
 
                normal[i] = 1;
80
 
                SimdScalar jacDiagABInv = 1.f / m_jac[i].getDiagonal();
81
 
 
82
 
                SimdVector3 rel_pos1 = pivotAInW - m_rbA.getCenterOfMassPosition(); 
83
 
                SimdVector3 rel_pos2 = pivotBInW - m_rbB.getCenterOfMassPosition();
84
 
                //this jacobian entry could be re-used for all iterations
85
 
                
86
 
                SimdVector3 vel1 = m_rbA.getVelocityInLocalPoint(rel_pos1);
87
 
                SimdVector3 vel2 = m_rbB.getVelocityInLocalPoint(rel_pos2);
88
 
                SimdVector3 vel = vel1 - vel2;
89
 
                
90
 
                SimdScalar rel_vel;
91
 
                rel_vel = normal.dot(vel);
92
 
 
93
 
        /*
94
 
                //velocity error (first order error)
95
 
                SimdScalar rel_vel = m_jac[i].getRelativeVelocity(m_rbA.getLinearVelocity(),angvelA,
96
 
                                                                                                                m_rbB.getLinearVelocity(),angvelB);
97
 
        */
98
 
        
99
 
                //positional error (zeroth order error)
100
 
                SimdScalar depth = -(pivotAInW - pivotBInW).dot(normal); //this is the error projected on the normal
101
 
                
102
 
                SimdScalar impulse = depth*m_setting.m_tau/timeStep  * jacDiagABInv -  m_setting.m_damping * rel_vel * jacDiagABInv;
103
 
                m_appliedImpulse+=impulse;
104
 
                SimdVector3 impulse_vector = normal * impulse;
105
 
                m_rbA.applyImpulse(impulse_vector, pivotAInW - m_rbA.getCenterOfMassPosition());
106
 
                m_rbB.applyImpulse(-impulse_vector, pivotBInW - m_rbB.getCenterOfMassPosition());
107
 
                
108
 
                normal[i] = 0;
109
 
        }
110
 
}
111
 
 
112
 
void    Point2PointConstraint::UpdateRHS(SimdScalar     timeStep)
113
 
{
114
 
 
115
 
}
116