Sign in to follow this  
BlackDuck

Bounding Box and Gravity

Recommended Posts

BlackDuck    151
Hi, I am a beginner to OpenGL and I have an project where I wish to just control a bi plane and with the basic physics involved. In my first phase I created a large green flat polygon to represent the ground, a pyramid to represent my bi-plane and a large blue skybox. Phase 2: I would like to achieve basic gravity force acting on the bi-plane So lets say the bi-plane starting position is y = 100 units. I wish for it to free fall. I was having problems getting my head around how to use velocity, f = mass * acceleration formulas but didn't know where or what I just needed. Next I am told it is best to work with a bounding box that encapsulates my bi-plane and work with this but I need help with both the concept and code. I am told this will later help with my collision detection and moving the model using a centre point (local coordinates, but I just don't understand this quite as yet) Can anyone point me to a good source to answer these two questions. Cheers, BlackDuck

Share this post


Link to post
Share on other sites
Dekasa    127
You're going about gravity a little off. Gravity = acceleration. Don't worry about the Force part, that doesn't affect your velocity. Think of it like this:

Plane position = acceleration + velocity + original position.
So every time you update your plane's position (dealing only with the Y axis, here), you take how much thrust or lift your plane has (player is pressing the Up or Down keys), and then take into account gravity.

So, more than not, find a nice, lowish number to represent gravity, and subtract that from your plane's Y position every frame. I'd go into more detail, but I'm not sure where your math is, nor do I know how accurate physically you want this to actually be.

For the bounding box question, it's pretty simple. You just make a rectangle, or circle, something that could hold your model inside of it, and have its centerpoint be the same center as the plane. That way, the box/circle/sphere moves with the plane, and for collisions, you just check to see if something hits that box, and if it does, then it hits the plane. Local coordinates are just coordinates with respect to the plane. If the box is in front of the plane, it might have the coordinates (plane.X + 10, plane.Y). This way, the box doesn't need to know its absolute position, it just takes its position in reference to the plane, itself. This way it'll automatically stay with the plane.

Share this post


Link to post
Share on other sites
BlackDuck    151
Awesome! I love this site. Should have come here straight away instead of wasting my night away ;)

I'll put those tips into action and see how it goes.

One more question. Bounding box, how is that implemented. I have an array containing the vertices. What do I create to have the bounding box dimensions. Do I also create a array of some sort to house all my bounding boxes for every object in my world?

JN

Share this post


Link to post
Share on other sites
OldProgie2    158
Quote:
Original post by Dekasa
Plane position = acceleration + velocity + original position.

That is not correct. The correct formula expressed in those terms would be x = x1 + ut + 1/2at^2, where u is initial velocity and a is acceleration.
Quote:
Original post by Dekasa
So, more than not, find a nice, lowish number to represent gravity, and subtract that from your plane's Y position every frame. I'd go into more detail, but I'm not sure where your math is, nor do I know how accurate physically you want this to actually be.

For a more correct use, on each (game time) frame use
velocity = velocity + acceleration (in this case -g)
position = position + velocity

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this