About Store Forum Documentation Contact



Post Reply 
Frustum Check
Author Message
Kevin Offline
Member

Post: #1
Frustum Check
Hi,
I have a problem with implementing my Game AI in Esenthel.
I have created a FSM and a Creature Class, I also have some State classes, for instance PatrolState.
In the update method I want the creature to change to PursueState if it sees the player.
Well, now I've no clue how to do some kind of Frustum test in Esenthel...
The method looks like so:

Code:
void PatrolState::Execute(Creature *pCreature) {
    
    if(!pCreature->action) {
        if(m_pWaypoint && m_pWaypoint->points()) {
            m_MoveTo=(m_MoveTo+1)%m_pWaypoint->points();     // set variable to next point index
            pCreature->actionMoveTo(m_pWaypoint->point(m_MoveTo).pos);
        }
    }
    
    //ToDo: replace "distance check" with frustum check
    if(player && Dist(pCreature->pos(), player->pos()) <= 5){
        //Pursue Player
        pCreature->FSM->ChangeState(new PursueState());
    }
    
}

Any Idea?
I thought about creating a physX actor to test it, but its a bit
complicated to do it like this, isn't it?
Thanks in advance!

regards,
Kevin
11-25-2009 10:37 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: Frustum Check
Hi,

You don't need frustum check (I mean Frustum class),

you can just calculate the angle between look direction and player position

something like this:
Code:
Vec delta_to_test=test.pos()-this.pos();
Vec look_dir=this.look_dir();
Bool sees=(AngleBetween(look_dir,delta_to_test)<=DegToRad(60));
11-25-2009 10:55 PM
Find all posts by this user Quote this message in a reply
Kevin Offline
Member

Post: #3
RE: Frustum Check
(11-25-2009 10:55 PM)Esenthel Wrote:  Hi,

You don't need frustum check (I mean Frustum class),

you can just calculate the angle between look direction and player position

something like this:
Code:
Vec delta_to_test=test.pos()-this.pos();
Vec look_dir=this.look_dir();
Bool sees=(AngleBetween(look_dir,delta_to_test)<=DegToRad(60));

Ok, thank you.
I've tried it, but I failed...
The code:

Code:
Vec toPlayer = player->pos() - pCreature->pos();

//Transform forward vector with Creatures rotation matrix, to
//get the direction it is facing:
Vec look_dir=Vec(0, 0, -1);
look_dir.mul(pCreature->matrix());

float angle = AbsAngleBetween(toPlayer, look_dir);

//If player is at distance of 3 to creature and the player is inside the FOV
//of the creature, change to Pursuit state
if(Dist(pCreature->pos(), player->pos()) <= 3 && angle <= DegToRad(45)){
    pCreature->FSM->ChangeState(new PursueState());
}

pCreature is a Creature (which is a "child" of Game::Obj), and player a Game::Chr.


//Edit:
I think I got it wink

Code:
Vec toPlayer = player->pos() - pCreature->pos();

//Transform forward vector with Creatures rotation matrix, to
//get the direction it is facing:
Vec look_dir=VecDir[DIRE_FORWARD];
look_dir.mul(pCreature->matrix());
look_dir -= pCreature->pos();

float angle = AbsAngleBetween(!toPlayer, !look_dir);

//If player is at distance of 3 to creature and the player is inside the FOV
//of the creature, change to Pursuit state
if(Dist(pCreature->pos(), player->pos()) <= 10 && angle <= DegToRad(30)){
    pCreature->FSM->ChangeState(new PursueState());
}
(This post was last modified: 11-26-2009 07:23 PM by Kevin.)
11-26-2009 06:30 PM
Find all posts by this user Quote this message in a reply
Post Reply