Physics Project

Anything related in any way to game development as a whole is welcome here. Tell us about your game, grace us with your project, show us your new YouTube video, etc.

Moderator: PC Supremacists

Post Reply
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Physics Project

Post by dandymcgee »

This is my first OpenGL application, and was created as my Final Exam project for my high school Physics I class. It consists of two distinct parts: A small game, and a sort of sandbox simulation. Although it's not terribly complicated I put a good deal of effort into make the code as neat as possible and it earned me an A+ for my final. ;) As far as efficiency.. well you can determine that for yourselves. It does crash periodically for unknown reasons, but I don't plan to update it any further.

This archive contains the PowerPoint I presented for the class, both executables, & full source ( including the Code::Blocks project files ).
DOWNLOAD

Controls:
Game - Q, W, E for NW, N, and NE respectively. (Must re-open application to start again)
Simulation - Keys surrounding "S" non-inclusive (Q, W, E, A, D, Z, X, C). I'm sure you can figure out what directions they correspond to.
You can also click with the left mouse button in the simulation to set the object's position.

All source code is freely available for whatever use you see fit, but you are not authorized to claim any significantly sized unaltered portion as your own.

Feedback is welcome. :)
Last edited by dandymcgee on Fri Jul 31, 2009 10:38 pm, edited 1 time in total.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
gordon
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 60
Joined: Mon May 04, 2009 2:38 pm

Re: Physics Project

Post by gordon »

Impressive work. I had a quick glimpse at the source and it has some useful stuff in it. Thanks, will help me with my learning.
User avatar
RyanPridgeon
Chaos Rift Maniac
Chaos Rift Maniac
Posts: 447
Joined: Sun Sep 21, 2008 1:34 pm
Current Project: "Triangle"
Favorite Gaming Platforms: PC
Programming Language of Choice: C/C++
Location: UK
Contact:

Re: Physics Project

Post by RyanPridgeon »

Nice one! I'm working on something similar for my Computing coursework
Ryan Pridgeon
C, C++, C#, Java, ActionScript 3, HaXe, PHP, VB.Net, Pascal
Music | Blog
User avatar
Bludklok
Chaos Rift Junior
Chaos Rift Junior
Posts: 241
Joined: Tue Apr 14, 2009 1:31 am
Current Project: EnigmaCore
Favorite Gaming Platforms: PC, N64, Playstation1, Playstation2
Programming Language of Choice: C++
Location: New Jersey
Contact:

Re: Physics Project

Post by Bludklok »

This is outstanding work. I did a C++ program for science final in freshman year of high school but no where near as complex as this.
Youtube
Website
Current project: Enigma Core
User avatar
RyanPridgeon
Chaos Rift Maniac
Chaos Rift Maniac
Posts: 447
Joined: Sun Sep 21, 2008 1:34 pm
Current Project: "Triangle"
Favorite Gaming Platforms: PC
Programming Language of Choice: C/C++
Location: UK
Contact:

Re: Physics Project

Post by RyanPridgeon »

How come the x force reads 0 when you are decelerating horizontally?
Ryan Pridgeon
C, C++, C#, Java, ActionScript 3, HaXe, PHP, VB.Net, Pascal
Music | Blog
User avatar
Netwatcher
Chaos Rift Junior
Chaos Rift Junior
Posts: 378
Joined: Sun Jun 07, 2009 2:49 am
Current Project: The Awesome Game (Actual title)
Favorite Gaming Platforms: Cabbage, Ground beef
Programming Language of Choice: C++
Location: Rehovot, Israel

Re: Physics Project

Post by Netwatcher »

Liked the fact that the gravity isn't 10 or 9.8... it's exactly 9.81 :D ( I hate approximations)


you made the points in the helicopter game to be added every few milliseconds, when I hit a button the program is "delayed" and I get the point only after a while... you should put it on a different thread or average the FPS (ofc you're not gonna do it NOW, I'm just saying...).

