Jump to content
• Advertisement

# Separating axis Theorem rotation issue

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

If you intended to correct an error in the post then please contact us.

## Recommended Posts

Hello there,

I am trying to get SAT working within my 2d game using Windows 8 and DirectX (DirectXTK).

However i have run into an issue which I cannot figure out.

(I have uploaded a video to youtube that demonstrates the issue)

When the boxes are AABB the collision works great, when i rotate the boxes the axis "flys" off and the boxes dont collide properly because of this.

YOUTUBE LINK :

(IGNORE THE WHITE BOXES TO THE LEFT OF THE SCREEN)

If anyone has any ideas about what could be causing this please let me know. Also if you would like to see the code, please post and tell me.

Thanks!

Edited by nickyc95

#### Share this post

##### Share on other sites
Advertisement

Can you post your code.  Looks like the way you are calculating the axis is wrong.

If you look at the top it looks like the Axis is being projected on the the X plane.

This is how I calculate the Axis.

[source lang="csharp"]

for (int x = 0; x < Points.Count; x++)
{
Vector3 p1 = Points[x];
Vector3 p2 = Points[x + 1 == Points.Count ? 0 : x + 1];
Vector3 edge = p1 - p2;
var A = new Vector2(-edge.X, edge.Y);
A.Normalize();
Axis.Add(A);
}

[/source]

#### Share this post

##### Share on other sites

@nicky95

It's hard to tell exactly what goes wrong without seeing any code.

@CJThomas

It seems like you are doing vector normalization in your code. This isn't necessary and requires a lot of cpu time. Your code should work just fine even if you remove "A.Normalize();"

Cheers,

Mike

#### Share this post

##### Share on other sites

It seems like you are doing vector normalization in your code. This isn't necessary and requires a lot of cpu time

Just curious as I don't know and would like to - when I use dot product to project a vertex onto an axis in SAT, I use the fact that the axis vector is normalized to give me the distance along the axis as the simple result of the dot product. How do you retrieve this if the axis vector isn't normalized?

Is it just a case of dividing the result by the length of the axis vector? If so, you still need the length of the axis vector, which is the slow bit of normalization.

#### Share this post

##### Share on other sites

Hi Aardvajk. I don't actually calculate the distance, since it is not needed. If you want the distance, you need to solve the Pythagorean theorem, which means calling square root. It's getting late here in Europe so I won't go into a lengthy explanation on SAT, but here are some links you might find useful:

http://www.geometrictools.com/Documentation/MethodOfSeparatingAxes.pdf

Cheers,
Mike

#### Share this post

##### Share on other sites

@CJThomas

It seems like you are doing vector normalization in your code. This isn't necessary and requires a lot of cpu time. Your code should work just fine even if you remove "A.Normalize();"

Thanks for the Tip.  I have removed that line and it works fine

#### Share this post

##### Share on other sites

Hi Aardvajk. I don't actually calculate the distance, since it is not needed.

Oh of course, you can compare the squared distances to check for overlaps. Doh! :)

Thanks for the links.

#### Share this post

##### Share on other sites

It seems like you are doing vector normalization in your code. This isn't necessary and requires a lot of cpu time

Just curious as I don't know and would like to - when I use dot product to project a vertex onto an axis in SAT, I use the fact that the axis vector is normalized to give me the distance along the axis as the simple result of the dot product. How do you retrieve this if the axis vector isn't normalized?

Is it just a case of dividing the result by the length of the axis vector? If so, you still need the length of the axis vector, which is the slow bit of normalization.

Aardvark, your instincts are correct. The dot product gives: Dot(A,B) = |A||B|Cos(Theta), so ( Dot(A,B) ) / |B| gives the distance of A projected onto B, which simplifies to dot(a,b) when b is a unit length vector.

#### Share this post

##### Share on other sites

• Advertisement
• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• Advertisement

• ### Popular Now

• 16
• 9
• 15
• 9
• 11
• Advertisement
×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!