Field of vision

Started by
3 comments, last by cruiz 22 years, 3 months ago
Hi! (I try(...) to explain my problem in english...) ) I try to program a Field of vision. How for example in Commandos. The enemy has a field where they see you. A triangular form with a circle end. (circlesector?? ) ) Hope you understand... ) Yeah... Now to the maths: How can I calculate if a Point(X/Y) is in this circle with angle and distance? Thanks... C.Ruiz (How exactly can I show pictures on this forum? If you show me I could send a picture...) Edited by - cruiz on January 2, 2002 1:26:11 PM
Advertisement
The shape you''re referring to is a cone!

Anyway, here''s the simplest way: Keep track of a vector representing the direction the ai player is facing. Then, take the dot-product of that and the vector pointing towards the human player. If the angle is less than half of the field-of-view angle, then the player is in the field of view; otherwise he is not.

The dot product of two vectors, A and B, is expressed as follows:
A * B = cos(angle_between_vectors)*(|A||B|)

To find the angle between them, then you need to do this:
angle_between_vectors = acos((A*B)/(|A||B|))

The symbol |A| means the absolute value of A. This can be calculated as follows:
|A| = sqrt(a.x2+a.y2+a.z2).

This does not handle occlusion detection. What that means is that, if you are behind a wall that the ai player is looking directly at, then he can still "see" you even though he shouldn''t be able to. From the sounds of things, you should be able to ignore this limitation.

Good luck.
Thanks!
Ok i''ve tried and it don''t works.
But I don''t understand the theory either!
What is if one or both vectors are zero??
A "man" don''t must walk not? It can stand around for example.
Ok explication to my game:
You are a ship and you see the field of vision.
If a opponent is in this field it should be visible.
Here my source:
  	double V1,W1, V2,W2;		V1=myship.VelX;		V2=myshipVelY;		W1=enemyshipVelX;		W2=enemyship.VelY;		double angle_between_vectors = acos((V1*W1+V2*W2)/((sqrt(V1*V1)+(V2*V2))*(sqrt(W1*W1)+(W2*W2))));				double currentangle=90;//for example		double bogennn=3.141* ((currentangle)/(180));              //Calculation in Radian		if((angle_between_vectors)<(bogennn/2))			AngleBool=true;		else			AngleBool=false;  


I hadn''t Vectors in shool yet.
I''ve read already an articel in the internet about them.
Really complicated!
Thanks for your posting.
Greets: C.Ruiz
(P.S.: A "cone"! Ok thanks! )
Ohhhh!
Yesterday did school begann.
A math-teacher explained me a part of my problem.
This formula is wronger than wrong!!!!!!!!!!
I'm on it. I have changed the formul but
I'm still working.
But now I understand the theory!!
(ok a part of it)
I mean i had Vector-maths never in school.
I will have in next semester i heard.
Greets from here: C.Ruiz

Edited by - cruiz on January 8, 2002 3:35:51 AM
do be, everyone from switzerland, yoda?

This topic is closed to new replies.

Advertisement