예제 #1
0
void makeExplosion(Pnt3f Location, Real32 Impulse)
{
    for(UInt32 i(0) ; i<allPhysicsBodies.size() ; ++i)
    {
        Vec3f Direction(allPhysicsBodies[i]->getPosition()-Location.subZero());

        Real32 Distance(Direction.length());
        Direction.normalize();

        allPhysicsBodies[i]->addForce(physicsWorld->impulseToForce(physHandler->getStepSize(), Direction*Impulse*(1.0f/Distance)));
        //The bodies need to be enabled because they may be auto-disabled when they
        //come to rest
        //The bodies are not re-enabled untill a new collision is detected
        allPhysicsBodies[i]->setEnable(true);
    }
}
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;
}
예제 #3
0
void vec2pnttest(void)
{
          Vec3f v (3.f, 3.f, 3.f);
    const Vec3f cv(2.f, 2.f, 2.f);

          Pnt3f  p(5.f, 5.f, 5.f);
    const Pnt3f cp(8.f, 8.f, 8.f);

    v = p.subZero();

    fprintf(stderr, "%f %f %f\n", v[0], v[1], v[2]);

    v = cp.subZero();

    fprintf(stderr, "%f %f %f\n", v[0], v[1], v[2]);

//    p = v;

//    p = cv;
}
ParticleSystemCore::ParticleSortByViewPosition::ParticleSortByViewPosition(const ParticleSystem* TheSystem, Pnt3f TheCameraPos, bool SortByMinimum) 
	: _System(TheSystem), _CameraPos(TheCameraPos.subZero()), _SortByMinimum(SortByMinimum)
{
}
void SkeletonBlendedGeometry::calculatePositions(void)
{
	if(getBaseGeometry() == NULL)
	{
		//Error
		SWARNING << "SkeletonBlendedGeometry::calculatePositions(): Base Geometry is NULL." << std::endl;
        return;
	if(getPositions() == NULL)
	{
		//Error
		SWARNING << "SkeletonBlendedGeometry::calculatePositions(): Positions is NULL." << std::endl;
        return;
	}
	if(getBaseGeometry()->getPositions() == NULL)
	{
		//Error
		SWARNING << "SkeletonBlendedGeometry::calculatePositions(): Base Geometry Postions is NULL." << std::endl;
        return;
	}
	if(getMFPositionIndexes()->size() != getMFJoints()->size())
	{
		//Error
		SWARNING << "SkeletonBlendedGeometry::calculatePositions(): Positions Indexes size is not the same as the affecting Joints size." << std::endl;
        return;
	}
	}
	if(getMFPositionIndexes()->size() != getMFBlendAmounts()->size())
	{
		//Error
		SWARNING << "SkeletonBlendedGeometry::calculatePositions(): Positions Indexes size is not the same as the affecting blend amount size." << std::endl;
        return;
	}

    Pnt3f CalculatedPoint;
    Pnt3f PointTemp;
    Vec3f CalculatedNormal;


    //Set the values of all points to 0
    for (int i(0); i < getPositions()->size(); ++i)
    {
        getPositions()->setValue(Pnt3f(0, 0, 0), i);
    }

    //Update the Positions and Normals
    for(UInt32 i(0) ; i < getMFPositionIndexes()->size() ; ++i)
    {

        Matrix temp = getJoints(i)->getAbsoluteDifferenceTransformation();
        temp.scale(getBlendAmounts(i));
        getBaseGeometry()->getPositions()->getValue<Pnt3f>(PointTemp, getPositionIndexes(i));
        temp.mult(PointTemp, CalculatedPoint);
        //temp.mult(getBaseGeometry()->getNormals()->getValue(getPositionIndexes(i)), CalculatedNormal);
        

        //Add
        CalculatedPoint += PointTemp.subZero();
        getPositions()->setValue<Pnt3f>(CalculatedPoint, getPositionIndexes(i));
    }

    for(UInt32 i = 0; i < _mfParents.size(); i++)
    {
        _mfParents[i]->invalidateVolume();
    }

    _volumeCache.setValid();
    _volumeCache.setEmpty();
}