Jump to content
  • Advertisement
Sign in to follow this  
Silarr

Slight Issue

This topic is 2891 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

Hi all,I am currently working on AABB's to start myself off without trying something too heavy.

I've read around before coming here to ask, it is most likely a simple answer but struggling to figure the solution.

I've defined simple objects using V-Arrays, successfully managed to find the Min/Max values and display the AABB to make sure it's around my objects which is fine.
The trouble I'm having is the collision response section of my code;

 
bool aabbCollision()
{

if(AABB.max.x < AABB.min.x) return false;
if(AABB.max.y < AABB.min.y) return false;
if(AABB.max.z < AABB.min.z) return false;

if(AABB.min.x > AABB.max.x) return false;
if(AABB.min.y > AABB.max.y) return false;
if(AABB.min.z > AABB.max.z) return false;

return true;
}

Very trivial for you guys obviously, I'm just checking the AABB against itself since I want to just get two similar objects with collision for now.

All is fine when compiling but when I put a condition for response it doesn't function at all.
Example:

    if(GetKeyState(VK_UP))
{
if(!OnCollision)
{
Forward(1); // Move forward
}
}


if(!OnCollision) - If I insert this I can't move forwards at all, kind of frustrating. It is like the collision is consistently taking place without having a collision in the first place?.


Any assistance would be appreciated; Any other code or additional information required I am happy to supply if it helps me to resolve this.

Kind Regards.

Share this post


Link to post
Share on other sites
Advertisement
Your function aabbCollision() will always return true. You don't specify, but if OnCollision is somehow related to that function, that could cause the condition you're getting.

Share this post


Link to post
Share on other sites
Quote:
Original post by Buckeye
Your function aabbCollision() will always return true. You don't specify, but if OnCollision is somehow related to that function, that could cause the condition you're getting.


Hi, thankyou for the reply, sorry for the delay in responding!

I've been trying to figure out why the function for collision is always returning true? I know this is probably dumb to ask but I have fiddled around with my code for a while and haven't had the slightest progress in figuring the solution.

I've made a function to draw the BoundingBoxes, but they obviously appear correctly when translated with the object itself + its the correct fit/shape.

I have come to a dead end with this, searching on webpages etc but not really getting any results, it tells me how to check for the collision, but whether I'm doing it correct myself is another story. I'll supply code so you maybe could best advise me where I'm going wrong or what I need to modify etc...




Object of same type: Drawn Using V-array, my aabb is calculated by looping through the vertice array to find min/max values.
I then tried creating two similar objects, having seperate AABB calculations which were Box & Box1, tried to compare the two but havent had any success with this either. I would prefer to keep to one AABB for the same objects.

AABBCollision - I have included several attempts, even though the same, but different variations trying to correct my issue I described in the first post.

I havent' given up on trying to work this out, but I really can't see where I'm going wrong.

[Edited by - Silarr on October 23, 2010 2:40:22 PM]

Share this post


Link to post
Share on other sites
What are the min and max values? What are they assigned and what do they represent?

by definition, max is always greater than the minimum, unless they are both equal, therefore the if statements which keep asking if max is less than min, will always return false, therefore skip all of the return false; statements. In this event, there will be only one statement left, return true;, and therefore your function will always return true.

Share this post


Link to post
Share on other sites
Quote:
Original post by boogyman19946
What are the min and max values? What are they assigned and what do they represent?



I will supply what I use to construct object/aabb. Representation on draw is a simple cuboid, simple enough for testing purposes, obviously I will try more complex shapes but right now I'm struggling with the most simple...


[Edited by - Silarr on October 23, 2010 2:32:50 PM]

Share this post


Link to post
Share on other sites
You want to be testing collision between two AABB's, but your code is obviously only testing one with itself!
It will always return true because a proper AABB will always have positive volume, so a collision test against itself will always be true.

Edit: You might have wanted to do something like this. Note that I did not check to see if your code was correct, but merely changed the overall design:


