DomainOperator
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2010 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
// Written by Wang Rui, (C) 2010
#ifndef OSGPARTICLE_DOMAINOPERATOR
#define OSGPARTICLE_DOMAINOPERATOR
#include <osg/Plane>
#include <osgParticle/Operator>
#include <osgParticle/Particle>
namespace osgParticle
{
class OSGPARTICLE_EXPORT DomainOperator : public Operator
{
public:
struct Domain
{
enum Type
{
UNDEFINED_DOMAIN = 0,
POINT_DOMAIN,
LINE_DOMAIN,
TRI_DOMAIN,
RECT_DOMAIN,
PLANE_DOMAIN,
SPHERE_DOMAIN,
BOX_DOMAIN,
DISK_DOMAIN
};
Domain( Type t ) : r1(0.0f), r2(0.0f), type(t) {}
osg::Plane plane;
osg::Vec3 v1;
osg::Vec3 v2;
osg::Vec3 v3;
osg::Vec3 s1;
osg::Vec3 s2;
float r1;
float r2;
Type type;
};
DomainOperator()
: Operator()
{}
DomainOperator( const DomainOperator& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY )
: Operator(copy, copyop), _domains(copy._domains), _backupDomains(copy._backupDomains)
{}
META_Object( osgParticle, DomainOperator );
inline void addPointDomain( const osg::Vec3& p );
inline void addLineSegmentDomain( const osg::Vec3& v1, const osg::Vec3& v2 );
inline void addTriangleDomain( const osg::Vec3& v1, const osg::Vec3& v2, const osg::Vec3& v3 );
inline void addRectangleDomain( const osg::Vec3& corner, const osg::Vec3& w, const osg::Vec3& h );
inline void addPlaneDomain( const osg::Plane& plane );
inline void addSphereDomain( const osg::Vec3& c, float r );
inline void addBoxDomain( const osg::Vec3& min, const osg::Vec3& max );
inline void addDiskDomain( const osg::Vec3& c, const osg::Vec3& n, float r1, float r2=0.0f );
void addDomain( const Domain& domain ) { _domains.push_back(domain); }
const Domain& getDomain( unsigned int i ) const { return _domains[i]; }
void removeDomain( unsigned int i )
{ if (i<_domains.size()) _domains.erase(_domains.begin() + i); }
void removeAllDomains() { _domains.clear(); }
unsigned int getNumDomains() const { return _domains.size(); }
void operate( Particle* P, double dt );
void beginOperate( Program* prg );
void endOperate();
protected:
virtual ~DomainOperator() {}
DomainOperator& operator=( const DomainOperator& ) { return *this; }
virtual void handlePoint( const Domain& /*domain*/, Particle* /*P*/, double /*dt*/ ) { ignore("Point"); }
virtual void handleLineSegment( const Domain& /*domain*/, Particle* /*P*/, double /*dt*/ ) { ignore("LineSegment"); }
virtual void handleTriangle( const Domain& /*domain*/, Particle* /*P*/, double /*dt*/ ) { ignore("Triangle"); }
virtual void handleRectangle( const Domain& /*domain*/, Particle* /*P*/, double /*dt*/ ) { ignore("Rectangle"); }
virtual void handlePlane( const Domain& /*domain*/, Particle* /*P*/, double /*dt*/ ) { ignore("Plane"); }
virtual void handleSphere( const Domain& /*domain*/, Particle* /*P*/, double /*dt*/ ) { ignore("Sphere"); }
virtual void handleBox( const Domain& /*domain*/, Particle* /*P*/, double /*dt*/ ) { ignore("Box"); }
virtual void handleDisk( const Domain& /*domain*/, Particle* /*P*/, double /*dt*/ ) { ignore("Disk"); }
inline void computeNewBasis( const osg::Vec3&, const osg::Vec3&, osg::Vec3&, osg::Vec3& );
inline void ignore( const std::string& func );
std::vector<Domain> _domains;
std::vector<Domain> _backupDomains;
};
// INLINE METHODS
inline void DomainOperator::addPointDomain( const osg::Vec3& p )
{
Domain domain( Domain::POINT_DOMAIN );
domain.v1 = p;
_domains.push_back( domain );
}
inline void DomainOperator::addLineSegmentDomain( const osg::Vec3& v1, const osg::Vec3& v2 )
{
Domain domain( Domain::LINE_DOMAIN );
domain.v1 = v1;
domain.v2 = v2;
domain.r1 = (v2 - v1).length();
_domains.push_back( domain );
}
inline void DomainOperator::addTriangleDomain( const osg::Vec3& v1, const osg::Vec3& v2, const osg::Vec3& v3 )
{
Domain domain( Domain::TRI_DOMAIN );
domain.v1 = v1;
domain.v2 = v2;
domain.v3 = v3;
domain.plane.set(v1, v2, v3);
computeNewBasis( v2-v1, v3-v1, domain.s1, domain.s2 );
_domains.push_back( domain );
}
inline void DomainOperator::addRectangleDomain( const osg::Vec3& corner, const osg::Vec3& w, const osg::Vec3& h )
{
Domain domain( Domain::RECT_DOMAIN );
domain.v1 = corner;
domain.v2 = w;
domain.v3 = h;
domain.plane.set(corner, corner+w, corner+h);
computeNewBasis( w, h, domain.s1, domain.s2 );
_domains.push_back( domain );
}
inline void DomainOperator::addPlaneDomain( const osg::Plane& plane )
{
Domain domain( Domain::PLANE_DOMAIN );
domain.plane.set(plane);
_domains.push_back( domain );
}
inline void DomainOperator::addSphereDomain( const osg::Vec3& c, float r )
{
Domain domain( Domain::SPHERE_DOMAIN );
domain.v1 = c;
domain.r1 = r;
_domains.push_back( domain );
}
inline void DomainOperator::addBoxDomain( const osg::Vec3& min, const osg::Vec3& max )
{
Domain domain( Domain::BOX_DOMAIN );
domain.v1 = min;
domain.v2 = max;
_domains.push_back( domain );
}
inline void DomainOperator::addDiskDomain( const osg::Vec3& c, const osg::Vec3& n, float r1, float r2 )
{
Domain domain( Domain::DISK_DOMAIN );
domain.v1 = c;
domain.v2 = n;
domain.r1 = r1;
domain.r2 = r2;
domain.plane.set(n, c);
_domains.push_back( domain );
}
inline void DomainOperator::computeNewBasis( const osg::Vec3& u, const osg::Vec3& v, osg::Vec3& s1, osg::Vec3& s2 )
{
// Copied from David McAllister's Particle System API (http://www.particlesystems.org), pDomain.h
osg::Vec3 w = u ^ v;
float det = w.z()*u.x()*v.y() - w.z()*u.y()*v.x() - u.z()*w.x()*v.y() -
u.x()*v.z()*w.y() + v.z()*w.x()*u.y() + u.z()*v.x()*w.y();
det = 1.0f / det;
s1.set( v.y()*w.z() - v.z()*w.y(), v.z()*w.x() - v.x()*w.z(), v.x()*w.y() - v.y()*w.x() );
s1 = s1 * det;
s2.set( u.y()*w.z() - u.z()*w.y(), u.z()*w.x() - u.x()*w.z(), u.x()*w.y() - u.y()*w.x() );
s2 = s2 * (-det);
}
inline void DomainOperator::ignore( const std::string& func )
{
OSG_NOTICE << className() << ": " << func << " domain not yet implemented. " << std::endl;
}
}
#endif
OSG_NOTICE
#define OSG_NOTICE
Definition Notify:86
Operator
Particle
Plane
osgParticle::DomainOperator::handlePlane
virtual void handlePlane(const Domain &, Particle *, double)
Definition DomainOperator:127
osgParticle::DomainOperator::addSphereDomain
void addSphereDomain(const osg::Vec3 &c, float r)
Add a sphere domain.
Definition DomainOperator:186
osgParticle::DomainOperator::getDomain
const Domain & getDomain(unsigned int i) const
Get a domain object directly, used by the .osg wrappers and serializers.
Definition DomainOperator:98
osgParticle::DomainOperator::META_Object
META_Object(osgParticle, DomainOperator)
osgParticle::DomainOperator::addRectangleDomain
void addRectangleDomain(const osg::Vec3 &corner, const osg::Vec3 &w, const osg::Vec3 &h)
Add a rectangle domain.
Definition DomainOperator:168
osgParticle::DomainOperator::handleRectangle
virtual void handleRectangle(const Domain &, Particle *, double)
Definition DomainOperator:126
osgParticle::DomainOperator::DomainOperator
DomainOperator(const DomainOperator &copy, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Definition DomainOperator:64
osgParticle::DomainOperator::handleTriangle
virtual void handleTriangle(const Domain &, Particle *, double)
Definition DomainOperator:125
osgParticle::DomainOperator::addBoxDomain
void addBoxDomain(const osg::Vec3 &min, const osg::Vec3 &max)
Add a box domain.
Definition DomainOperator:194
osgParticle::DomainOperator::removeDomain
void removeDomain(unsigned int i)
Remove a domain at specific index.
Definition DomainOperator:101
osgParticle::DomainOperator::addPointDomain
void addPointDomain(const osg::Vec3 &p)
Add a point domain.
Definition DomainOperator:141
osgParticle::DomainOperator::operate
void operate(Particle *P, double dt)
Apply the acceleration to a particle. Do not call this method manually.
osgParticle::DomainOperator::handlePoint
virtual void handlePoint(const Domain &, Particle *, double)
Definition DomainOperator:123
osgParticle::DomainOperator::ignore
void ignore(const std::string &func)
Definition DomainOperator:227
osgParticle::DomainOperator::addTriangleDomain
void addTriangleDomain(const osg::Vec3 &v1, const osg::Vec3 &v2, const osg::Vec3 &v3)
Add a triangle domain.
Definition DomainOperator:157
osgParticle::DomainOperator::addDiskDomain
void addDiskDomain(const osg::Vec3 &c, const osg::Vec3 &n, float r1, float r2=0.0f)
Add a disk domain.
Definition DomainOperator:202
osgParticle::DomainOperator::DomainOperator
DomainOperator()
Definition DomainOperator:60
osgParticle::DomainOperator::beginOperate
void beginOperate(Program *prg)
Perform some initializations. Do not call this method manually.
osgParticle::DomainOperator::addLineSegmentDomain
void addLineSegmentDomain(const osg::Vec3 &v1, const osg::Vec3 &v2)
Add a line segment domain.
Definition DomainOperator:148
osgParticle::DomainOperator::getNumDomains
unsigned int getNumDomains() const
Get number of domains.
Definition DomainOperator:108
osgParticle::DomainOperator::~DomainOperator
virtual ~DomainOperator()
Definition DomainOperator:120
osgParticle::DomainOperator::handleDisk
virtual void handleDisk(const Domain &, Particle *, double)
Definition DomainOperator:130
osgParticle::DomainOperator::_backupDomains
std::vector< Domain > _backupDomains
Definition DomainOperator:136
osgParticle::DomainOperator::operator=
DomainOperator & operator=(const DomainOperator &)
Definition DomainOperator:121
osgParticle::DomainOperator::handleBox
virtual void handleBox(const Domain &, Particle *, double)
Definition DomainOperator:129
osgParticle::DomainOperator::endOperate
void endOperate()
Perform some post-operations. Do not call this method manually.
osgParticle::DomainOperator::removeAllDomains
void removeAllDomains()
Remove all existing domains.
Definition DomainOperator:105
osgParticle::DomainOperator::_domains
std::vector< Domain > _domains
Definition DomainOperator:135
osgParticle::DomainOperator::handleSphere
virtual void handleSphere(const Domain &, Particle *, double)
Definition DomainOperator:128
osgParticle::DomainOperator::addDomain
void addDomain(const Domain &domain)
Add a domain object directly, used by the .osg wrappers and serializers.
Definition DomainOperator:95
osgParticle::DomainOperator::computeNewBasis
void computeNewBasis(const osg::Vec3 &, const osg::Vec3 &, osg::Vec3 &, osg::Vec3 &)
Definition DomainOperator:213
osgParticle::DomainOperator::addPlaneDomain
void addPlaneDomain(const osg::Plane &plane)
Add a plane domain.
Definition DomainOperator:179
osgParticle::DomainOperator::handleLineSegment
virtual void handleLineSegment(const Domain &, Particle *, double)
Definition DomainOperator:124
osgParticle::Operator::className
virtual const char * className() const
Definition Operator:41
osgParticle::Operator::Operator
Operator()
Definition Operator:92
osgParticle::Particle
Definition Particle:47
osgParticle::Program
Definition osgParticle/Program:36
osg::CopyOp
Definition CopyOp:41
osg::CopyOp::SHALLOW_COPY
@ SHALLOW_COPY
Definition CopyOp:47
osg::Plane
A plane class. It can be used to represent an infinite plane.
Definition Plane:34
osg::Plane::set
void set(const Plane &pl)
Definition Plane:105
osg::Vec3f::z
value_type & z()
Definition Vec3f:82
osg::Vec3f::set
void set(value_type x, value_type y, value_type z)
Definition Vec3f:67
osg::Vec3f::y
value_type & y()
Definition Vec3f:81
osg::Vec3f::x
value_type & x()
Definition Vec3f:80
osgParticle
Definition AccelOperator:27
osg::Vec3
Vec3f Vec3
Definition Vec3:21
OSGPARTICLE_EXPORT
#define OSGPARTICLE_EXPORT
Definition osgParticle/Export:40
osgParticle::DomainOperator::Domain
Definition DomainOperator:34
osgParticle::DomainOperator::Domain::s2
osg::Vec3 s2
Definition DomainOperator:54
osgParticle::DomainOperator::Domain::v3
osg::Vec3 v3
Definition DomainOperator:52
osgParticle::DomainOperator::Domain::v2
osg::Vec3 v2
Definition DomainOperator:51
osgParticle::DomainOperator::Domain::Domain
Domain(Type t)
Definition DomainOperator:48
osgParticle::DomainOperator::Domain::type
Type type
Definition DomainOperator:57
osgParticle::DomainOperator::Domain::s1
osg::Vec3 s1
Definition DomainOperator:53
osgParticle::DomainOperator::Domain::r1
float r1
Definition DomainOperator:55
osgParticle::DomainOperator::Domain::v1
osg::Vec3 v1
Definition DomainOperator:50
osgParticle::DomainOperator::Domain::r2
float r2
Definition DomainOperator:56
osgParticle::DomainOperator::Domain::plane
osg::Plane plane
Definition DomainOperator:49
osgParticle::DomainOperator::Domain::Type
Type
Definition DomainOperator:36
osgParticle::DomainOperator::Domain::UNDEFINED_DOMAIN
@ UNDEFINED_DOMAIN
Definition DomainOperator:37
osgParticle::DomainOperator::Domain::DISK_DOMAIN
@ DISK_DOMAIN
Definition DomainOperator:45
osgParticle::DomainOperator::Domain::SPHERE_DOMAIN
@ SPHERE_DOMAIN
Definition DomainOperator:43
osgParticle::DomainOperator::Domain::POINT_DOMAIN
@ POINT_DOMAIN
Definition DomainOperator:38
osgParticle::DomainOperator::Domain::LINE_DOMAIN
@ LINE_DOMAIN
Definition DomainOperator:39
osgParticle::DomainOperator::Domain::TRI_DOMAIN
@ TRI_DOMAIN
Definition DomainOperator:40
osgParticle::DomainOperator::Domain::RECT_DOMAIN
@ RECT_DOMAIN
Definition DomainOperator:41
osgParticle::DomainOperator::Domain::PLANE_DOMAIN
@ PLANE_DOMAIN
Definition DomainOperator:42
osgParticle::DomainOperator::Domain::BOX_DOMAIN
@ BOX_DOMAIN
Definition DomainOperator:44