•      Sign In
• Create Account

# JD_Rushing

Member Since 28 Sep 2013
Offline Last Active Aug 01 2016 12:15 PM

### In Topic: Odd issue with Separating Axis Theorem

02 September 2015 - 10:44 AM

Without edge testing i was getting false positives.  And the last loop is testing the mix/max for the smallest overlap.  X,Y is min0 and max0.  Z,W is min1, max1.  I don't plan on keeping it like that, as storing the values is definitely not optimized.  It was just for debugging.

Walking passed the "cracks" between 2 oob is apparently a common problem.  I am trying to research and see what I can find.  Although any suggestions on that would be great.

EDIT:

I am averaging all the collisions together and then applying the average to the object to move it.  It appears to be working right now with low gravity.  Higher gravity, back to same problem.

### In Topic: Odd issue with Separating Axis Theorem

02 September 2015 - 09:13 AM

Well the code is mostly fixed.

```	bool Collide(RigidBody* other, Vector4f& collision)
{
std::vector<Vector3f> axies;
std::vector<Vector4f> minmax;
int count = 0;
float min0, max0;
float min1, max1;
Vector3f dir;
float dist = 10000.f;
Vector3f axis;
int wAxis = -1;
int which = -1;
axies.resize(0);
minmax.resize(0);
Vector3f offset = pos - other->pos;
for (count = 0; count < GetFaceSize(); count++)
{
dir = GetNormal(count);
Project(dir, min0, max0);
other->Project(dir, min1, max1);
if (max0 < min1 || max1 < min0)
return false;
axies.push_back(dir);
minmax.push_back(Vector4f(min0, max0, min1, max1));
}
for (count = 0; count < other->GetFaceSize(); count++)
{
dir = other->GetNormal(count);
Project(dir, min0, max0);
other->Project(dir, min1, max1);
if (max0 < min1 || max1 < min0)
return false;
axies.push_back(dir);
minmax.push_back(Vector4f(min0, max0, min1, max1));
}

int counts;
for (count = 0; count < GetFaceSize(); count++)
{
for (counts = 0; counts < other->GetFaceSize(); counts++)
{
dir = GetNormal(count).CrossProduct(other->GetNormal(counts));
dir.Normalize();
Project(dir, min0, max0);
other->Project(dir, min1, max1);
if (max0 < min1 || max1 < min0)
return false;

axies.push_back(dir);
minmax.push_back(Vector4f(min0, max0, min1, max1));
}
}
int aCount = 0;
float temp;
for (count = 0; count < axies.size(); count++)
{
if (!axies[count].isEqual(Vector3f(0, 0, 0)))
{
if ((minmax[count].y - minmax[count].z < minmax[count].w - minmax[count].x) && minmax[count].y > minmax[count].z)
{
if (dist > minmax[count].y - minmax[count].z)
{
wAxis = count;
axis = axies[count];
dist = minmax[count].y - minmax[count].z;
}
}
else if (minmax[count].w > minmax[count].x)
{
if (dist > minmax[count].w - minmax[count].x)
{
wAxis = count;
axis = axies[count];
dist = minmax[count].w - minmax[count].x;
}
}
}
}
if ((pos - other->pos).Dot(axis) < 0)
{
axis = axis * -1.0f;
}
collision = Vector4f(axis, dist);
return true;
}
```

The cross product of the 2 box faces is for edge testing.  And the check for a 0 direction is because cross product of same directions give you a 0.

Ty snake5 on the min/max, that was a problem, and the "touching == true" was unneccessary.

It works mostly.  When two oobs meet, I seem to get caught or pushed out of the hallway.

### In Topic: Odd issue with Separating Axis Theorem

31 August 2015 - 10:56 PM

