Title: Simple and Efficient LineofSight for 3D Landscapes
1Simple and Efficient Line-of-Sight for 3D
Landscapes
- AI Game Programming Wisdom
2Ideal Sector Transform Matrix
- The transformation is essentially a rotation of a
point around the origin such that it ends in the
ideal sector(0-45 degree range). - The traits are described by following
conditionals. - dx gt 0, dy gt 0, dx gt dy
- Matrix Initialization
- dxlt0dylt0ABS(dx)ltABS(dy)
3Ideal Sector Transform Matrix
- Initialization of the matrix requires a relative
vector. - Ex) a ray from (-1,-1) to (-2,2) gt (-1,3)
- Transformation function
Void TransformToVirtualGridSpace(x, y) if
(matrix2) // dx lt dy swap(x, y) if
(matrix0) // dx lt 0 x -x if
(matrix1) // dy lt 0 y -y
4Offset Transformation
- Assumption
- Landscape stores data such as visibility and
friction for each element, or set of two polygon
triangles, surrounded by four adjacent vertices. - To access this data structure, we must index into
an array using the coordinates of the bottom-left
corner of the element. - However, bottom left in virtual space is not
equivalent to bottom left in real space.
5Offset Transformation
- The new transform function
Void TransformOffsetToRealSpace(x, y) x
matrix0 y matrix1 if (matrix2
TRUE) swap(x, y)
6Ray-Landscape Collision
- Collision check
- The first step in performing this collision check
is transforming the ray into virtual grid space. - Next, if the ray doesnt already lie on a
division line, it must be extended backward to
the nearest division line(connection between two
adjacent vertices).
7Optimizations
- The landscape could be broken up into several
chunks, each with its own precomputed
world-aligned bounding box (ABB). - The algorithm will collide with these ABBs,
reject the nonintersecting with ABB chunk, and
sort the intersecting ones by distance along ray
to intersection point with ABB, front to back. - In flight games, the chunk rejection yields a
tremendous increase in speed.
8Conclusion
- Algorithms dealing with the landscape grid
geometry will benefit tremendously from the
virtual grid transform.
9An Open-Source Fuzzy Logic Library
- AI Game Programming Wisdom
10Terminology
- A list of terms used in this article
- Variable
- Set
- Rules
- Min
- Max
- PROD
- Degree of Membership (DOM)
- Inference
- Composition
- Crisp Value
- Membership Function
- Fuzzification
- defuzzification
11FFLL Features
- Membership Functions
- Define the sets shape and is used to fuzzify
the x values of the variable by associating a DOM
with an x value. - FFLL provides support for Triangles, Trapezoids,
S-Curves, and Singletons. - In Search of Speed
- Lookup tables are used wherever possible,
sacrificing some memory for the sake of speed. - Each sets membership function contains a lookup
table used to speed the fuzzification process.
12FFLL Features
- One-Dimensional Rules Array
- FFLL stores rules a one-dimensional array.
- Defuzzification
- To eliminate extra calculations, FFLL does not
calculate the output value until it is requested. - Model/Child Relationship
- One or more objects can use a FFLL model at
same time. - These objects are referred to as children of
the FFLL model.
13FFLL Features
- Multithread Support
- Unicode Support
- All strings in the FFLL library use the wide
character data type wchar_t. - Loading a Model
- FFLL can load files in the Fuzzy Control
Language(FCL) as defined in the IEC 61131-7
International Standard Control Programming.
14FFLL Features
- Viewing a Model
- While FFLL does not provide any built-in viewing
capabilities, the FCL format is supported by
Louder Than A Bomb!s Spark! fuzzy logic editor. - Exported Symbols
- FFLL can be used as a class library and/or
through an API.
15FFLL API
- Why an API?
- The API is for developers who want to use the
precompiled DLL and/or do not want to import the
classes into their application. - API Functions
- ffll_new_model
- ffll_load_fcl_file
- ffll_new_child
- ffll_set_value
- ffll_get_output_value
16A FFLL Example
- While it is possible to build an entire fuzzy
logic model using FFLLs exported classes, in
practice it is best to create fuzzy logic models
using the FCL language.
17A FFLL Example
- Fuzzy Control Language (FCL) example file 1/2
FUNCTION_BLOCK VAR_INPUT Our_Health REAL (
RANGE(0 .. 100) ) Enemy_Health REAL (
RANGE(0 .. 100) ) END_VAR VAR_OUTPUT Aggressive
ness REAL ( RANGE(0 .. 4) ) END_VAR FUZZIFI
Our_Health TERM Near_Death (0,0) (0,1)
(50,0) TERM Good (14,0) (50,1) (83,0) TERM
Excellent (50,0) (100,1) (100,0) END_FUZZIFY
FUZZIFI Our_Health TERM Near_Death (0,0)
(0,1) (50,0) TERM Good (14,0) (50,1)
(83,0) TERM Excellent (50,0) (100,1)
(100,0) END_FUZZIFY
18A FFLL Example
- Fuzzy Control Language (FCL) example file 2/2
DEFUZZIFY valve METHOD MoM END_DEFUZZIFY RULEB
LOCK first ANDMIN ACCUMMAX RULE 0 IF Good
AND Good THEN Fight_Defensively RULE 1 IF Good
AND Excellent THEN Fight_Defensively RULE 2 IF
Good AND Near_Death THEN All_Out_Attack RULE 3
IF Excellent AND Good THEN All_Out_Attack RULE
4 IF Excellent AND Excellent THEN
Fight_Defensively RULE 5 IF Excellent AND
Near_Death THEN All_Out_Attack RULE 6 IF
Near_Death AND Good THEN Run_Away RULE 7 IF
Near_Death AND Excellent THEN Run_Away RULE 7
IF Near_Death AND Near_Death THEN
Fight_Defensively END_RULEBLOCK END_FUNCTION
19A FFLL Example
include FFLLAPI.h // FFLL API include
ltiostream.hgt // for i/o functions define
OUR_HEALTH 0 // our health is 1st
variable define ENEMY_HEALTH 1 // enemy health
is 2nd variable int main( int argc, char
argbv ) float our_health, enemy_health //
values for input variables char option // var
for selection of what user wants to
do cout.setf(iosfixed) cout.precision(2) //
only display 2 decimal places // create and
load the model int model ffll_new_model() in
t ret_val ffll_load_fcl_file(model,
..\\aiwisdom.fcl)
20A FFLL Example
if(ret_val lt 0) cout ltlt Error Opening
aiwisdom.fcl return 0 // create a child for
the model int child ffll_new_child(model) whi
le(1) cout ltlt SELECT AN OPTION \n\tS - set
values\n\tQ quit cout ltlt endl cin gtgt
option if(option Q option
q) break if(option S option
s) cout ltlt Our Health cin gtgt
our_health
21A FFLL Example
switch(output) case (1) cout ltlt Run
Away! break case (1) cout ltlt Fight
Defensively break case (1) cout ltlt Run
Away! break // end switch cout ltlt
endl // end if option s // end
while(1) return 0 // end main()
cout ltlt Enemys Health cin gtgt
enemy_health cout ltlt Aggressiveness // set
input variables ffll_set_value(model, child,
OUR_HEALTH, our_health) ffll_set_value(model,
child, ENEMY_HEALTH, enemy_health) // get and
display the output value int output
ffll_get_output_value(model1, child)
22Conclusion
- Fuzzy logic can be a powerful tool in an AI
Programmers arsenal.