About Store Forum Documentation Contact



Post Reply 
Cuts(Shape, Shape) problem
Author Message
Myx Offline
Member

Post: #1
Cuts(Shape, Shape) problem
Hello there!

I recently decided to start up a new project, so far everything is running along excellently... or atleast it was until I ran into my Cuts-problem.

It was while working on my NPCs detection function that problems appeared.
The function basically creates a cone extenting from right in front of the NPCs head to a certain distance based on a variable.

Code:
Character* Character::scanView()
{
    Cone theView;
    theView.set(0, getSightRange()/3, getSightRange(),
        cskel.getPoint("Head").pos+cskel.getPoint("Head").dir,
        cskel.getPoint("Head").dir);

    Box theBox(getSightRange()+getSightRange()/10, pos());
    Memb<Obj*> theObjects;
    Game::World.objQuery(theObjects, theBox);

    REPA(theObjects)
    {
        if(Character* theCharacter = CAST(Character, theObjects[i]))
        {
            if(theCharacter != this)
            {
                                // Check if the character is a friend or not
                if(theCharacter->getFaction() != getFaction())
                {
                    Box charBox = theCharacter->mesh->box;
                    charBox += theCharacter->pos();
                    
                                        // I never pass this if-statement
                    if(Cuts((Shape)theView, (Shape)(charBox)))
                    {
                        return theCharacter;
                    }
                }
            }
        }
    }

    return NULL;
}

I've drawn all shapes to the screen and they all look like they're supposed to. But for some reason I never get past the "if(Cuts((Shape)theView, (Shape)(charBox)))" line.

The reason for the (Shape) type-cast is that the engine wouldn't recognize theView and charBox as Shapes. I converted theView and charBox to Shapes and then drew them to make sure they were still correct, and they appeared to be.

So anyone, please tell me, what am I overlooking?


Grateful for any and all answers
// Myx
12-28-2009 02:18 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: Cuts(Shape, Shape) problem
Hi, your codes appear to be correct, but the problem is that Cuts(Shape,Shape) doesn't support all possible combinations of the shape types
please in the meantime use this function Cuts(Vec point,Cone cone):

if(Cuts(theCharacter->pos(), theView))
12-28-2009 03:42 PM
Find all posts by this user Quote this message in a reply
Myx Offline
Member

Post: #3
RE: Cuts(Shape, Shape) problem
(12-28-2009 03:42 PM)Esenthel Wrote:  the problem is that Cuts(Shape,Shape) doesn't support all possible combinations of the shape types
Ahhhh...

(12-28-2009 03:42 PM)Esenthel Wrote:  please in the meantime use this function Cuts(Vec point,Cone cone):

if(Cuts(theCharacter->pos(), theView))
That did the trick! Thanks alot!
12-28-2009 03:54 PM
Find all posts by this user Quote this message in a reply
Post Reply