Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/bullet/BulletDynamics/ConstraintSolver/btSolverBody.h @ 2845

Last change on this file since 2845 was 2662, checked in by rgrieder, 16 years ago

Merged presentation branch back to trunk.

  • Property svn:eol-style set to native
File size: 3.5 KB
RevLine 
[1963]1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
4
5This software is provided 'as-is', without any express or implied warranty.
6In no event will the authors be held liable for any damages arising from the use of this software.
7Permission is granted to anyone to use this software for any purpose,
8including commercial applications, and to alter it and redistribute it freely,
9subject to the following restrictions:
10
111. 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.
122. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
133. This notice may not be removed or altered from any source distribution.
14*/
15
16#ifndef BT_SOLVER_BODY_H
17#define BT_SOLVER_BODY_H
18
19class   btRigidBody;
20#include "LinearMath/btVector3.h"
21#include "LinearMath/btMatrix3x3.h"
22#include "BulletDynamics/Dynamics/btRigidBody.h"
23#include "LinearMath/btAlignedAllocator.h"
24#include "LinearMath/btTransformUtil.h"
25
26
[2430]27///The btSolverBody is an internal datastructure for the constraint solver. Only necessary data is packed to increase cache coherence/performance.
[1963]28ATTRIBUTE_ALIGNED16 (struct)    btSolverBody
29{
30        BT_DECLARE_ALIGNED_ALLOCATOR();
31       
[2430]32        btMatrix3x3             m_worldInvInertiaTensor;
33
[1963]34        btVector3               m_angularVelocity;
[2430]35        btVector3               m_linearVelocity;
36        btVector3               m_centerOfMassPosition;
37        btVector3               m_pushVelocity;
38        btVector3               m_turnVelocity;
39
[1963]40        float                   m_angularFactor;
41        float                   m_invMass;
42        float                   m_friction;
43        btRigidBody*    m_originalBody;
44       
45       
46        SIMD_FORCE_INLINE void  getVelocityInLocalPoint(const btVector3& rel_pos, btVector3& velocity ) const
47        {
48                velocity = m_linearVelocity + m_angularVelocity.cross(rel_pos);
49        }
50
51        //Optimization for the iterative solver: avoid calculating constant terms involving inertia, normal, relative position
52        SIMD_FORCE_INLINE void internalApplyImpulse(const btVector3& linearComponent, const btVector3& angularComponent,btScalar impulseMagnitude)
53        {
54                if (m_invMass)
55                {
56                        m_linearVelocity += linearComponent*impulseMagnitude;
57                        m_angularVelocity += angularComponent*(impulseMagnitude*m_angularFactor);
58                }
59        }
60       
61        SIMD_FORCE_INLINE void internalApplyPushImpulse(const btVector3& linearComponent, const btVector3& angularComponent,btScalar impulseMagnitude)
62        {
63                if (m_invMass)
64                {
65                        m_pushVelocity += linearComponent*impulseMagnitude;
66                        m_turnVelocity += angularComponent*(impulseMagnitude*m_angularFactor);
67                }
68        }
69
70       
71        void    writebackVelocity()
72        {
73                if (m_invMass)
74                {
75                        m_originalBody->setLinearVelocity(m_linearVelocity);
76                        m_originalBody->setAngularVelocity(m_angularVelocity);
77                       
78                        //m_originalBody->setCompanionId(-1);
79                }
80        }
81       
82
83        void    writebackVelocity(btScalar timeStep)
84        {
85                if (m_invMass)
86                {
87                        m_originalBody->setLinearVelocity(m_linearVelocity);
88                        m_originalBody->setAngularVelocity(m_angularVelocity);
89                       
90                        //correct the position/orientation based on push/turn recovery
91                        btTransform newTransform;
92                        btTransformUtil::integrateTransform(m_originalBody->getWorldTransform(),m_pushVelocity,m_turnVelocity,timeStep,newTransform);
93                        m_originalBody->setWorldTransform(newTransform);
94                       
95                        //m_originalBody->setCompanionId(-1);
96                }
97        }
98
99        void    readVelocity()
100        {
101                if (m_invMass)
102                {
103                        m_linearVelocity = m_originalBody->getLinearVelocity();
104                        m_angularVelocity = m_originalBody->getAngularVelocity();
105                }
106        }
107
108       
109
110
111};
112
113#endif //BT_SOLVER_BODY_H
114
115
Note: See TracBrowser for help on using the repository browser.