dandymcgee wrote:N64vSNES wrote:
I have no idea how I should calculate that axis (blue line) and when projecting the polygons I'm confused to why that line makes a difference?
The blue line is correct, but the green ones are not. You're not projecting along the y-axis, you're projecting onto the blue line.
obb.png
This would be the projection on one of the axes. There are four axis total you need to project them onto. As Falco already pointed out, you don't understand what a projection onto an axis is. Go check out the resources he gave you.
THANK YOU.
I told you, dude. You don't just take one component of a vector and call that shit a projection. Imagine that the lines forming the edges of your polygon continue or "project" (loll0rskates!) onto the axis. That's what a projection is.
What's that, you say? The projection isn't aligned with the X or Y axis, so you don't know the value of the projection? No shit! The polygon isn't axis-aligned! As I said before, you are trying to approach this without linear algebra. Shit isn't going to work. Welcome to the wonderful world of vectors and matrices, young'n.
N64vSNES wrote:When you say the blue line is incorrect, is it because I drew another blue line to the polygons face? Because I just did that so you knew which face I was thinking was perpendicular
He said your blue one WAS correct. You found an axis properly (on paper). I doubt you did it correctly on code, since your projections are still incorrect (and that would require you to have utilized that linear algebra knowledge).
Your green lines are wrong as fuck, because as we said, those are PROJECTIONS, not just you dropping the y component of your vectors.
Think about it. Look back at your picture. The blue face of the polygon that you used to create that axis is parallel to the axis, correct? Now a "separating axis" is PERPENDICULAR to that axis. Find me a perpendicular line to that axis in your picture that does not intersect your green projections. You can't, because your projections are incorrect. That would be a false collision.
Here's what you do:
1) Find two axes for each polygon by subtracting the two vertices (in WORLD COORDINATES) that create each edge to create the vector between them. The algorithm (and projections) require each axis to be NORMALIZED, so find the magnitude of the axes (distance formula, pythagorean theorem, whatever you want to call it), and divide each of their components by this magnitude. Bam! You have normalized vectors. Winning!
2) Now the easy part. The "vector projections" of your vertices onto these axes are simple dot products between each vertex and your axis (this is because your axes are already normalized). NOW KEEP IN MIND: You need to project a total of 6 vertices onto each axis for two oriented bounding boxes. Since one of your OBBs was used to create an axis in the first place, it has two edges that are perpendicular to its own axes. The vector projections of the vertices forming the edge perpendicular to your axis of projection are going to be equal, so you only need to project two vertices (like the box on the right of dandymcgee's drawing).
The box on the left actually needs to have FOUR projections (not the two in the drawing), because none of its edges are aligned with the axis you're projecting onto (meaning each vertex will have a unique projection value).
SO BIG PICTURE:
PROJECT 6 WORLD-SPACE VERTICES ONTO 4 NORMALIZED AXES.
Now, the next step: For each axis, you will be given 6 "one-dimensional scalars" by performing these projections. If there is any overlap between polygon A's scalars and polygon B's scalars, there cannot possibly be an axis perpendicular to the axis of projection that separates the two. You have a collision whose depth is the difference between the two minimally overlapping scalars and whose direction is in the direction of the axis. Don't bother testing on any other axes!
So multiply that scalar overlap by your normalized axis, and tada! You now have a vector that will separate the two polygons: the collision normal. Use this collision normal to bang 7g rocks like a super fricken rockstar from Mars!
BACK TO WORK.