i am a part of a big project
and the GUI part will be sent to me as a library
my task is to write the physics engine of the system
but i haven't any idea about how to start
you'd start with the GUI, you're gonna have to wait for that to be done before you can actually start the physics engine, unless im missing something...
You don't need to see stuff to crate simple physics.
Make a class for the ball with the velocity, position, direction as members. Make the ball updating velocity and direction according to physics and change the position accordingly.
You may need a class to calculate vector stuff to evaluate the force.
A collision with just a floor is easy to make.
Why are you writing a physics engine? There are plenty of free ones out there and the fact that you're asking how to write one tells me its not something you're going to be able to accomplish. Physics engines are complicated as hell. If this is a 2d project, then it gets a little easier to accomplish. Before you can create any sort of physics engine you need to define/understand the rules of the game/simulation world and identify the requirements. Also, physics has nothing to do with a GUI. It's hardcore calculations based on object states, locations, etc... hope this helps.
This is purely a speculation question, I have no experience with GUI's, games programming and porgramming with physics. But if you created a box and put a put a small ball in the middle, and gravity acted on it so it fell, do you have to program where the bottom of this box is so it doesn't fall forever, or does the ball already know where the bottom is? I'm thinking its the first but it got me thinking!!
Technically the ball wouldn't know the x/y coords ( or z ) of a collision layer for the box edges. The ball will not know it's hit a collision layer until ball.y equals the coordinates of a box edge. Let's put it this way. If we hung you inside of a massive box, would you know the x/y coordinates of the box floor prior to slamming into it?... maybe that was a bad example. Then again, if AI is introduced, yes it is possible to know the floor exists. You'll see that kind of logic in a lot of FPS games out there where the enemy AI uses terrain and objects to its advantage. It knows the location of objects currently in memory, exact distances, heights, etc...
This post brings back memories of some of the old Nintendo/Sega games where the NPCs were to stupid to go around objects and barely recognized a collision... they just keep walking in place stuck in the corner of some item shop lol. That was because they did not know that objects existed until they hit them and had no intelligence to bypass or all together avoid objects.
I have written a program like this in my old TI-82 calculator.. I know the basics of how it would work.. I was just talking to my teacher and he told me the latest release of C++ you can control an out put on the screen with an X and a Y axis.. if this is true.. what you need to do is map out your window and know all the x and y cords on the screen. once you know what you minimums and maximums are, you can write the code.. I know i could write you this program if I knew the language better.. but I am still learning myself about it..
say if the screen was 100 characters wide by 80 tall.. you could write a loop that randomizes a number between -1 and 1. there by either staying the same, taking or giving one space on the screen to the moving object.
if I was writing it in ti-82 it would go something like this:
(int rand*1)+1>A
Label X
A+1=A
if A > 2
c=c+1
goto Z
if A<1
c= c-1
goto Z
if A=0
c=c+0
goto Z
label Z
If A=>2 and A =<99
then
goto K
If A =1
(int rand*1)+1>b
goto H
If A = 100
(int rand*1)+1>b
if b > 2
goto H
b=b+1
goto q
if b<1
b= b-1
goto q
if b=0
b=b+0
goto q
label q
If b=80
b=b-1
goto K
If b=1
b=b+1
goto K
Label K
output(A,b, "O"
goto X
I haven't written in years.. But it would go something like this to make the ball bounce around on the screen using an X and Y axis. I remember there being a Racecar game that was written similar to this. I was trying to learn how to write my own code from this car game and it is very similar to basic.. it was written so that the car was in the shape of a "V" and on either side of the screen it looked like "| |" and the "V" was in the middle.. You could control it going side to side.. if you hit the walls. the game was over and your car would explode.. the game ran from the top of the screen down like it does in C++.. If you can control the X and Y axis.. along with cout command. you can do a lot more than people realize.
use cout to control the box of the screen and use the X,Y axis command to control your object.. you might even be able to program a space invaders type of game..
I don't know if I explained myself well enough.. It is hard to type on here when you can't write as it is written in the calculator using the equations function under the math area of the calculator.
it's also late and I am very tired..
if your ball either reaches 100Y or 20X, then you need to randomize a number. When it hits the top or bottom of your screen you need to randomize a number so the ball either goes straight and bounces back or bounces back up or down away from the wall.. and continues in that direction until acted upon by another wall.. I know I left out bits of the code and this is not all of it.. but it's been 15 years since I wrote this code and I forgot a lot of it.. it is possible.. never let anyone tell you it isn't. because it is... I remember writing a game for my calculator that was GTA style back in '96, it used almost all my K.. it was written with a combination of this style and a bit of hand drawn pictures on my graphing calculator with sex scenes built into the game along with fighting and driving you could control on the screen..
here's a good physics engine(with a new scripting language you haven't ever heard of!):
www.phunland.com
the commercial(yes, pay for it) version is here:
www.algodoo.com
And yes, it's VERY complicated to make a physics engine.