root/OpenSceneGraph/trunk/src/osgParticle/SinkOperator.cpp @ 13041

Revision 13041, 3.7 kB (checked in by robert, 2 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2010 Robert Osfield
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
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * OpenSceneGraph Public License for more details.
12*/
13// Written by Wang Rui, (C) 2010
14
15#include <osg/Notify>
16#include <osgParticle/ModularProgram>
17#include <osgParticle/SinkOperator>
18
19#define SINK_EPSILON 1e-3
20
21using namespace osgParticle;
22
23void SinkOperator::beginOperate( Program* prg )
24{
25    // Don't transform domains if they are used for sinking velocities
26    if ( _sinkTarget==SINK_POSITION )
27        DomainOperator::beginOperate(prg );
28}
29
30void SinkOperator::handlePoint( const Domain& domain, Particle* P, double dt )
31{
32    const osg::Vec3& value = getValue(P);
33    kill( P, (domain.v1==value) );
34}
35
36void SinkOperator::handleLineSegment( const Domain& domain, Particle* P, double dt )
37{
38    const osg::Vec3& value = getValue(P);
39    osg::Vec3 offset = value - domain.v1, normal = domain.v2 - domain.v1;
40    normal.normalize();
41
42    float diff = fabs(normal*offset - offset.length()) / domain.r1;
43    kill( P, (diff<SINK_EPSILON) );
44}
45
46void SinkOperator::handleTriangle( const Domain& domain, Particle* P, double dt )
47{
48    bool insideDomain = false;
49    const osg::Vec3& value = getValue(P);
50    osg::Vec3 offset = value - domain.v1;
51    if ( offset*domain.plane.getNormal()>SINK_EPSILON )
52        insideDomain = false;
53    else
54    {
55        float upos = offset * domain.s1;
56        float vpos = offset * domain.s2;
57        insideDomain = !(upos<0.0f || vpos<0.0f || (upos+vpos)>1.0f);
58    }
59    kill( P, insideDomain );
60}
61
62void SinkOperator::handleRectangle( const Domain& domain, Particle* P, double dt )
63{
64    bool insideDomain = false;
65    const osg::Vec3& value = getValue(P);
66    osg::Vec3 offset = value - domain.v1;
67    if ( offset*domain.plane.getNormal()>SINK_EPSILON )
68        insideDomain = false;
69    else
70    {
71        float upos = offset * domain.s1;
72        float vpos = offset * domain.s2;
73        insideDomain = !(upos<0.0f || upos>1.0f || vpos<0.0f || vpos>1.0f);
74    }
75    kill( P, insideDomain );
76}
77
78void SinkOperator::handlePlane( const Domain& domain, Particle* P, double dt )
79{
80    const osg::Vec3& value = getValue(P);
81    bool insideDomain = (domain.plane.getNormal()*value>=-domain.plane[3]);
82    kill( P, insideDomain );
83}
84
85void SinkOperator::handleSphere( const Domain& domain, Particle* P, double dt )
86{
87    const osg::Vec3& value = getValue(P);
88    float r = (value - domain.v1).length();
89    kill( P, (r<=domain.r1) );
90}
91
92void SinkOperator::handleBox( const Domain& domain, Particle* P, double dt )
93{
94    const osg::Vec3& value = getValue(P);
95    bool insideDomain = !(
96        (value.x() < domain.v1.x()) || (value.x() > domain.v2.x()) ||
97        (value.y() < domain.v1.y()) || (value.y() > domain.v2.y()) ||
98        (value.z() < domain.v1.z()) || (value.z() > domain.v2.z())
99    );
100    kill( P, insideDomain );
101}
102
103void SinkOperator::handleDisk( const Domain& domain, Particle* P, double dt )
104{
105    bool insideDomain = false;
106    const osg::Vec3& value = getValue(P);
107    osg::Vec3 offset = value - domain.v1;
108    if ( offset*domain.v2>SINK_EPSILON )
109        insideDomain = false;
110    else
111    {
112        float length = offset.length();
113        insideDomain = (length<=domain.r1 && length>=domain.r2);
114    }
115    kill( P, insideDomain );
116}
Note: See TracBrowser for help on using the browser.