Not logged in, Join Here! or Log In Below:  
 
News Articles Search    
 


Submitted by Lee Mazurek, posted on January 28, 2002




Image Description, by Lee Mazurek



Here is a charged particle simulator I wrote for physics class. The teacher was using some electron hockey game one day, and he made a comment about how expensive it was. I then set out to program it myself, and sell my own particle simulator cheaply. Hopefully schools will buy it.

The program uses SDL in combination with OpenGL. There is not really anything special about the graphics, and the physics are brute force unoptimized. One of the ways I cheat on the physics however is to allow the graphics card to do the interpolation of the potential field rather than doing it all myself.

It is nice to get a complete program done, as I have been programming for quite some time and have not made anything that was finished (I have a huge code base of highly optimized 3/4 finished game libraries). My project to end all projects is still pending.

The simulator also include a game mode of course where the goal is to get the particle into the goal. Try it out, it was rather amusing to see my roomates be engrossed by such a simple game.

Editor's Note: The demo is available for download here (162k)


[prev]
Image of the Day Gallery
www.flipcode.com

[next]

 
Message Center / Reader Comments: ( To Participate in the Discussion, Join the Community )
 
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.
 
MK42

January 28, 2002, 02:42 PM

Yep, that worked for me as well!

Thanks!

- Marco

 
SirKnight

January 28, 2002, 02:52 PM

Hey thats pretty cool. We are doing things like that with charges and whatnot in physics right now. I may just have to show my professor your program. :)

-SirKnight

 
MirekCz

January 28, 2002, 03:25 PM

This program totally rocks!
That was best 15mins playing games I had since a LONG LONG time.
This game is really what hobbist programers make at best, simple, yet well designed and flawlessly working. I LOVE IT!:)
The only thing is that it's quite simple...(I was quite often able to beat levels with just 1 or 2 charges, never used more then 4 and I did play 25 levels at least) althrought it might be a great challenge for some young students at schools etc.

The only thing that was disturbing me, at least at the beggining, was that I'm used to drag&drop and therefore I tryed to press the button, move a charge and release button. While the program expects me to press button, release button, move charge, press button again and release button..., but it's just a detail that was easily sunk in the sea of pure gameplay you created. Really good work, congrats:)))

 
ghost007

January 28, 2002, 03:44 PM

Man, this is a seriously cool program. I've always loved programs that apply the laws of physics.

BTW, any cheats for this game?? =) =)

 
337

January 28, 2002, 04:15 PM

First, sorry everyone, I thought this would be more of a demo and not a debug session. The pic of the day was abused by myself.

Thanks for all the suggestions everyone, I believe now it is actually keyboard related. That was wierd that it was shutting down alright. My keyboard check code checks for any message that has the SDLK_ESCAPE keycode, and not for its actual state. Here is an excerpt from the SDL source code...

/* We lost the keyboard, so post key up messages for all pressed keys */

I fixed the escape problem and changed the drag drop behavior.

I am indebted to you all, so here is some public domain source code http://mazurek.net/physics/hidden/partsource.zip, please don't email me and tell me about the quality/trashiness of the source. Its just there for those who want to see it.

 
337

January 28, 2002, 04:16 PM

Nope, no cheats, and no violence. My roommate wanted to have the particle puncture people, and he also wanted a no point subtraction cheat, but now I am officially done so no more.

 
Skeet

January 28, 2002, 04:29 PM

same:

APPLICATION LOG START
Time: Mon Jan 28 22:25:36 2002
log initialized file:C:cppelectron hockeylog.cpp line:37
initializing display file:C:cppelectron hockeyscenegraph.cpp line:81
set viewport/enabled blending, depthtest, smoothshading file:C:cppelectron hockeyscenegraph.cpp line:118
setting window caption file:C:cppelectron hockeyscenegraph.cpp line:125
pumping messages file:C:cppelectron hockeyscenegraph.cpp line:312
clearing gl window file:C:cppelectron hockeyscenegraph.cpp line:335
swapping buffers using SDL_GL_SwapBuffers file:C:cppelectron hockeyscenegraph.cpp line:376
pumping messages file:C:cppelectron hockeyscenegraph.cpp line:312
clearing gl window file:C:cppelectron hockeyscenegraph.cpp line:335
swapping buffers using SDL_GL_SwapBuffers file:C:cppelectron hockeyscenegraph.cpp line:376
shutting down display file:C:cppelectron hockeyscenegraph.cpp line:135



 
337

January 28, 2002, 05:26 PM

I was using a different method. You find the magnitude of the force with f = kq/r^2. Then the direction of the force is the line between them or p1-p2. The direction is normalized and then multiplied by the force. It is made to point away if charges repel and towards if attract.

 
337

January 28, 2002, 05:28 PM

