Merged changed to osgParticle from Macro, these add the ability to
orientate the particles to predefined axis.
This commit is contained in:
@@ -260,8 +260,6 @@ sMStats m_getMemoryStatistics()
|
||||
m_breakOnAllocation(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if( (ptr = getenv("OSG_MM_CHECK_ON_ALLOCATIONS")) != 0)
|
||||
{
|
||||
@@ -499,19 +497,25 @@ sMStats m_getMemoryStatistics()
|
||||
// Fill the remainder
|
||||
|
||||
unsigned int shiftCount = 0;
|
||||
char *cptr = (char *) lptr;
|
||||
unsigned char *cptr = (unsigned char *) lptr;
|
||||
for (i = 0; i < (length & 0x3); i++, cptr++, shiftCount += 8)
|
||||
{
|
||||
if (*cptr == static_cast<char>((pattern >> shiftCount) & 0xff)) ++numMatching;
|
||||
if (*cptr == static_cast<unsigned char>((pattern >> shiftCount) & 0xff)) ++numMatching;
|
||||
else ++numNotMatching;
|
||||
}
|
||||
|
||||
if (numMatching>0 && !allocUnit->printedOutUnintializedInfo)
|
||||
{
|
||||
// possible unitialized data?
|
||||
printf("Warning: possible uninitilized memory numMatching=%d numNotMatching=%d\n",numMatching,numNotMatching);
|
||||
printf("Warning: possible uninitilized memory numMatching=%d numNotMatching=%d length=%d\n",numMatching,numNotMatching,length);
|
||||
printf(" allocationNumber=%d sourceFile '%s' sourceLine=%d\n",allocUnit->allocationNumber,allocUnit->sourceFile,allocUnit->sourceLine);
|
||||
|
||||
// cptr = ((unsigned char *)allocUnit->reportedAddress);
|
||||
// for (i = 0; i < length; i++, cptr++)
|
||||
// {
|
||||
// std::cout<<" "<<i<<" " << std::hex << (unsigned int) *cptr << std::dec <<std::endl;
|
||||
// }
|
||||
|
||||
allocUnit->printedOutUnintializedInfo=true;
|
||||
|
||||
return false;
|
||||
|
||||
@@ -30,7 +30,38 @@ bool ParticleSystem_readLocalData(osg::Object &obj, osgDB::Input &fr)
|
||||
osgParticle::ParticleSystem &myobj = static_cast<osgParticle::ParticleSystem &>(obj);
|
||||
bool itAdvanced = false;
|
||||
|
||||
if (fr[0].matchWord("DoublePassRendering")) {
|
||||
if (fr[0].matchWord("particleAlignment")) {
|
||||
if (fr[1].matchWord("BILLBOARD")) {
|
||||
myobj.setParticleAlignment(osgParticle::ParticleSystem::BILLBOARD);
|
||||
fr += 2;
|
||||
itAdvanced = true;
|
||||
}
|
||||
if (fr[1].matchWord("FIXED")) {
|
||||
myobj.setParticleAlignment(osgParticle::ParticleSystem::FIXED);
|
||||
fr += 2;
|
||||
itAdvanced = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (fr[0].matchWord("alignVectorX")) {
|
||||
osg::Vec3 v;
|
||||
if (fr[1].getFloat(v.x()) && fr[2].getFloat(v.y()) && fr[3].getFloat(v.z())) {
|
||||
myobj.setAlignVectorX(v);
|
||||
fr += 4;
|
||||
itAdvanced = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (fr[0].matchWord("alignVectorY")) {
|
||||
osg::Vec3 v;
|
||||
if (fr[1].getFloat(v.x()) && fr[2].getFloat(v.y()) && fr[3].getFloat(v.z())) {
|
||||
myobj.setAlignVectorY(v);
|
||||
fr += 4;
|
||||
itAdvanced = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (fr[0].matchWord("doublePassRendering")) {
|
||||
if (fr[1].matchWord("TRUE")) {
|
||||
myobj.setDoublePassRendering(true);
|
||||
fr += 2;
|
||||
@@ -96,7 +127,23 @@ bool ParticleSystem_writeLocalData(const osg::Object &obj, osgDB::Output &fw)
|
||||
{
|
||||
const osgParticle::ParticleSystem &myobj = static_cast<const osgParticle::ParticleSystem &>(obj);
|
||||
|
||||
fw.indent() << "DoublePassRendering ";
|
||||
fw.indent() << "particleAlignment ";
|
||||
switch (myobj.getParticleAlignment()) {
|
||||
default:
|
||||
case osgParticle::ParticleSystem::BILLBOARD:
|
||||
fw << "BILLBOARD" << std::endl;
|
||||
break;
|
||||
case osgParticle::ParticleSystem::FIXED:
|
||||
fw << "FIXED" << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
osg::Vec3 v = myobj.getAlignVectorX();
|
||||
fw.indent() << "alignVectorX " << v.x() << " " << v.y() << " " << v.z() << std::endl;
|
||||
v = myobj.getAlignVectorY();
|
||||
fw.indent() << "alignVectorY " << v.x() << " " << v.y() << " " << v.z() << std::endl;
|
||||
|
||||
fw.indent() << "doublePassRendering ";
|
||||
if (myobj.getDoublePassRendering())
|
||||
fw << "TRUE" << std::endl;
|
||||
else
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace
|
||||
}
|
||||
|
||||
osgParticle::Particle::Particle()
|
||||
: shape_(QUAD),
|
||||
: shape_(QUAD),
|
||||
sr_(0.2f, 0.2f),
|
||||
ar_(1, 0),
|
||||
cr_(osg::Vec4(1, 1, 1, 1), osg::Vec4(1, 1, 1, 1)),
|
||||
@@ -78,16 +78,15 @@ bool osgParticle::Particle::update(double dt)
|
||||
return true;
|
||||
}
|
||||
|
||||
void osgParticle::Particle::render(const osg::Matrix &modelview, float scale) const
|
||||
void osgParticle::Particle::render(const osg::Vec3 &xpos, const osg::Vec3 &px, const osg::Vec3 &py, float scale) const
|
||||
{
|
||||
osg::Vec3 xpos = modelview.preMult(position_);
|
||||
|
||||
glColor4f( current_color_.x(),
|
||||
glColor4f( current_color_.x(),
|
||||
current_color_.y(),
|
||||
current_color_.z(),
|
||||
current_color_.w() * current_alpha_);
|
||||
|
||||
float cs = current_size_ * scale;
|
||||
osg::Vec3 p1(px * current_size_ * scale);
|
||||
osg::Vec3 p2(py * current_size_ * scale);
|
||||
|
||||
switch (shape_)
|
||||
{
|
||||
@@ -97,26 +96,26 @@ void osgParticle::Particle::render(const osg::Matrix &modelview, float scale) co
|
||||
|
||||
case QUAD:
|
||||
glTexCoord2f(0, 0);
|
||||
glVertex3f(xpos.x() - cs, xpos.y() - cs, xpos.z());
|
||||
glVertex3fv((xpos-p1-p2).ptr());
|
||||
glTexCoord2f(1, 0);
|
||||
glVertex3f(xpos.x() + cs, xpos.y() - cs, xpos.z());
|
||||
glVertex3fv((xpos+p1-p2).ptr());
|
||||
glTexCoord2f(1, 1);
|
||||
glVertex3f(xpos.x() + cs, xpos.y() + cs, xpos.z());
|
||||
glVertex3fv((xpos+p1+p2).ptr());
|
||||
glTexCoord2f(0, 1);
|
||||
glVertex3f(xpos.x() - cs, xpos.y() + cs, xpos.z());
|
||||
glVertex3fv((xpos-p1+p2).ptr());
|
||||
break;
|
||||
|
||||
case QUAD_TRIANGLESTRIP:
|
||||
// we must glBegin() and glEnd() here, because each particle is a single strip
|
||||
glBegin(GL_TRIANGLE_STRIP);
|
||||
glTexCoord2f(1, 1);
|
||||
glVertex3f(xpos.x() + cs, xpos.y() + cs, xpos.z());
|
||||
glVertex3fv((xpos+p1+p2).ptr());
|
||||
glTexCoord2f(0, 1);
|
||||
glVertex3f(xpos.x() - cs, xpos.y() + cs, xpos.z());
|
||||
glVertex3fv((xpos-p1+p2).ptr());
|
||||
glTexCoord2f(1, 0);
|
||||
glVertex3f(xpos.x() + cs, xpos.y() - cs, xpos.z());
|
||||
glVertex3fv((xpos+p1-p2).ptr());
|
||||
glTexCoord2f(0, 0);
|
||||
glVertex3f(xpos.x() - cs, xpos.y() - cs, xpos.z());
|
||||
glVertex3fv((xpos-p1-p2).ptr());
|
||||
glEnd();
|
||||
break;
|
||||
|
||||
@@ -124,21 +123,28 @@ void osgParticle::Particle::render(const osg::Matrix &modelview, float scale) co
|
||||
// we must glBegin() and glEnd() here, because each particle is a single fan
|
||||
glBegin(GL_TRIANGLE_FAN);
|
||||
glTexCoord2f(0.5f, 0.5f);
|
||||
glVertex3f(xpos.x(), xpos.y(), xpos.z());
|
||||
glVertex3fv(xpos.ptr());
|
||||
glTexCoord2f(hex_texcoord_x1, hex_texcoord_y1);
|
||||
glVertex3f(xpos.x() + cs * cosPI3, xpos.y() + cs * sinPI3, xpos.z());
|
||||
glVertex3fv((xpos+p1*cosPI3+p2*sinPI3).ptr());
|
||||
//glVertex3f(xpos.x() + cs * cosPI3, xpos.y() + cs * sinPI3, xpos.z());
|
||||
glTexCoord2f(hex_texcoord_x2, hex_texcoord_y1);
|
||||
glVertex3f(xpos.x() - cs * cosPI3, xpos.y() + cs * sinPI3, xpos.z());
|
||||
glVertex3fv((xpos-p1*cosPI3+p2*sinPI3).ptr());
|
||||
//glVertex3f(xpos.x() - cs * cosPI3, xpos.y() + cs * sinPI3, xpos.z());
|
||||
glTexCoord2f(0, 0.5f);
|
||||
glVertex3f(xpos.x() - cs, xpos.y(), xpos.z());
|
||||
glVertex3fv((xpos-p1).ptr());
|
||||
//glVertex3f(xpos.x() - cs, xpos.y(), xpos.z());
|
||||
glTexCoord2f(hex_texcoord_x2, hex_texcoord_y2);
|
||||
glVertex3f(xpos.x() - cs * cosPI3, xpos.y() - cs * sinPI3, xpos.z());
|
||||
glVertex3fv((xpos-p1*cosPI3-p2*sinPI3).ptr());
|
||||
//glVertex3f(xpos.x() - cs * cosPI3, xpos.y() - cs * sinPI3, xpos.z());
|
||||
glTexCoord2f(hex_texcoord_x1, hex_texcoord_y2);
|
||||
glVertex3f(xpos.x() + cs * cosPI3, xpos.y() - cs * sinPI3, xpos.z());
|
||||
glVertex3fv((xpos+p1*cosPI3-p2*sinPI3).ptr());
|
||||
//glVertex3f(xpos.x() + cs * cosPI3, xpos.y() - cs * sinPI3, xpos.z());
|
||||
glTexCoord2f(1, 0.5f);
|
||||
glVertex3f(xpos.x() + cs, xpos.y(), xpos.z());
|
||||
glVertex3fv((xpos+p1).ptr());
|
||||
//glVertex3f(xpos.x() + cs, xpos.y(), xpos.z());
|
||||
glTexCoord2f(hex_texcoord_x1, hex_texcoord_y1);
|
||||
glVertex3f(xpos.x() + cs * cosPI3, xpos.y() + cs * sinPI3, xpos.z());
|
||||
glVertex3fv((xpos+p1*cosPI3+p2*sinPI3).ptr());
|
||||
//glVertex3f(xpos.x() + cs * cosPI3, xpos.y() + cs * sinPI3, xpos.z());
|
||||
glEnd();
|
||||
break;
|
||||
|
||||
|
||||
@@ -12,12 +12,16 @@
|
||||
#include <osg/BlendFunc>
|
||||
#include <osg/TexEnv>
|
||||
#include <osg/Material>
|
||||
#include <osg/Notify>
|
||||
|
||||
#include <osgDB/ReadFile>
|
||||
|
||||
osgParticle::ParticleSystem::ParticleSystem()
|
||||
: osg::Drawable(),
|
||||
def_bbox_(osg::Vec3(-10, -10, -10), osg::Vec3(10, 10, 10)),
|
||||
alignment_(BILLBOARD),
|
||||
align_X_axis_(1, 0, 0),
|
||||
align_Y_axis_(0, 1, 0),
|
||||
doublepass_(false),
|
||||
frozen_(false),
|
||||
display_list_id_(-1),
|
||||
@@ -39,6 +43,9 @@ osgParticle::ParticleSystem::ParticleSystem()
|
||||
osgParticle::ParticleSystem::ParticleSystem(const ParticleSystem ©, const osg::CopyOp ©op)
|
||||
: osg::Drawable(copy, copyop),
|
||||
def_bbox_(copy.def_bbox_),
|
||||
alignment_(copy.alignment_),
|
||||
align_X_axis_(copy.align_X_axis_),
|
||||
align_Y_axis_(copy.align_Y_axis_),
|
||||
doublepass_(copy.doublepass_),
|
||||
frozen_(copy.frozen_),
|
||||
display_list_id_(-1),
|
||||
@@ -89,10 +96,10 @@ void osgParticle::ParticleSystem::drawImmediateMode(osg::State &state)
|
||||
last_frame_ = state.getFrameStamp()->getFrameNumber();
|
||||
|
||||
// get the current modelview matrix
|
||||
const osg::Matrix &modelview = state.getModelViewMatrix();
|
||||
osg::Matrix modelview = state.getModelViewMatrix();
|
||||
|
||||
// set modelview = identity
|
||||
state.applyModelViewMatrix(0);
|
||||
if (alignment_ == BILLBOARD)
|
||||
state.applyModelViewMatrix(0);
|
||||
|
||||
// set up depth mask for first rendering pass
|
||||
glPushAttrib(GL_DEPTH_BUFFER_BIT);
|
||||
@@ -108,17 +115,17 @@ void osgParticle::ParticleSystem::drawImmediateMode(osg::State &state)
|
||||
|
||||
#ifdef USE_SEPERATE_COMPILE_AND_EXECUTE
|
||||
glNewList(display_list_id_, GL_COMPILE);
|
||||
single_pass_render(modelview);
|
||||
single_pass_render(state, modelview);
|
||||
glEndList();
|
||||
glCallList(display_list_id_);
|
||||
#else
|
||||
glNewList(display_list_id_, GL_COMPILE_AND_EXECUTE);
|
||||
single_pass_render(modelview);
|
||||
single_pass_render(state, modelview);
|
||||
glEndList();
|
||||
#endif
|
||||
|
||||
} else {
|
||||
single_pass_render(modelview);
|
||||
single_pass_render(state, modelview);
|
||||
}
|
||||
|
||||
// restore depth mask settings
|
||||
@@ -175,7 +182,7 @@ void osgParticle::ParticleSystem::setDefaultAttributes(const std::string &textur
|
||||
}
|
||||
|
||||
|
||||
void osgParticle::ParticleSystem::single_pass_render(const osg::Matrix &modelview)
|
||||
void osgParticle::ParticleSystem::single_pass_render(osg::State & /*state*/, const osg::Matrix &modelview)
|
||||
{
|
||||
draw_count_ = 0;
|
||||
if (particles_.size() <= 0) return;
|
||||
@@ -193,8 +200,18 @@ void osgParticle::ParticleSystem::single_pass_render(const osg::Matrix &modelvie
|
||||
i->beginRender();
|
||||
i0 = i;
|
||||
}
|
||||
++draw_count_;
|
||||
i->render(modelview, sqrtf(static_cast<float>(detail_)));
|
||||
++draw_count_;
|
||||
|
||||
switch (alignment_) {
|
||||
case BILLBOARD:
|
||||
i->render(modelview.preMult(i->getPosition()), osg::Vec3(1, 0, 0), osg::Vec3(0, 1, 0), sqrtf(static_cast<float>(detail_)));
|
||||
break;
|
||||
case FIXED:
|
||||
i->render(i->getPosition(), align_X_axis_, align_Y_axis_, sqrtf(static_cast<float>(detail_)));
|
||||
break;
|
||||
default: ;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user