Archived

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

BGCJR

Magnetic field simulator

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 this post


Link to post
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 float GetSphereRadius() = 0;
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]

Share this post


Link to post
Share on other sites