Need assistance with 2D physics project
If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
5 posts
Page 1 of 1
Hi,
for the past few days I've been working on a little 2D physics "engine" that i might or might not later use for a game of some sorts. I'm also planning to port it into DirectX once i get the hang of it and physics works. This is how a "testing window" looks:
*X & Y locations are where the cube will start from
*X & Y Initial sped is, you guessed it, the speed cubes will move with when spawned
*X & Y force is acceleration that is applied constantly, similar to wind/gravity
To cut to the chase, I'm a novice/amateur programmer and have quite quickly encountered some problems. The main one is, that with ever growing code i can't seem to find the issue itself.
So I am uploading the source in hopes that someone can help me on some issues i have with it:
Gif quality is very bad but in real time it's much more fluid and you can see those 3 kind of sticking together and swirling around.
:!: If you meddle with the code on button 1 (cube creation) and cube/wall code itself you will discover some pretty nice gravity effects (GIF). I have disabled them for now, as there are issues to fix.
- if you (default setup, no speed, just Y force = 1) stack them one on top of each other they will eventually fall trough the top one (cube count - 21 - on the image is higher than the amount of visible cubes)
- cube hi detection works VERY wierdly, they might pass trough each other when force is applied, same works with cube-wall hit detection
[read post below]
for the past few days I've been working on a little 2D physics "engine" that i might or might not later use for a game of some sorts. I'm also planning to port it into DirectX once i get the hang of it and physics works. This is how a "testing window" looks:
*X & Y locations are where the cube will start from
*X & Y Initial sped is, you guessed it, the speed cubes will move with when spawned
*X & Y force is acceleration that is applied constantly, similar to wind/gravity
To cut to the chase, I'm a novice/amateur programmer and have quite quickly encountered some problems. The main one is, that with ever growing code i can't seem to find the issue itself.
So I am uploading the source in hopes that someone can help me on some issues i have with it:
Gif quality is very bad but in real time it's much more fluid and you can see those 3 kind of sticking together and swirling around.
:!: If you meddle with the code on button 1 (cube creation) and cube/wall code itself you will discover some pretty nice gravity effects (GIF). I have disabled them for now, as there are issues to fix.
- if you (default setup, no speed, just Y force = 1) stack them one on top of each other they will eventually fall trough the top one (cube count - 21 - on the image is higher than the amount of visible cubes)
- cube hi detection works VERY wierdly, they might pass trough each other when force is applied, same works with cube-wall hit detection
[read post below]
You do not have the required permissions to view the files attached to this post.
Last edited by Obiekt on Wed Jan 02, 2013 2:44 pm, edited 1 time in total.
Come to think of it, none of you should care for the inner workings of my sloppy code, nor did my request comply with the fact that this is my self-educational project.
So, to simplify, the main problem i currently have is how to design an efficient hit detection system for objects in real time.
Example: Object X travels from point A to point B. There is a rectangle R somewhere in it's path. Since there I have no quantum computers at hand I can't constantly keep checking for collisions while moving X pixel by pixel at set speed.
Instead I use speed as an amount of pixels X will cross in a tick (Refresh function). Currently i am using a system that only checks collision at the point when X will be next P(X.x/y += speed.x/y). This works at low speeds, but if speed is too large (or the wall is too thin the P will be behind the wall (no collision) so the X keep moving.
I could make a graph of X path for every point, always checking collisions, but if speed is 50+ and there are more objects, checking everything in between it would not at all be feasible on a normal computer.
I hope you see what my problem is, i would be happy for any advice on an efficient hit detection - don't need the code, I only lack the method! Ask away if I didn't explain it well enough. Download stays if anyone is curious enough, but there's no need to mess with the code.
So, to simplify, the main problem i currently have is how to design an efficient hit detection system for objects in real time.
Example: Object X travels from point A to point B. There is a rectangle R somewhere in it's path. Since there I have no quantum computers at hand I can't constantly keep checking for collisions while moving X pixel by pixel at set speed.
Instead I use speed as an amount of pixels X will cross in a tick (Refresh function). Currently i am using a system that only checks collision at the point when X will be next P(X.x/y += speed.x/y). This works at low speeds, but if speed is too large (or the wall is too thin the P will be behind the wall (no collision) so the X keep moving.
I could make a graph of X path for every point, always checking collisions, but if speed is 50+ and there are more objects, checking everything in between it would not at all be feasible on a normal computer.
I hope you see what my problem is, i would be happy for any advice on an efficient hit detection - don't need the code, I only lack the method! Ask away if I didn't explain it well enough. Download stays if anyone is curious enough, but there's no need to mess with the code.
Hello Obiekt,
I dont have an answer to your problem but I did come across this amazing source which demonstrates a physics engine and is written entirely in VB.Net.
http://www.planet-source-code.com/vb/sc ... &lngWId=10
It appears to handle collisions very well so maybe you can figure out how it was done by viewing the source. cooll;
I dont have an answer to your problem but I did come across this amazing source which demonstrates a physics engine and is written entirely in VB.Net.
http://www.planet-source-code.com/vb/sc ... &lngWId=10
It appears to handle collisions very well so maybe you can figure out how it was done by viewing the source. cooll;
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
Thanks, this will help me a lot in my project!
Now to try to decipher it
Now to try to decipher it

I have been banging my head with this for days and though collisions work awesomely in his example it draws objects in a very weird fashion, offsetting coordinates with a weird combination of width and x (and height and y).
I could just try using collision system, but his rotations work very well too so I just modified it a bit.
Example:
Thanks in advance
EDIT: and sorry for doubleposting
I could just try using collision system, but his rotations work very well too so I just modified it a bit.
Example:
Code: Select all
This code, used in the demo, creates the floor about 50 (visual estimate) pixels from the left and about 300 pixels from the top (which makes no sense). I am 95% that this could be fixed somewhere in RectangleParticle.vb (perhaps in subs paint or getcornerpositions). I may be asking a lot but if someone were to look at this and find a fix, I could advance with ease from here.Dim floor As RectangleParticle = New RectangleParticle(325, 324, 649, 50, 0, True, 1, 0.3, 0)
APEngine.addParticle(floor)
'(x, y, width, height, rotation, fixed, mass, elasticity, friction)
Thanks in advance
EDIT: and sorry for doubleposting
5 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023