Added a Matrix::value_type typedef'd trait into osg::Matrix, defaulting its
value to float, and converted the internal code across to use value_type. This allows Matrix to be converted to use double's simply by change the definition of value_type. Added Matrix::glLoadlMatrix and Matrix::glMultMatrix() to help encapsulate the changes between float and double matrix usage. Updated code that uses Matrix so it doesn't assume float or double matrices.
This commit is contained in:
@@ -41,12 +41,12 @@ void osgParticle::FluidFrictionOperator::operate(Particle *P, double dt)
|
||||
Fr = current_program_->rotateLocalToWorld(Fr);
|
||||
}
|
||||
|
||||
// correct unwanted velocity increments
|
||||
osg::Vec3 dv = Fr * P->getMassInv() * dt;
|
||||
float dvl = dv.length();
|
||||
if (dvl > vm) {
|
||||
dv *= vm / dvl;
|
||||
}
|
||||
// correct unwanted velocity increments
|
||||
osg::Vec3 dv = Fr * P->getMassInv() * dt;
|
||||
float dvl = dv.length();
|
||||
if (dvl > vm) {
|
||||
dv *= vm / dvl;
|
||||
}
|
||||
|
||||
P->addVelocity(dv);
|
||||
}
|
||||
|
||||
@@ -36,9 +36,9 @@ osgParticle::Particle::Particle()
|
||||
prev_pos_(0, 0, 0),
|
||||
position_(0, 0, 0),
|
||||
velocity_(0, 0, 0),
|
||||
prev_angle_(0, 0, 0),
|
||||
angle_(0, 0, 0),
|
||||
angular_vel_(0, 0, 0),
|
||||
prev_angle_(0, 0, 0),
|
||||
angle_(0, 0, 0),
|
||||
angular_vel_(0, 0, 0),
|
||||
t0_(0),
|
||||
current_size_(0),
|
||||
current_alpha_(0)
|
||||
@@ -78,16 +78,16 @@ bool osgParticle::Particle::update(double dt)
|
||||
prev_pos_ = position_;
|
||||
position_ += velocity_ * dt;
|
||||
|
||||
// update angle
|
||||
prev_angle_ = angle_;
|
||||
angle_ += angular_vel_ * dt;
|
||||
// update angle
|
||||
prev_angle_ = angle_;
|
||||
angle_ += angular_vel_ * dt;
|
||||
|
||||
if (angle_.x() > osg::PI*2) angle_.x() -= osg::PI*2;
|
||||
if (angle_.x() < -osg::PI*2) angle_.x() += osg::PI*2;
|
||||
if (angle_.y() > osg::PI*2) angle_.y() -= osg::PI*2;
|
||||
if (angle_.y() < -osg::PI*2) angle_.y() += osg::PI*2;
|
||||
if (angle_.z() > osg::PI*2) angle_.z() -= osg::PI*2;
|
||||
if (angle_.z() < -osg::PI*2) angle_.z() += osg::PI*2;
|
||||
if (angle_.x() > osg::PI*2) angle_.x() -= osg::PI*2;
|
||||
if (angle_.x() < -osg::PI*2) angle_.x() += osg::PI*2;
|
||||
if (angle_.y() > osg::PI*2) angle_.y() -= osg::PI*2;
|
||||
if (angle_.y() < -osg::PI*2) angle_.y() += osg::PI*2;
|
||||
if (angle_.z() > osg::PI*2) angle_.z() -= osg::PI*2;
|
||||
if (angle_.z() < -osg::PI*2) angle_.z() += osg::PI*2;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -99,11 +99,11 @@ void osgParticle::Particle::render(const osg::Vec3 &xpos, const osg::Vec3 &px, c
|
||||
current_color_.z(),
|
||||
current_color_.w() * current_alpha_);
|
||||
|
||||
osg::Matrix R;
|
||||
R.makeRotate(
|
||||
angle_.x(), osg::Vec3(1, 0, 0),
|
||||
angle_.y(), osg::Vec3(0, 1, 0),
|
||||
angle_.z(), osg::Vec3(0, 0, 1));
|
||||
osg::Matrix R;
|
||||
R.makeRotate(
|
||||
angle_.x(), osg::Vec3(1, 0, 0),
|
||||
angle_.y(), osg::Vec3(0, 1, 0),
|
||||
angle_.z(), osg::Vec3(0, 0, 1));
|
||||
|
||||
osg::Vec3 p1(px * current_size_ * scale);
|
||||
osg::Vec3 p2(py * current_size_ * scale);
|
||||
@@ -126,10 +126,10 @@ void osgParticle::Particle::render(const osg::Vec3 &xpos, const osg::Vec3 &px, c
|
||||
break;
|
||||
|
||||
case QUAD_TRIANGLESTRIP:
|
||||
glPushMatrix();
|
||||
glTranslatef(xpos.x(), xpos.y(), xpos.z());
|
||||
glMultMatrixf(R.ptr());
|
||||
// we must glBegin() and glEnd() here, because each particle is a single strip
|
||||
glPushMatrix();
|
||||
glTranslatef(xpos.x(), xpos.y(), xpos.z());
|
||||
R.glMultMatrix();
|
||||
// we must glBegin() and glEnd() here, because each particle is a single strip
|
||||
glBegin(GL_TRIANGLE_STRIP);
|
||||
glTexCoord2f(1, 1);
|
||||
glVertex3fv((p1+p2).ptr());
|
||||
@@ -140,13 +140,13 @@ void osgParticle::Particle::render(const osg::Vec3 &xpos, const osg::Vec3 &px, c
|
||||
glTexCoord2f(0, 0);
|
||||
glVertex3fv((-p1-p2).ptr());
|
||||
glEnd();
|
||||
glPopMatrix();
|
||||
glPopMatrix();
|
||||
break;
|
||||
|
||||
case HEXAGON:
|
||||
glPushMatrix();
|
||||
glTranslatef(xpos.x(), xpos.y(), xpos.z());
|
||||
glMultMatrixf(R.ptr());
|
||||
glPushMatrix();
|
||||
glTranslatef(xpos.x(), xpos.y(), xpos.z());
|
||||
R.glMultMatrix();
|
||||
// we must glBegin() and glEnd() here, because each particle is a single fan
|
||||
glBegin(GL_TRIANGLE_FAN);
|
||||
glTexCoord2f(0.5f, 0.5f);
|
||||
@@ -166,22 +166,22 @@ void osgParticle::Particle::render(const osg::Vec3 &xpos, const osg::Vec3 &px, c
|
||||
glTexCoord2f(hex_texcoord_x1, hex_texcoord_y1);
|
||||
glVertex3fv((p1*cosPI3+p2*sinPI3).ptr());
|
||||
glEnd();
|
||||
glPopMatrix();
|
||||
glPopMatrix();
|
||||
break;
|
||||
|
||||
case LINE:
|
||||
case LINE:
|
||||
{
|
||||
// Get the normalized direction of the particle, to be used in the
|
||||
// calculation of one of the linesegment endpoints.
|
||||
float vl = velocity_.length();
|
||||
if (vl != 0) {
|
||||
osg::Vec3 v = velocity_ * current_size_ * scale / vl;
|
||||
float vl = velocity_.length();
|
||||
if (vl != 0) {
|
||||
osg::Vec3 v = velocity_ * current_size_ * scale / vl;
|
||||
|
||||
glTexCoord1f(0);
|
||||
glVertex3f(xpos.x(), xpos.y(), xpos.z());
|
||||
glTexCoord1f(1);
|
||||
glVertex3f(xpos.x() + v.x(), xpos.y() + v.y(), xpos.z() + v.z());
|
||||
}
|
||||
glTexCoord1f(0);
|
||||
glVertex3f(xpos.x(), xpos.y(), xpos.z());
|
||||
glTexCoord1f(1);
|
||||
glVertex3f(xpos.x() + v.x(), xpos.y() + v.y(), xpos.z() + v.z());
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
@@ -20,11 +20,11 @@ osgParticle::ParticleProcessor::ParticleProcessor()
|
||||
need_ltw_matrix_(false),
|
||||
need_wtl_matrix_(false),
|
||||
current_nodevisitor_(0),
|
||||
endless_(true),
|
||||
lifeTime_(0.0),
|
||||
startTime_(0.0),
|
||||
currentTime_(0.0),
|
||||
resetTime_(0.0)
|
||||
endless_(true),
|
||||
lifeTime_(0.0),
|
||||
startTime_(0.0),
|
||||
currentTime_(0.0),
|
||||
resetTime_(0.0)
|
||||
{
|
||||
setCullingActive(false);
|
||||
}
|
||||
@@ -38,11 +38,11 @@ osgParticle::ParticleProcessor::ParticleProcessor(const ParticleProcessor ©,
|
||||
need_ltw_matrix_(copy.need_ltw_matrix_),
|
||||
need_wtl_matrix_(copy.need_wtl_matrix_),
|
||||
current_nodevisitor_(0),
|
||||
endless_(copy.endless_),
|
||||
lifeTime_(copy.lifeTime_),
|
||||
startTime_(copy.startTime_),
|
||||
currentTime_(copy.currentTime_),
|
||||
resetTime_(copy.resetTime_)
|
||||
endless_(copy.endless_),
|
||||
lifeTime_(copy.lifeTime_),
|
||||
startTime_(copy.startTime_),
|
||||
currentTime_(copy.currentTime_),
|
||||
resetTime_(copy.resetTime_)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -64,30 +64,30 @@ void osgParticle::ParticleProcessor::traverse(osg::NodeVisitor &nv)
|
||||
// retrieve the current time
|
||||
double t = nv.getFrameStamp()->getReferenceTime();
|
||||
|
||||
// reset this processor if we've reached the reset point
|
||||
if ((currentTime_ >= resetTime_) && (resetTime_ > 0)) {
|
||||
currentTime_ = 0;
|
||||
t0_ = -1;
|
||||
}
|
||||
// reset this processor if we've reached the reset point
|
||||
if ((currentTime_ >= resetTime_) && (resetTime_ > 0)) {
|
||||
currentTime_ = 0;
|
||||
t0_ = -1;
|
||||
}
|
||||
|
||||
// skip if we haven't initialized t0_ yet
|
||||
// skip if we haven't initialized t0_ yet
|
||||
if (t0_ != -1) {
|
||||
|
||||
// check whether the processor is alive
|
||||
bool alive = false;
|
||||
if (currentTime_ >= startTime_) {
|
||||
if (endless_ || (currentTime_ < (startTime_ + lifeTime_)))
|
||||
alive = true;
|
||||
}
|
||||
// check whether the processor is alive
|
||||
bool alive = false;
|
||||
if (currentTime_ >= startTime_) {
|
||||
if (endless_ || (currentTime_ < (startTime_ + lifeTime_)))
|
||||
alive = true;
|
||||
}
|
||||
|
||||
// update current time
|
||||
currentTime_ += t - t0_;
|
||||
// update current time
|
||||
currentTime_ += t - t0_;
|
||||
|
||||
// process only if the particle system is not frozen/culled
|
||||
if (alive &&
|
||||
enabled_ &&
|
||||
!ps_->isFrozen() &&
|
||||
(ps_->getLastFrameNumber() >= (nv.getFrameStamp()->getFrameNumber() - 1) || !ps_->getFreezeOnCull())) {
|
||||
enabled_ &&
|
||||
!ps_->isFrozen() &&
|
||||
(ps_->getLastFrameNumber() >= (nv.getFrameStamp()->getFrameNumber() - 1) || !ps_->getFreezeOnCull())) {
|
||||
|
||||
// initialize matrix flags
|
||||
need_ltw_matrix_ = true;
|
||||
|
||||
Reference in New Issue
Block a user