Real32 OctreeAStarAlgorithm::manhattanDistanceCost(Octree::OTNodePtr node,
                                                   const Pnt3f& Location,
                                                   Real32 CostPerUnit)
{
    Pnt3f Target;
    node->getVolume().getCenter(Target);
    return CostPerUnit * (osgAbs(Location.x() - Target.x())
                        + osgAbs(Location.y() - Target.y())
                        + osgAbs(Location.z() - Target.z()));
}
Pnt3f randomOpenPosition(const Pnt3f& Min,
                         const Pnt3f& Max,
                         OctreePtr TheOctree)
{
    Pnt3f Result;
    do
    {
        Result.setValues(RandomPoolManager::getRandomReal32(Min.x(),Max.x()),
                         RandomPoolManager::getRandomReal32(Min.y(),Max.y()),
                         RandomPoolManager::getRandomReal32(Min.z(),Max.z()));
    }while(!TheOctree->getNodeThatContains(Result)->isEmpty());

    return Result;
}
NodeTransitPtr OctreeVisualization::createNodeGeo(OctreePtr,
                                                  const Octree::OTNodePtr node,
                                                  Material* GeoMaterial,
                                                  const Node* BaseGeo)
{
    //Make the Geoemtry
    NodeRecPtr box = deepCloneTree(BaseGeo);

    dynamic_cast<Geometry*>(box->getCore())->setMaterial(GeoMaterial);

    Matrix m;
    TransformRecPtr box_trans;
    NodeRecPtr trans_node = makeCoredNode<Transform>(&box_trans);
    Pnt3f Center;
    node->getVolume().getCenter(Center);
    m.setTranslate( Center.x(), Center.y(), Center.z());

    const Real32 Offset(0.0f);
    Vec3f Size;
    node->getVolume().getSize(Size);
    m.setScale(Size.x()-(Size.x()*Offset), Size.y()-(Size.y()*Offset), Size.z()-(Size.z()*Offset));
    box_trans->setMatrix(m);
    trans_node->addChild(box);

    return NodeTransitPtr(trans_node);
}
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;
}
Exemple #5
0
void FModSound::setChannelPosition(const Pnt3f &pos, UInt32 ChannelID)
{
    FMOD::Channel* channel(getChannel(ChannelID));
    if(channel != NULL)
    {
        FMOD_RESULT result;

        FMOD_MODE TheMode;
        result = channel->getMode(&TheMode);
        FMOD_ERRCHECK(result,"FModSound::setChannelPosition()");
        if(result == FMOD_OK && TheMode & FMOD_3D)
        {
            FMOD_VECTOR curPos;
            FMOD_VECTOR curVec;

            result = channel->get3DAttributes(&curPos, &curVec);
            FMOD_ERRCHECK(result,"FModSound::setChannelPosition()");

            curPos.x = pos.x();
            curPos.y = pos.y();
            curPos.z = pos.z();

            result = channel->set3DAttributes(&curPos, &curVec);
            FMOD_ERRCHECK(result,"FModSound::setChannelPosition()");
        }
    }
}
bool RandomMovementParticleAffector::affect(ParticleSystemRefPtr System, Int32 ParticleIndex, const Time& elps)
{
    //System->setUpdateSecAttribs(false);
    Real32 x,
           y,
           z,
           age(System->getAge(ParticleIndex));

    if(getAttributeAffected() == VELOCITY_ATTRIBUTE)
    {
        Vec3f vel = System->getSecVelocity(ParticleIndex);
        // grab each value independently , and adjust the phase for each
        // axis, since we have a 3D phase and the 1D distribution only takes
        // one value
        Real32 velSum = vel.x() + vel.y() + vel.z();

        getPerlinDistribution()->setPhase(getPhase().x() + velSum);
        x = getPerlinDistribution()->generate(vel.x() + age);
        getPerlinDistribution()->setPhase(getPhase().y() + velSum);
        y = getPerlinDistribution()->generate(vel.y() + age);
        getPerlinDistribution()->setPhase(getPhase().z() + velSum);
        z = getPerlinDistribution()->generate(vel.z() + age);


        System->setVelocity(Vec3f(x,y,z) + vel,ParticleIndex);

    }else // affecting position	
    {
        Pnt3f pos = System->getSecPosition(ParticleIndex);
        Real32 posSum = pos.x() + pos.y() + pos.z();

        getPerlinDistribution()->setPhase(getPhase().x() + posSum);
        x = getPerlinDistribution()->generate(pos.x() + age);
        getPerlinDistribution()->setPhase(getPhase().y() + posSum);
        y = getPerlinDistribution()->generate(pos.y() + age);
        getPerlinDistribution()->setPhase(getPhase().z() + posSum);
        z = getPerlinDistribution()->generate(pos.z() + age);


        System->setPosition(Pnt3f(x,y,z) + pos.subZero(),ParticleIndex);
    }

    return false;
}
bool FrustumVolume::intersect(const Pnt3f &point) const
{
    bool retCode = true;

    for(Int32 i = 0; i < 6; i++) 
    {
        if((_planeVec[i].getNormal().x() * point.x() +
            _planeVec[i].getNormal().y() * point.y() +
            _planeVec[i].getNormal().z() * point.z() -
            _planeVec[i].getDistanceFromOrigin()     ) < 0.f) 
        {
            retCode = false;
            break;
        }
    }
    
    return retCode;
}
NodeTransitPtr OctreeVisualization::createNodeDistanceLOD(OctreePtr,
                                                          const Octree::OTNodePtr node,
                                                          Material* GeoMaterial,
                                                          const Node* BaseGeo,
                                                          Real32 Range
                                                         )
{
    NodeRecPtr box = deepCloneTree(BaseGeo);
    dynamic_cast<Geometry*>(box->getCore())->setMaterial(GeoMaterial);

    //DistanceLOD node
    DistanceLODRecPtr LOD = DistanceLOD::create();
    LOD->editMFRange()->push_back(10.0);

    NodeRecPtr LODNode = makeNodeFor(LOD);
    LODNode->addChild(box);
    LODNode->addChild(makeCoredNode<Group>());

    Matrix m;
    TransformRecPtr box_trans;
    NodeRecPtr trans_node = makeCoredNode<Transform>(&box_trans);
    Pnt3f Center;
    node->getVolume().getCenter(Center);
    m.setTranslate(Center.x(),
                   Center.y(),
                   Center.z());

    const Real32 Offset(0.0f);
    Vec3f Size;
    node->getVolume().getSize(Size);
    m.setScale(Size.x()-(Size.x()*Offset),
               Size.y()-(Size.y()*Offset),
               Size.z()-(Size.z()*Offset));
    box_trans->setMatrix(m);
    trans_node->addChild(LODNode);

    return NodeTransitPtr(trans_node);
}