PDA

View Full Version : Moving game agents around the map



howie
05-05-2006, 11:37 AM
I'm working on a FPS where the game agents will move around an office environment map (hallways, rooms, stairs). This is my first effort in moving game agents so I want to make sure I'm thinking about this correctly.

1) For each agent, I need a center point so that I can tell where the agent is in world space. Mainly used to get the distance between the player and the agent.

2) Another point that extends from the agent so that I can tell the direction it is facing in world space.

3) Moving the agent around the map...

This is the part I'm having trouble wrapping my head around. If the map is untransformed, then moving the agent is easy because x and z can be use to navigate the map (like walking on a grid). After the transformation, depending on where the view is looking, x and z no longer have that grid ability.

So the question is, when moving agents around the map, do you move the agent as though it's in local view? Or is there a magic way to move them in world view.

jide
05-05-2006, 12:05 PM
Well, huh, glMoveAgentsAroundTheMap (agents, my_map, players) ?

I guess world coordinates system could be the best thing for you. But I must admit I did not understood everything from what you wrote. So if you can clear things a bit, or best tell what's about GL in your request, it might help.

k_szczech
05-05-2006, 01:04 PM
Is this what you are looking for?

renderMap();
for (i = 0; i < numberOfAgents; i++)
{
glPushMatrix();
glTranslatef(agent[i].x, agent[i].y, agent[i].z;
glRotatef(agent[i].direction, 0, 1, 0);
drawAgent();
glPopMatrix();
}Some notes:
map should never be transformed by your application. From your application's point of view map is static and uses always the same coordinate system.

howie
05-05-2006, 03:55 PM
What I'm looking for is a bird's eye view of the concepts to make sure I'm doing it in a way that most programers do.

<< From your application's point of view map is static and uses always the same coordinate system. >>

If I understand you correctly, use the coordinate system of the map in it's untrasformed state. That way the coordinate system in relation to moving the agent around never changes.

That's what I was thinking but just wanted conformation.

k_szczech
05-05-2006, 04:25 PM
Here's a simple example:

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(....);
glRotatef(cameraAndleX, 1, 0, 0);
glRotatef(cameraAngleY, 0, 1, 0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(-cameraPosition.x, -cameraPosition.y, -cameraPosition.z);

renderMap(); //do not transform anything here

glPushMatrix();
glTranslatef(agent.x, agent.y, agent.z);
glRotatef(agent.direction, 0, 1, 0);
drawAgent();
glPopMateix();Applying camera rotations to projection matrix and camera position to modelview matrix can be usefull for environment mapping, this is why I separated these transformations this way.
By the way - if you put topic like this in advanced forum you make people confused - a reader is most likely to think that problem is complex.

jide
05-05-2006, 05:14 PM
For bird views, try to use quaternions, it might be more easy.

knackered
05-05-2006, 06:04 PM
jide, do you agree this thread belongs in the advanced forum?

jide
05-05-2006, 06:31 PM
So, is this a spark in the shadow of times ?? I really hope it is because I don't like hatred.
I can start your fire if you want and you'll see the light starting to shine inside of you. This is where I'm the best but it's only for those who deserve it ;) This is one of the reasons I'm here.

Anyone SEES things as they do (can): it's obvious knackered. And there's a good proverb for understanding this point:


"everything is hard before it becomes easy"
The goal is to make them understand they were in the wrong place, not to oblige them to give up: What if people said to Zidane he was bad and insists on that he should play Hockey instead ?? Would England won the 98 world cup ??? :p

But maybe you don't go in the beginner's forum often enough... Please don't push me anymore. I don't want to enshade this place.

Don't take it badly please.

howie
05-05-2006, 06:45 PM
Thanks for all your help. Wasn't sure if this was beginner or advanced material.

k_szczech, thanks for the code example.

jide
05-05-2006, 07:04 PM
howie, did the code helped you ? Can you explicitly tell what you really want ? Was my first post in this topic right ? Is it fully linked with GL ?

Anyway, if this does not belong to this forum, moderators will move it, but this is not an excuse to give up.

howie
05-05-2006, 07:42 PM
From the code example I can see the order in which he is doing his translations.

I guess what I'm asking is that when it comes to moving agents around the map, you transform the agents in model view as if the map was static. That way moving x 10 and z 15 has real meaning in relationship to the map. Then you apply your world transformations.

The problem I'm trying to wrap my head around is the world trasformation is the player in a FPS. I don't have a model view representation of that point or how to get it since you can hold down one key and stear with the mouse. So having the agent react to the players position when I don't have that position in model view. I don't know...

howie
05-05-2006, 08:21 PM
I think I got it. If I record the Y rotation in a seperate matrix but opposite, then merge the matrix with a copy of the world view matrix, I'll get the point the player is at as if the point was in model view. That seems to work.

knackered
05-08-2006, 05:15 AM
yes but jide, do YOU agree this thread belongs in the advanced forum?
By the way, you're no relation to Cantona are you?

jide
05-08-2006, 05:51 AM
It doesn't.

"If the seagulls follow the fish boat it is because they believe we will throw them fishes", E. Cantona :-D

knackered
05-08-2006, 06:36 AM
:) nice one