```	bool Collide(RigidBody* other, Vector4f& collision)
{
std::vector<Vector3f> axies;
std::vector<Vector4f> minmax;
int count = 0;
float min0, max0;
float min1, max1;
Vector3f dir;
float dist = 10000.f;
Vector3f axis;
bool moving = false;
bool touching = false;
int wAxis = -1;
int which = -1;
axies.resize(0);
minmax.resize(0);
for (count = 0; count < GetFaceSize(); count++)
{
dir = GetNormal(count);
Project(dir, min0, max0);
other->Project(dir, min1, max1);
if (max0 < min1 || max1 < min0)
return false;
axies.push_back(dir);
minmax.push_back(Vector4f(min0, max0, min1, max1));
if (max1 == min0 || max0 == min1)
{
touching = true;
}
else
{
if (max0 > min1 && dir != Vector3f(0, 0, 0))
{
if (dist > max0 - min1 && max0 - min1 > 0.0f)
{
dist = max0 - min1;
axis = dir;
wAxis = axies.size() - 1;
}
}
else if (dir != Vector3f(0, 0, 0))
{
if (dist > max1 - min0 && max1 - min0 > 0.0f)
{
dist = max1 - min0;
axis = dir;
wAxis = axies.size() - 1;
}
}
}
}
for (count = 0; count < other->GetFaceSize(); count++)
{
dir = other->GetNormal(count);
Project(dir, min0, max0);
other->Project(dir, min1, max1);
if (max0 < min1 || max1 < min0)
return false;
axies.push_back(dir);
minmax.push_back(Vector4f(min0, max0, min1, max1));

if (max1 == min0 || max0 == min1)
{
touching = true;
}
else if (max0 > min1 && dir != Vector3f(0, 0, 0))
{
if (dist > max0 - min1 && max0 - min1 > 0.0f)
{
dist = max0 - min1;
axis = dir;
wAxis = axies.size() - 1;
}
}
else if (dir != Vector3f(0, 0, 0))
{
if (dist > max1 - min0 && max1 - min0 > 0.0f)
{
dist = max1 - min0;
axis =  dir;
wAxis = axies.size() - 1;
}
}
}

int counts;
for (count = 0; count < GetFaceSize(); count++)
{
for (counts = 0; counts < other->GetFaceSize(); counts++)
{
dir = GetNormal(count).CrossProduct(other->GetNormal(counts));
dir.Normalize();
Project(dir, min0, max0);
other->Project(dir, min1, max1);
if (max0 < min1 || max1 < min0)
return false;

axies.push_back(dir);
minmax.push_back(Vector4f(min0, max0, min1, max1));

if (max1 == min0 || max0 == min1)
{
touching = true;
}
else if (max0 > min1 && dir != Vector3f(0, 0, 0))
{
if (dist > max0 - min1 && max0 - min1 > 0.0f)
{
dist = max0 - min1;
axis = dir;
wAxis = axies.size() - 1;
}
}
else if (dir != Vector3f(0, 0, 0))
{
if (dist > max1 - min0 && max1 - min0 > 0.0f)
{
dist = max1 - min0;
axis = dir;
wAxis = axies.size() - 1;
}
}
}
}
if (touching == true && dist > 1000.0f)
{
dist = 0;
}
collision = Vector4f(axis * -1.0f, dist);
return true;
}
```

### In Topic: Where do I begin WITHOUT an engine?

07 December 2013 - 02:43 AM

There is a lot of good advice here but...what are you trying to make?

This may help your route.  If your plans are small simple games, an easy to use engine is probably for you.  The more complex and intense a game is, the more effort you will have to use in learning HOW stuff works so you can manipulate it.  In that aspect, you may find that some of these engines just wouldn't work for you.

I started learning opengl using nehe.gamedev.net

It was a great learning experience.  But, as someone pointed out, be careful about outdated material.  I realized a lot of the code I learned would have to be migrated to VBO's and shaders.

I would recommend you learning a language (c++, java, c#) on the side even if you use an engine.  It could definitely come in handy later on.

### In Topic: I want to make a Sonic the Hedgehog-esc game, I have no idea where to start

19 October 2013 - 06:22 PM

I definitely recommend the bouncing ball off walls as a first.  Start with a ball on the screen.  Then make 4 walls.  Then make the ball start moving, bouncing off the walls when it collides.  Then add user input, the direction buttons.  The user can help maneuver the ball.  Now to add challenge, start keeping score.  The longer the user keeps the ball from hitting the wall, the more score they get.  At this point you have to display text to show them a score.  Then you have to decide if they should have multiple wall hits before the game ends, or just one hit and its done.  Then you can start a save file to keep track of high scores.

This is the first game I learned to make.....on QBasic

PARTNERS