bool TurbulenceParticleAffector::affect(ParticleSystemRefPtr System, Int32 ParticleIndex, const Time& elps) { if(getBeacon() != NULL) { Matrix BeaconToWorld(getBeacon()->getToWorld()); Vec3f translation, tmp; Quaternion tmp2; BeaconToWorld.getTransform(translation,tmp2,tmp,tmp2); Pnt3f particlePos = System->getPosition(ParticleIndex); Real32 distanceFromAffector = particlePos.dist(Pnt3f(translation.x(),translation.y(),translation.z())); if((getMaxDistance() < 0.0) || (distanceFromAffector <= getMaxDistance())) //only affect the particle if it is in range { Real32 Xparam, Yparam, Zparam; Pnt3f pos(System->getPosition(ParticleIndex)); getPerlinDistribution()->setPhase(getPhase()[0]); Xparam = getPerlinDistribution()->generate(pos[0]); getPerlinDistribution()->setPhase(getPhase()[1]); Yparam = getPerlinDistribution()->generate(pos[1]); getPerlinDistribution()->setPhase(getPhase()[2]); Zparam = getPerlinDistribution()->generate(pos[2]); Vec3f fieldAffect(Vec3f(Xparam, Yparam, Zparam)); fieldAffect = fieldAffect * (getAmplitude()* (elps/(OSG::osgClamp<Real32>(1.0f,std::pow(distanceFromAffector,getAttenuation()),TypeTraits<Real32>::getMax())))); System->setVelocity(System->getVelocity(ParticleIndex) + fieldAffect, ParticleIndex); } // end distance conditional } // end null beacon conditional return false; }
bool VortexParticleAffector::affect(ParticleSystemRefPtr System, Int32 ParticleIndex, const Time& elps) { if(getBeacon() != NULL) { Matrix BeaconToWorld(getBeacon()->getToWorld()); Vec3f translation, tmp; Quaternion tmp2; BeaconToWorld.getTransform(translation,tmp2,tmp,tmp2); Pnt3f particlePos = System->getPosition(ParticleIndex); Real32 distanceFromAffector = particlePos.dist(Pnt3f(translation.x(),translation.y(),translation.z())); if((getMaxDistance() < 0.0) || (distanceFromAffector <= getMaxDistance())) //only affect the particle if it is in range { Vec3f particleDirectionFromVortex(particlePos.x() - translation.x(), particlePos.y() - translation.y(), particlePos.z() - translation.z()); particleDirectionFromVortex = particleDirectionFromVortex.cross(getVortexAxis()); particleDirectionFromVortex.normalize(); particleDirectionFromVortex = particleDirectionFromVortex * ((-getMagnitude() * elps)/OSG::osgClamp<Real32>(1.0f,std::pow(distanceFromAffector,getAttenuation()),TypeTraits<Real32>::getMax())); System->setVelocity(particleDirectionFromVortex + System->getVelocity(ParticleIndex),ParticleIndex); } } return false; }
Real32 OctreeAStarAlgorithm::euclideanDistanceCost(Octree::OTNodePtr node, const Pnt3f& Location, Real32 CostPerUnit) { Pnt3f Target; node->getVolume().getCenter(Target); return CostPerUnit * Location.dist(Target); }
Real32 DistanceLOD::calcDistance(DrawActionBase *pAction, const Matrix &mToWorld) { Matrix m; m.invertFrom(mToWorld); m.mult(pAction->getCameraToWorld()); Pnt3f eyepos; m.mult(eyepos, eyepos); _lastDist = eyepos.dist(getCenter()); return _lastDist; }
vector<Pnt3f> createControlPoints(int lineIndex, Pnt3f p1, Pnt3f p2, int thres){ vector<Pnt3f> result; Vec3f vec = p2 - p1; //cout << "start: "<<p1<<endl; //cout << "end: "<<p2<<endl; float len3D = p1.dist(p2); //cout <<"len3d: "<< len3D<<endl; //MY 2D-POINTS GLdouble modelview[16], projection2[16]; GLint viewport[4]; glGetDoublev(GL_MODELVIEW_MATRIX, modelview); glGetDoublev(GL_PROJECTION_MATRIX, projection2); glGetIntegerv(GL_VIEWPORT, viewport); double x,y,z; gluProject(p1[0], p1[1], p1[2], modelview, projection2, viewport, &x,&y,&z); Pnt2d tmp2d; tmp2d[0] = x; tmp2d[1] = y; double x1,y1,z1; gluProject(p2[0], p2[1], p2[2], modelview, projection2, viewport, &x1,&y1,&z1); Pnt2d tmp2d1; tmp2d1[0] = x1; tmp2d1[1] = y1; // length of 2D edge float len2D = tmp2d.dist(tmp2d1); float stepsize; //if(len2D < 10) // return result; if(len2D > 100){ //cout << "len2d: " << len2D<<endl; float perc = CHECK_PIXEL * 100 / len2D; //cout << "perc: "<<perc<<endl; stepsize = /*len3D */ perc / 100 / thres;} else { stepsize = 0.5 /thres; } // calculate length //float length = sqrt(vec[0]*vec[0] + vec[1]*vec[1] + vec[2]*vec[2]); //cout << "::: " << length<<endl; //if (len3D < 0.1) // return result; //every 5% of the line //float stepsize = 0.5 / thres; //float stepsize = (len3D * 0.05) / perc; stepsize = stepsize; //cout << "stepsize: " << stepsize<<endl; float high = tmp2d[1]-tmp2d1[1]; //cout << "high: "<<high<<endl; if(-10 < high && high < 10 && stepsize < 0.25){ //return result; stepsize = stepsize / 2; } //float stepsize = random / thres; for(int i(1);i*stepsize <= 1;i++) { //cout << "fuu: "<< i*stepsize<<endl; //cout << " cp at ->"<< p1+i*step*vec; Pnt3f np; np[0] = p1[0] + (stepsize*i) * vec[0]; np[1] = p1[1] + (stepsize*i) * vec[1]; np[2] = p1[2] + (stepsize*i) * vec[2]; // stop - in case of longer line calc //if((stepsize*i) >= len3D) // break; //cout << np[0] << " " << np[1] << " " << np[2] <<endl; //_CONTROLPOINTS.push_back(np); if(rand()%3 == 0) result.push_back(np); //if(thres>7) // result.push_back(np); //if(-10 < high < 10 && stepsize >= 0.25 ) // result.push_back(np); } //if(result.size() < 10) // result.clear(); _CONTROLPOINTS[lineIndex] = result; //exit(0); return result; }