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:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user