PDA

View Full Version : [C++ and DirectX] Spring physics simulation



Mato
07-16-2012, 03:58 PM
It came to my mind that i had done this little project a few months back before starting to work with runescape so i thought maybe someone wants to play with it :) So it is a 2D simulation where you can build some structure with balls and attach springs to them so the springs will try to keep the distance between the balls that what it was originally.

Left click to place a green freely moving ball and space + left click to place a red ball that is static and will not move. To delete a ball, hold numpad 1 and left click it. To set a spring between 2 balls, right click one ball and then right click the other ball and you will see a blue line appear between them, that is the spring. By holding the mouse scroll down and moving the mouse you can move everything in the world so the area doesnt limit to the area you see. When you have built enough, press numpad 7 so the simulation starts running. You can also pause the simulation with numpad 7, make some changes and unpause it if you want and you can add balls and springs at runtime too. You cannot drag the balls, all you can do atm is to edit the gravity by up and down arrow keys.

An example structure i made to show how you can test it, just for example:
http://i50.tinypic.com/2nsapu8.png

I uploaded it here because the file is too large to upload as an attachment: http://www.filefactory.com/file/3c6ad7h9ejxd/n/DXSpring_rar
Another download link: http://www.sendspace.com/file/elhr0k

F-Secure (and probably other antivirus programs too) say that the .exe is a virus, that is because i have included the graphics inside it, you can see them in files.h in the source code. If you dont trust me, you are free to check the source and recompile it yourself and see that it says the same thing.

The compiled .exe is at DXSpring/Release folder if you just want to test it. The graphics arent very fancy, just made them quick with SumoPaint. There is no save/load option so dont spend like 2 hours building a huge thing and then accidentally close the thing :p

EDIT: Oh and if it says that d3dx_43.dll is missing or something like that, you need the newest directx: Download here (http://www.microsoft.com/en-us/download/details.aspx?id=8109)
And if it still doesnt run, you might not have the redistributable: x64 Download (http://www.microsoft.com/en-US/download/details.aspx?id=15336) or x86 Download (http://www.microsoft.com/en-US/download/details.aspx?id=29)

Recursive
07-16-2012, 04:41 PM
Use a different site to upload it, filefactory is being a beech

Mato
07-16-2012, 04:52 PM
There you go, try the other link.

Mark
07-16-2012, 06:36 PM
Nice work.
what was your idea with this where you creating a game of some sort if so how come you discarded it

Mato
07-16-2012, 06:53 PM
I wasnt creating a game, this was just a little project to do for fun. I wanted to do another one too that would use the real mass-spring-damper equation so it would solve the equation to get the real position at the point of time, as this is just using euler integration in 50 steps so it isnt that accurate. The reason i didnt do it is that im in highschool 1st grade so my math knowledge isnt so good that i could handle the equation well enough.

tristen8878
10-11-2012, 06:55 PM
Very nice good physics for a game engine though I've been working on a game engine written in java and uses opengl api so the performance can be boosted by a lot. It's going good am going to have to work on physics soon for my engine because I want to implement rag-doll and things like that got any tips?