#### Archived

This topic is now archived and is closed to further replies.

# Magnetic field simulator

This topic is 5297 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

How many people know a way to do one? i thought maybe a particle for starts. then collision detection for each particle(sphere to sphere) then a charge (float) for each particle. I want to display a magnetic fields interact with different objects. Bobby

##### Share on other sites
I never tried anything like this, but if I did I would try this:

Psuedo:
void UpdateParticleSystem(float Delta){    //--The attractor object should have a bounding sphere    //--around and contain the sphere center and radius    //--    SomeAttractor Attractor = System->GetAttractor();//    for(int ParticleID = 0; ParticleID < NumParticles; ParticleID++)    {        //--The field affector would be the distance from the        //--attractor at which the particles start getting affected        //--        //--  Center + Radius + Affector Distance        //--  [ATTRACTOR]        //--  +----------+        //--  |          |        //--  |          |    Radius  Affector Distance        //--  |  Center--|------|o-----------|0        //--  |          |        //--  |          |        //--  +----------+        //--        //--        float FieldAffector = Attractor.GetSphereCenter() + Attractor.GetSphereRadius() + 25;//        //--Compute the distance between the particle and the        //--attractor        //--        //-- D = sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2))        Distance = ComputeDistance(Attractor.GetSphereCenter(), Particle[ParticleID].Position)//        //--Check if we should apply the magnetic field        //--        if(Distance <= (FieldAffector + Particle[ParticleID].Size))        {            //--Penetracted the field            //--            //--Now see if it collides with the attractor            //--            if(Distance <= (Attractor.GetSphereRadius() + Particle[ParticleID].Size))            {                //--Particle collided with the attractor, don't                //--update the particle. Also, set the particles                //--position to:                //--Attractor.GetSphereCenter() + Attractor.GetSphereRadius()                //--This is in case it penatrated the attractor, it                //--would set it back so it looks like it's stuck on                //--the attractor and not in the attractor.             }             else             {                 //--The particle didn't collide with the                 //--attractor, but it is in the magnetic field.                 //--Update the particles velocity to move                 //--toward the attractor             }        }        else        {            //--Particle did not collide, update the particle like normal        }    }}

Like I said I never tried something like this so I don't know if it will work. It should give you an idea of what I'm thinking though
I'm tired as hell so it may be a little off...

EDIT
BTW:
You could make a pure virtual class for the attractor object that way anything that inherits it can become an attractor?

class IATTRACTOR
{
public:
virtual VECTOR3 GetSphereCenter() = 0;
};

class SomeObject : public IATTRACTOR
{
//
};

//--In particle system:
void SetAttractor(IATTRACTOR* Attractor)
{
this->Attractor = Attractor;
}

//--Then just call it like this:
SomeObject Object;
//Initialize/setup the object
ParticleSystem->SetAttractor(&Object);

I hope you get where I'm going with this...

-UltimaX-
Ariel Productions
|Designing A Screen Shot System|

"You wished for a white christmas... Now go shovel your wishes!"

[edited by - UltimaX on March 19, 2004 1:18:10 AM]

1. 1
2. 2
3. 3
frob
20
4. 4
Rutin
19
5. 5

• 32
• 13
• 11
• 9
• 18
• ### Forum Statistics

• Total Topics
632555
• Total Posts
3007066

×