C++: An issue with storing lists of data, in a sense.

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

User avatar
Indubitable.
Posts: 13
Joined: Mon May 24, 2010 4:56 pm UTC
Location: Scotland

C++: An issue with storing lists of data, in a sense.

Postby Indubitable. » Sat Feb 19, 2011 12:03 am UTC

Hello there,

I was wondering if anyone would be willing to help me with an issue I'm having with a project I'm writing for school? I think it ought to require no knowledge of physics engines (which is what my project is), just programming constructs, but I may be wrong.

The specification for the project is rather vague and I'm somewhat competitive so I am trying to outdo a project which someone created a few years ago, in a sense, which is my I'm doing something so needlessly complex for a high school project.

I'm writing a 3D physics engine, which operates solely with oriented bounding boxes each defined as a part of an array of objects of my RigidBody class. So far, I've implemented all major features aside from the remainder of collision detection (which is why I am here) and collision response. For collision response, I must have a list for each object of points of collision, collision normals and the object with which each point is colliding.
I can see no issue in finding each of these pieces of data, just how to store them. I have classes for vectors (which I'm using to store the position vectors of each vertex, as well as vectors themselves), vectors comprised of functions, planes with rectangular constraints (for the faces of the boxes), lines with constraints (for edges), matrices and the boxes themselves.

What I'm baffled by is how to store the information in order to be able to use it in collision response, given that I do not know how many collisions there will be. I was thinking that I could create two 2-D arrays for collision normals and vertices where the first dimension corresponds to the number of boxes (so each part of that dimension corresponds directly to the same-numbered box) and the second has eight entries (I think this is the maximum possible number of colliding points at once). However, I fear that this could be horribly inefficient.

My other thought was that I could create a collision class but this would require me to check for the number of vertices first (which would mean effectively finding each one and then tallying them) and then create an array of collisions of the required size, but this would then mean that I would need to find collision points again, thus ruining efficiency.

Which of these ought I to use, do you think/do you have any other suggestions?

If anyone wants to see the code, I can post a zip file but right now it's 1300 lines and counting and it's rather poorly commented because I've been focusing on getting the thing finished, so it could be horrible to read. Also, right now it only compiles on Linux (as far as I know; it could compile on Windows, and that's the goal but I'd rather get the rest of it done first). It requires SDL and OpenGL.

Thanks.
My bass is called Rosa and I love her lots. <3

8-Bit Theater wrote:WM: Ok, an orphanage is on fire, what do you--
BM: Use FIRE-3 to torch the building and then pick off any survivors with BOLT-2 set to a wide dispersal.

_Axle_
Posts: 253
Joined: Fri Sep 24, 2010 7:33 pm UTC

Re: C++: An issue with storing lists of data, in a sense.

Postby _Axle_ » Sat Feb 19, 2011 1:12 am UTC

Each Collision can only be 2 objects.

Make a Collision structure, which has each object in the collision, contact normal, contact points, penetration depth, etc. For each pair that collides, fill out the structure and save it until the resolution phase of physics. Just push it back on a std::vector.
Yakk wrote:Computer Science is to Programming as Materials Physics is to Structural Engineering.


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 8 guests