#if defined(_MSC_VER) #pragma warning( disable : 4786 ) #endif #include #include #include #include #include #include #include #include #include using namespace osg; ImpostorSprite::ImpostorSprite() { // don't use display list since we will be updating the geometry. _useDisplayList = false; _parent = NULL; _ism = NULL; _previous = NULL; _next = NULL; _texture = NULL; _s = 0; _t = 0; } ImpostorSprite::~ImpostorSprite() { if (_ism) { _ism->remove(this); } } float ImpostorSprite::calcPixelError(const Matrix& MVPW) const { // find the maximum screen space pixel error between the control coords and the quad coners. float max_error_sqrd = 0.0f; for(int i=0;i<4;++i) { Vec3 projected_coord = _coords[i]*MVPW; Vec3 projected_control = _controlcoords[i]*MVPW; float dx = (projected_coord.x()-projected_control.x()); float dy = (projected_coord.y()-projected_control.y()); float error_sqrd = dx*dx+dy*dy; if (error_sqrd > max_error_sqrd) max_error_sqrd = error_sqrd; } return sqrtf(max_error_sqrd); } void ImpostorSprite::drawImplementation(State&) const { // when the tex env is set to REPLACE, and the // texture is set up correctly the color has no effect. glColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); glBegin( GL_QUADS ); glTexCoord2fv( (GLfloat *)&_texcoords[0] ); glVertex3fv( (GLfloat *)&_coords[0] ); glTexCoord2fv( (GLfloat *)&_texcoords[1] ); glVertex3fv( (GLfloat *)&_coords[1] ); glTexCoord2fv( (GLfloat *)&_texcoords[2] ); glVertex3fv( (GLfloat *)&_coords[2] ); glTexCoord2fv( (GLfloat *)&_texcoords[3] ); glVertex3fv( (GLfloat *)&_coords[3] ); glEnd(); } bool ImpostorSprite::computeBound() const { _bbox.init(); _bbox.expandBy(_coords[0]); _bbox.expandBy(_coords[1]); _bbox.expandBy(_coords[2]); _bbox.expandBy(_coords[3]); _bbox_computed=true; if (!_bbox.valid()) { notify(WARN) << "******* ImpostorSprite::computeBound() problem"<