bool aabbCollision(Box AABB2)
{

if(AABB.max.x < AABB2.min.x) return false;
if(AABB.max.y < AABB2.min.y) return false;
if(AABB.max.z < AABB2.min.z) return false;

if(AABB.min.x > AABB2.max.x) return false;
if(AABB.min.y > AABB2.max.y) return false;
if(AABB.min.z > AABB2.max.z) return false;

return true;
}


Share this post


Link to post
Share on other sites
Quote:
Original post by xytor
You want to be testing collision between two AABB's, but your code is obviously only testing one with itself!

Edit: You might have wanted to do something like this. Note that I did not check to see if your code was correct, but merely changed the overall design:

*** Source Snippet Removed ***


Yeh When I realised this, I changed the collision accordingly, but apparently it's still turning true. I'm trying to work it out logically where the problem is;

1: Define V-Array for Object1
2: Define V-Array for Object 2
3: AABB Struct
4. Box,Box1 --> AABB Struct
5. Pointer to V-Arrays
6. Calculate first AABB for Object 1 looping V.Array
7. Same as 6 but for Object 2 Array

8. void Object 1 { Enable Arrays, PushMatrix-->Random location<--- Draw Object, Disable Arrays}

9. Same as 8.
10. Collision Detection - Box vs Box1 Min/Max.

11. Assign key to move forward only if Collision is false. [Obviously wont work because collision is still turning true.]


I'm trying to solve the "why" but can't figure out logically where I've gone wrong :/. [I posted code in previous posts if a reference is needed].

If I have two seperate Arrays, so two similar objects but different values, then calculate a AABB for each object, then compare the two... surely it should work, but for some reason it isn't, and that's what I can't seem figure out.


Solution is probably staring me in the face :d








Share this post


Link to post
Share on other sites
Quote:
Original post by Silarr
Quote:
Original post by xytor
You want to be testing collision between two AABB's, but your code is obviously only testing one with itself!

Edit: You might have wanted to do something like this. Note that I did not check to see if your code was correct, but merely changed the overall design:

*** Source Snippet Removed ***


Yeh When I realised this, I changed the collision accordingly, but apparently it's still turning true. I'm trying to work it out logically where the problem is;

1: Define V-Array for Object1
2: Define V-Array for Object 2
3: AABB Struct
4. Box,Box1 --> AABB Struct
5. Pointer to V-Arrays
6. Calculate first AABB for Object 1 looping V.Array
7. Same as 6 but for Object 2 Array

8. void Object 1 { Enable Arrays, PushMatrix-->Random location<--- Draw Object, Disable Arrays}

9. Same as 8.
10. Collision Detection - Box vs Box1 Min/Max.

11. Assign key to move forward only if Collision is false. [Obviously wont work because collision is still turning true.]


I'm trying to solve the "why" but can't figure out logically where I've gone wrong :/. [I posted code in previous posts if a reference is needed].

If I have two seperate Arrays, so two similar objects but different values, then calculate a AABB for each object, then compare the two... surely it should work, but for some reason it isn't, and that's what I can't seem figure out.


Solution is probably staring me in the face :d


It's better to post code rather than your own logic because C/C++ is standardized, while your own logic syntax is not; it's less readable to me.

Anyway, you should do some live debugger sanity checks. For example, put a breakpoint inside the collision function and make sure that the two AABBs are different.

Share this post


Link to post
Share on other sites
Quote:
if (key == 'a'){if (aabbCollision==false)Forward(5);}

The line aabbCollision==false appears to be comparing the address of the function to the value for false. Since the address of the function is greater than 0 and false is probably defined as 0, "aabbCollision==false" is always false and Forward never gets called.

Try calling the function:

if( !aabbCollision( Box, Box1 ) ) Forward(5);

I don't know what IDE you're using, but you need to learn how to debug by setting breakpoints in your code (as suggested), outputting messages to a debug window, etc.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!