Chunky by FelipeFS
Chunky by FelipeFS
GPWiki.org
It is currently Wed Jul 30, 2014 11:06 am

All times are UTC




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: coding physics.
PostPosted: Fri Jan 11, 2013 6:16 pm 
Bit Baby

Joined: Fri Jan 11, 2013 6:08 pm
Posts: 8
Hy,
I'm developing a FPS game. So far I only implemented a framework to display the level with opengl.
I'm about to start on physics. Now I'm wondering if it's a good idea to code the physics myself?

Pro:
It will be a great experience
It will be optimized for my game

Con:
It will take a lot of time
there allready exist a lot of good library's.

What do you think? What would you recommend? Building it myself or using a library?
And if so, which library would you recommend for physics?

Greatings
Genzm


Top
 Profile  
 
 Post subject: Re: coding physics.
PostPosted: Fri Jan 11, 2013 8:20 pm 
Grand Optimizer

Joined: Sun Oct 16, 2011 3:09 pm
Posts: 362
Location: Here (where else?)
Depends on your goal, I think.
From a "I wanna get the game running now" point of view, use a library any day.
From a "I wanna learn how to code physics" point of view, I'd say code the physics :)

_________________
My project: Messing about in FreeRCT, dev blog, and IRC #freerct at oftc.net


Top
 Profile  
 
 Post subject: Re: coding physics.
PostPosted: Fri Jan 11, 2013 11:21 pm 
Bit Baby

Joined: Fri Jan 11, 2013 6:08 pm
Posts: 8
But do you think it's possible? I kind of have an idea what it is to code physics.
In what time do you think it's possible to get some decent working physics?


Top
 Profile  
 
 Post subject: Re: coding physics.
PostPosted: Sat Jan 12, 2013 9:25 am 
Grand Optimizer

Joined: Sun Oct 16, 2011 3:09 pm
Posts: 362
Location: Here (where else?)
Technically it's possible, otherwise there would not be any library that handles physics.

The biggest problem is perhaps the question how precise do you want it. Another question is whether it should be "realistic" (whatever that means). If you do a sort-of physics simulation, you should be able to get it pretty much correct w.r.t. real-life.

However, aside from CPU limitations, real-life correct does not mean it works in a game. For example a bullet flies 900m/s and is not visible to the naked eye.From a game perspective however, it is probably much more fun to see bullets across the screen.

The other direction for physics is to think from the game. What effect do you want in the game? Code that, such that it looks and works right. The latter gives you much more freedom.

As for the time-frame, it depends a lot on what you want to have, and how much experience you have in math and programming. Linear motion is the simplest, you may want to start there. I found http://gafferongames.com/game-physics/f ... -timestep/ a very interesting read.

As I said before however, when you are worried about time that it takes, use a library. Using a library is always faster than writing one, even if it is a dedicated solution.

_________________
My project: Messing about in FreeRCT, dev blog, and IRC #freerct at oftc.net


Top
 Profile  
 
 Post subject: Re: coding physics.
PostPosted: Sat Jan 12, 2013 9:56 am 
Bit Baby

Joined: Fri Jan 11, 2013 6:08 pm
Posts: 8
I found the article that you posted interessting (didn't read it fully, but certainly will).
I know my math and I do have some expirience in programming, so I think I will try to code the physics myself. It seems quite a learning experience :P
Besides, I only need some bullets flying and some gravity in my game. Using an entire physics library would probably have a lot of overload.

If you might have some more interessting links about programming physics: please post them.
Thanks for the advice.


Top
 Profile  
 
 Post subject: Re: coding physics.
PostPosted: Sun Jan 27, 2013 2:16 pm 
Bit Baby

Joined: Fri Jan 11, 2013 6:08 pm
Posts: 8
I've started the programming of my physics. Everything is starting to work now.
I have falling objects, and I use a self implemented ray cast to detect collision. It works, but it is quite slow. I'm running a very basic level on only 20 fps. Of course this was expected, because the raycasting has a very basic (brute force) way of working.
A little bit of pseudocode:
Code:
for every object that moves:
    for every other object in the level:
        for every triangle the object consist of:
            check if the moving object collides with this triangle


This is obviously not very efficient which causes my lag. The thing is I can't really find any optimizations just of the top of my head.
So if anyone has some suggestions on how to improve the performance of this, or links to interesting articles, I would be very interested to hear about them.

Greatings genzm


Top
 Profile  
 
 Post subject: Re: coding physics.
PostPosted: Sun Jan 27, 2013 3:38 pm 
Grand Optimizer

Joined: Sun Oct 16, 2011 3:09 pm
Posts: 362
Location: Here (where else?)
Don't check collision of A -> B as well as B -> A
Have some surrounding rectangle or such around an object so you can decide quickly whether testing is at all useful (if the surrounding rectangles between two objects don't overlap, the triangles inside certainly won't).

Edit: Anyone wants to buy a golden keyboard? It says at the left I carry it, and it's kind of heavy :p

_________________
My project: Messing about in FreeRCT, dev blog, and IRC #freerct at oftc.net


Top
 Profile  
 
 Post subject: Re: coding physics.
PostPosted: Sun Jan 27, 2013 5:03 pm 
Bit Baby

Joined: Fri Jan 11, 2013 6:08 pm
Posts: 8
Ok, that's a nice tip :P
Any idea how I can limit the amount of vertices that I need to check?
There are objects (like terrain or environment objects) which have a lot of vertices in one object.
If I could somehow filter only vertices which are near, that would help a lot.
I was thinking of saving vertex data in a hash set or something, if I would find the right hash function (which would use x,y,z) I could select only those vertices that are near the object...

I'm not really sure yet, but let me know what you think.


Top
 Profile  
 
 Post subject: Re: coding physics.
PostPosted: Wed Jan 30, 2013 2:15 am 
BANNED

Joined: Sun Jun 24, 2012 12:49 am
Posts: 504
Quote:
Edit: Anyone wants to buy a golden keyboard? It says at the left I carry it, and it's kind of heavy :p


Hah. That was out of the #0000FF. You shall remain the bearer of the golden keyboard. No, but really? You're selling a golden-wired-thingy keyboard? Kewl


Top
 Profile  
 
 Post subject: Re: coding physics.
PostPosted: Wed Jan 30, 2013 9:18 pm 
Dexterous Droid
User avatar

Joined: Wed Aug 18, 2004 7:40 pm
Posts: 3795
Location: South Africa
genzm wrote:
If I could somehow filter only vertices which are near, that would help a lot.

Use a kd-tree or some other space partitioning strategy. You want to do collision detection in a hierarchy: cheap operations that eliminate the majority of possibly colliding entities --> expensive operations that check the remaining entities for actual collisions.

I gotta go to sleep so bad man, but ask questions if you have. |I

_________________
Whatever the mind can conceive and believe, it can achieve


Top
 Profile  
 
 Post subject: Re: coding physics.
PostPosted: Fri Feb 01, 2013 12:02 pm 
Bit Baby

Joined: Fri Jan 11, 2013 6:08 pm
Posts: 8
Reading the description of the k-d tree it mostly does resemble the idea I had. I did all ready implement this. It is still full of bugs, but I will get it working. I still will take some inspiration of this kd-tree. It's funny that I just followed an entire course about trees and heaps, but we never saw this one :P (unfortunatly).
Anyway, for now I don't really have any questions. If any come up I will certainly ask them.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC


Who is online

Users browsing this forum: Yandex [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

Powered by phpBB® Forum Software © phpBB Group