whoops, should have thought before I posted in first place, what I am doing and what you do are exactly the same

 
Tam

January 28, 2002, 06:06 PM

Not XP here either. I have the same setup as you though.

1.4 gig Athlon
512 megs DDR
GeForce 3 Ti500
Win 2k Pro

Mine opens the window and then immediately fails as well.

 
Genu

January 28, 2002, 06:30 PM

This stuff is impressive. Could you apply your model to more complexe magnetic field?

louis
http://www.gel.ulaval.ca/~dumais01

 
Mattman

January 28, 2002, 06:40 PM

Same here :(

 
Mattman

January 28, 2002, 06:42 PM

Doesn't work here either.

Dell running Windows 98
Pentium III 800 MHz
128 MB RAM
NVIDIA GeForce2 AGP

 
337

January 28, 2002, 06:46 PM

I could probably compute the magnetic field too, we haven't yet gone over that in physics class though. Its just a list of particles and their velocities, I'll probably add that feature later

 
Politik

January 29, 2002, 01:03 AM

Its been a while since I've 'done' physics, but in this 2d view I dont believe the magnetic field matters. the resultant forces would be in/out of the screen, I think.

 
Sampsa Lehtonen

January 29, 2002, 02:42 AM

It works!

The user interface is a bit clumsy, I accidently pressed "quit game" when I was trying to place a charge near the buttons.
Otherwise very educating and fun to play ;)

 
RyseFtk

January 29, 2002, 03:53 AM

same:

APPLICATION LOG START
Time: Tue Jan 29 09:52:32 2002
log initialized file:C:cppelectron hockeylog.cpp line:37
initializing display file:C:cppelectron hockeyscenegraph.cpp line:81
set viewport/enabled blending, depthtest, smoothshading file:C:cppelectron hockeyscenegraph.cpp line:118
setting window caption file:C:cppelectron hockeyscenegraph.cpp line:125
pumping messages file:C:cppelectron hockeyscenegraph.cpp line:312
clearing gl window file:C:cppelectron hockeyscenegraph.cpp line:335
swapping buffers using SDL_GL_SwapBuffers file:C:cppelectron hockeyscenegraph.cpp line:376
pumping messages file:C:cppelectron hockeyscenegraph.cpp line:312
clearing gl window file:C:cppelectron hockeyscenegraph.cpp line:335
swapping buffers using SDL_GL_SwapBuffers file:C:cppelectron hockeyscenegraph.cpp line:376
shutting down display file:C:cppelectron hockeyscenegraph.cpp line:135




 
Wim Libaers

January 29, 2002, 01:07 PM

The magnetic field vectors may be perpendicular to the screen, but the forces on particles will be in the screen plane.

 
Chappa

January 30, 2002, 10:33 AM

Me too :


APPLICATION LOG START
Time: Wed Jan 30 16:28:40 2002
log initialized file:C:cppelectron hockeylog.cpp line:37
initializing display file:C:cppelectron hockeyscenegraph.cpp line:81
set viewport/enabled blending, depthtest, smoothshading file:C:cppelectron hockeyscenegraph.cpp line:118
setting window caption file:C:cppelectron hockeyscenegraph.cpp line:125
pumping messages file:C:cppelectron hockeyscenegraph.cpp line:312
clearing gl window file:C:cppelectron hockeyscenegraph.cpp line:335
swapping buffers using SDL_GL_SwapBuffers file:C:cppelectron hockeyscenegraph.cpp line:376
pumping messages file:C:cppelectron hockeyscenegraph.cpp line:312
clearing gl window file:C:cppelectron hockeyscenegraph.cpp line:335
swapping buffers using SDL_GL_SwapBuffers file:C:cppelectron hockeyscenegraph.cpp line:376
shutting down display file:C:cppelectron hockeyscenegraph.cpp line:135



 
Sniper BoB

January 30, 2002, 08:22 PM

I had the same problem, but the little debugger trick fixed it..... also ITS FUN! wow who'd have guessed..... i think you need to fix the drag though. When I release the mouse it stays. To drop the charge I need to click again, very annoying. You can make it work both ways. Single click to move, single click to place. Or drag to move and place.

Great work!

 
Mattman

January 30, 2002, 08:27 PM

Actually, the equation given was not incorrect. If you look again, there was an r in the numerator, representing the actually vector (including both the magnitude and direction), while the denominator contained |r|, which is just the magnitude of r. This equation reduces to the equation you gave, but it includes the direction of the vector E.

 
jojolinkybob

March 14, 2002, 05:23 PM

Awesome, something like this would have been splendid as a visual aid for Differential Equations back in college.

 
This thread contains 52 messages.
First Previous ( To view more messages, select a page: 0 1 ... out of 1) Next Last
 
 
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.