Changeset 13041 for OpenSceneGraph/trunk/src/osgParticle/BounceOperator.cpp
- Timestamp:
- 03/21/12 18:36:20 (15 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgParticle/BounceOperator.cpp
r12292 r13041 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2010 Robert Osfield 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2010 Robert Osfield 2 2 * 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 5 5 * (at your option) any later version. The full license is in LICENSE file 6 6 * included with this distribution, and on the openscenegraph.org website. 7 * 7 * 8 8 * This library is distributed in the hope that it will be useful, 9 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 11 * OpenSceneGraph Public License for more details. 12 12 */ … … 24 24 float distance = domain.plane.distance( P->getPosition() ); 25 25 if ( distance*domain.plane.distance(nextpos)>=0 ) return; 26 26 27 27 osg::Vec3 normal = domain.plane.getNormal(); 28 28 float nv = normal * P->getVelocity(); 29 29 osg::Vec3 hitPoint = P->getPosition() - P->getVelocity() * (distance / nv); 30 30 31 31 float upos = (hitPoint - domain.v1) * domain.s1; 32 32 float vpos = (hitPoint - domain.v1) * domain.s2; 33 33 if ( upos<0.0f || vpos<0.0f || (upos + vpos)>1.0f ) return; 34 34 35 35 // Compute tangential and normal components of velocity 36 36 osg::Vec3 vn = normal * nv; 37 37 osg::Vec3 vt = P->getVelocity() - vn; 38 38 39 39 // Compute new velocity 40 40 if ( vt.length2()<=_cutoff ) P->setVelocity( vt - vn*_resilience ); … … 47 47 float distance = domain.plane.distance( P->getPosition() ); 48 48 if ( distance*domain.plane.distance(nextpos)>=0 ) return; 49 49 50 50 osg::Vec3 normal = domain.plane.getNormal(); 51 51 float nv = normal * P->getVelocity(); 52 52 osg::Vec3 hitPoint = P->getPosition() - P->getVelocity() * (distance / nv); 53 53 54 54 float upos = (hitPoint - domain.v1) * domain.s1; 55 55 float vpos = (hitPoint - domain.v1) * domain.s2; 56 56 if ( upos<0.0f || upos>1.0f || vpos<0.0f || vpos>1.0f ) return; 57 57 58 58 // Compute tangential and normal components of velocity 59 59 osg::Vec3 vn = normal * nv; 60 60 osg::Vec3 vt = P->getVelocity() - vn; 61 61 62 62 // Compute new velocity 63 63 if ( vt.length2()<=_cutoff ) P->setVelocity( vt - vn*_resilience ); … … 70 70 float distance = domain.plane.distance( P->getPosition() ); 71 71 if ( distance*domain.plane.distance(nextpos)>=0 ) return; 72 72 73 73 osg::Vec3 normal = domain.plane.getNormal(); 74 74 float nv = normal * P->getVelocity(); 75 75 76 76 // Compute tangential and normal components of velocity 77 77 osg::Vec3 vn = normal * nv; 78 78 osg::Vec3 vt = P->getVelocity() - vn; 79 79 80 80 // Compute new velocity 81 81 if ( vt.length2()<=_cutoff ) P->setVelocity( vt - vn*_resilience ); … … 91 91 float distance2 = (nextpos - domain.v1).length(); 92 92 if ( distance2<=domain.r1 ) return; 93 93 94 94 // Bounce back in if going outside 95 95 osg::Vec3 normal = domain.v1 - P->getPosition(); normal.normalize(); 96 96 float nmag = P->getVelocity() * normal; 97 97 98 98 // Compute tangential and normal components of velocity 99 99 osg::Vec3 vn = normal * nmag; 100 100 osg::Vec3 vt = P->getVelocity() - vn; 101 101 if ( nmag<0 ) vn = -vn; 102 102 103 103 // Compute new velocity 104 104 float tanscale = (vt.length2()<=_cutoff) ? 1.0f : (1.0f - _friction); 105 105 P->setVelocity( vt * tanscale + vn * _resilience ); 106 106 107 107 // Make sure the particle is fixed to stay inside 108 108 nextpos = P->getPosition() + P->getVelocity() * dt; … … 111 111 { 112 112 normal = domain.v1 - nextpos; normal.normalize(); 113 113 114 114 osg::Vec3 wishPoint = domain.v1 - normal * (0.999f * domain.r1); 115 115 P->setVelocity( (wishPoint - P->getPosition()) / dt ); … … 120 120 float distance2 = (nextpos - domain.v1).length(); 121 121 if ( distance2>domain.r1 ) return; 122 122 123 123 // Bounce back out if going inside 124 124 osg::Vec3 normal = P->getPosition() - domain.v1; normal.normalize(); 125 125 float nmag = P->getVelocity() * normal; 126 126 127 127 // Compute tangential and normal components of velocity 128 128 osg::Vec3 vn = normal * nmag; 129 129 osg::Vec3 vt = P->getVelocity() - vn; 130 130 if ( nmag<0 ) vn = -vn; 131 131 132 132 // Compute new velocity 133 133 float tanscale = (vt.length2()<=_cutoff) ? 1.0f : (1.0f - _friction); … … 141 141 float distance = domain.plane.distance( P->getPosition() ); 142 142 if ( distance*domain.plane.distance(nextpos)>=0 ) return; 143 143 144 144 osg::Vec3 normal = domain.plane.getNormal(); 145 145 float nv = normal * P->getVelocity(); 146 146 osg::Vec3 hitPoint = P->getPosition() - P->getVelocity() * (distance / nv); 147 147 148 148 float radius = (hitPoint - domain.v1).length(); 149 149 if ( radius>domain.r1 || radius<domain.r2 ) return; 150 150 151 151 // Compute tangential and normal components of velocity 152 152 osg::Vec3 vn = normal * nv; 153 153 osg::Vec3 vt = P->getVelocity() - vn; 154 154 155 155 // Compute new velocity 156 156 if ( vt.length2()<=_cutoff ) P->setVelocity( vt - vn*_resilience );