And the keystroke checking; you did a switch statement or else if... so I can't press up & left, and if I do I will just fall down because the up key isn't checked.(the NE, SE, SW and NW keys doesn't work right for some reason)
and it also finds out when I press irrelevant keys (such as the "k" key or the "o" key )
Other then that >Great work :D
"Programmers are the Gods of their tiny worlds. They create something out of nothing. In their command-line universe, they say when it’s sunny and when it rains. And the tiny universe complies."
-Derek Powazek, http://powazek.com/posts/1655

blip.fm DJ profile - http://blip.fm/Noobay
current code project http://sourceforge.net/projects/vulcanengine/
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Physics Project

Post by dandymcgee »

@RyanPridgeon:
RyanPridgeon wrote:How come the x force reads 0 when you are decelerating horizontally?
I know technically friction is a force and should probably be considered when calculating "force", but the "force" you see being displayed in my properties list is technically only the net applied force (ie. when you press a key you apply a force as well as gravity which is constantly applying force).

@NetWatcher:
Netwatcher wrote:Liked the fact that the gravity isn't 10 or 9.8... it's exactly 9.81 :D ( I hate approximations)
I tried to make it as accurate as possible.
Netwatcher wrote:you made the points in the helicopter game to be added every few milliseconds, when I hit a button the program is "delayed" and I get the point only after a while... you should put it on a different thread or average the FPS (ofc you're not gonna do it NOW, I'm just saying...).
If you only move along one axis (ie. bouncing vertically) your points go up VERY slow on purpose. Otherwise it's based on velocity (more velocity = more points). Also take note that the score variable is a float being cast to an int before being displayed, so if it's going up slowly enough the number you see won't change until it gets far enough to be rounded up instead of down.
Netwatcher wrote:And the keystroke checking; you did a switch statement or else if... so I can't press up & left, and if I do I will just fall down because the up key isn't checked.(the NE, SE, SW and NW keys doesn't work right for some reason)
Again, in the game this was completely on purpose to add to the difficulty level. You can only apply force NW, N, or NE in the game and I'm not sure what you mean about keys not working?
Netwatcher wrote:and it also finds out when I press irrelevant keys (such as the "k" key or the "o" key )
What do you mean by "It finds out"?

@Everyone else:
Thank you guys for your compliments, they're much appreciated. Feel free to hack at the source, it's far from professional but I believe it's neat enough and commented well enough for you to get the basic gist of what's going on. :)
(Note: You may want to avoid trying to understand the block comments of debug code, most of it is irrelevant and I just never happened to delete it.)
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
Netwatcher
Chaos Rift Junior
Chaos Rift Junior
Posts: 378
Joined: Sun Jun 07, 2009 2:49 am
Current Project: The Awesome Game (Actual title)
Favorite Gaming Platforms: Cabbage, Ground beef
Programming Language of Choice: C++
Location: Rehovot, Israel

Re: Physics Project

Post by Netwatcher »

dandymcgee wrote:@RyanPridgeon:
RyanPridgeon wrote:How come the x force reads 0 when you are decelerating horizontally?
I know technically friction is a force and should probably be considered when calculating "force", but the "force" you see being displayed in my properties list is technically only the net applied force (ie. when you press a key you apply a force as well as gravity which is constantly applying force).

@NetWatcher:
Netwatcher wrote:Liked the fact that the gravity isn't 10 or 9.8... it's exactly 9.81 :D ( I hate approximations)
I tried to make it as accurate as possible.
Netwatcher wrote:you made the points in the helicopter game to be added every few milliseconds, when I hit a button the program is "delayed" and I get the point only after a while... you should put it on a different thread or average the FPS (ofc you're not gonna do it NOW, I'm just saying...).
If you only move along one axis (ie. bouncing vertically) your points go up VERY slow on purpose. Otherwise it's based on velocity (more velocity = more points). Also take note that the score variable is a float being cast to an int before being displayed, so if it's going up slowly enough the number you see won't change until it gets far enough to be rounded up instead of down.
Netwatcher wrote:And the keystroke checking; you did a switch statement or else if... so I can't press up & left, and if I do I will just fall down because the up key isn't checked.(the NE, SE, SW and NW keys doesn't work right for some reason)
Again, in the game this was completely on purpose to add to the difficulty level. You can only apply force NW, N, or NE in the game and I'm not sure what you mean about keys not working?
Netwatcher wrote:and it also finds out when I press irrelevant keys (such as the "k" key or the "o" key )
What do you mean by "It finds out"?

@Everyone else:
Thank you guys for your compliments, they're much appreciated. Feel free to hack at the source, it's far from professional but I believe it's neat enough and commented well enough for you to get the basic gist of what's going on. :)
(Note: You may want to avoid trying to understand the block comments of debug code, most of it is irrelevant and I just never happened to delete it.)
I mean, if I press "up" and "k" nothing will happen because I pressed "K"

about the other E,Q,C and Z keys... they are alright It's just that It's not as big of a movement as the other directions.

I just comment what I think... didn't realize some of these were actually part of the game.
I feel stupid :roll:
"Programmers are the Gods of their tiny worlds. They create something out of nothing. In their command-line universe, they say when it’s sunny and when it rains. And the tiny universe complies."
-Derek Powazek, http://powazek.com/posts/1655

blip.fm DJ profile - http://blip.fm/Noobay
current code project http://sourceforge.net/projects/vulcanengine/
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Physics Project

Post by dandymcgee »

Netwatcher wrote: I mean, if I press "up" and "k" nothing will happen because I pressed "K"

about the other E,Q,C and Z keys... they are alright It's just that It's not as big of a movement as the other directions.

I just comment what I think... didn't realize some of these were actually part of the game.
I feel stupid :roll:
Well I'm not sure how much you know about vectors, but that is exactly what the forces in this application are. When you apply a force of 120N NW you're actually dividing it among the X and Y axis, AND going against gravity. This might be what's causing you to see it as a lesser effect.

As far as input, this project was the very first programming project I've done with an actual deadline (and therefore probably the first project I've actually completed). I didn't have time to make it idiot-proof, so pressing the wrong keys will in fact result in a performance penalty. ;)

Don't feel stupid, I appreciate the feedback! :mrgreen:
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
Netwatcher
Chaos Rift Junior
Chaos Rift Junior
Posts: 378
Joined: Sun Jun 07, 2009 2:49 am
Current Project: The Awesome Game (Actual title)
Favorite Gaming Platforms: Cabbage, Ground beef
Programming Language of Choice: C++
Location: Rehovot, Israel

Re: Physics Project

Post by Netwatcher »

dandymcgee wrote:
Netwatcher wrote: I mean, if I press "up" and "k" nothing will happen because I pressed "K"

about the other E,Q,C and Z keys... they are alright It's just that It's not as big of a movement as the other directions.

I just comment what I think... didn't realize some of these were actually part of the game.
I feel stupid :roll:
Well I'm not sure how much you know about vectors, but that is exactly what the forces in this application are. When you apply a force of 120N NW you're actually dividing it among the X and Y axis, AND going against gravity. This might be what's causing you to see it as a lesser effect.
That's exactly what I meant.


And god am so glad I'm done with my High-school & College physics
"Programmers are the Gods of their tiny worlds. They create something out of nothing. In their command-line universe, they say when it’s sunny and when it rains. And the tiny universe complies."
-Derek Powazek, http://powazek.com/posts/1655

blip.fm DJ profile - http://blip.fm/Noobay
current code project http://sourceforge.net/projects/vulcanengine/
Post Reply