Public Group

# Bounding Box and Gravity

This topic is 3035 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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 on other sites
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 on other sites
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 on other sites
Quote:
 Original post by DekasaPlane 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 DekasaSo, 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

1. 1
2. 2
Rutin
25
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 22
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631764
• Total Posts
3002210
×