Amulets & Armor
v1.02
Open Source Game
|
3D Collision Routines More...
Macros | |
#define | COLLIDE_3D_MAX_LINES_FOR_SECTORS 100 |
#define | easyabs(x) (((x)>=0)?(x):-(x)) |
#define | HIT_TYPE_LINE 0 |
#define | HIT_TYPE_OBJECT 1 |
#define | MAX_LINE_HITS 20 |
Variables | |
T_word16 | G_numHits = 0 |
3D Collision Routines
#define COLLIDE_3D_MAX_LINES_FOR_SECTORS 100 |
Collide3dGetSectorsInBox determines all the sectors that are in a square radius box. In addition, it returns a boolean telling if it found the box touching a void area.
y | – Center of box |
radius | – Radius of box |
maxSectors | – Max sectors allowed to be found |
p_sectors | – Where to put the sectors |
p_numSectors | – Pointer to store num sectors found |
#define easyabs | ( | x) | (((x)>=0)?(x):-(x)) |
#define HIT_TYPE_LINE 0 |
#define HIT_TYPE_OBJECT 1 |
#define MAX_LINE_HITS 20 |
E_Boolean CheckLineCanStepThrough | ( | T_word16 | i, |
T_3dObject * | p_obj | ||
) |
E_Boolean Collide3dCheckLineOfSight | ( | T_sword16 | sightStartX, |
T_sword16 | sightStartY, | ||
T_sword16 | sightEndX, | ||
T_sword16 | sightEndY | ||
) |
E_Boolean Collide3dCheckLineOfSightWithZ | ( | T_sword16 | sightStartX, |
T_sword16 | sightStartY, | ||
T_sword16 | sightEndX, | ||
T_sword16 | sightEndY, | ||
T_sword16 | sightZ | ||
) |
T_sword16 Collide3dCheckSegmentHitBox | ( | T_word16 | lineNum, |
T_sword16 | x1, | ||
T_sword16 | y1, | ||
T_sword16 | x2, | ||
T_sword16 | y2 | ||
) |
Collide3dCheckSegmentHitBox determines quickly if a line hits a box.
lineNum | – Wall to check floors and ceilings. |
x1 | – Left point of box |
y1 | – Upper point of box |
x2 | – Right of box |
y2 | – Lower of box |
T_sword16 Collide3dCheckSegmentHitsSegment | ( | T_sword16 | x1, |
T_sword16 | y1, | ||
T_sword16 | x2, | ||
T_sword16 | y2, | ||
T_word16 | lineNum | ||
) |
T_word16 Collide3dFindWallList | ( | T_sword16 | x1, |
T_sword16 | y1, | ||
T_sword16 | x2, | ||
T_sword16 | y2, | ||
T_sword16 | z, | ||
T_word16 | maxWalls, | ||
T_wallListItem * | p_list, | ||
T_byte8 | wallTypes | ||
) |
E_Boolean Collide3dGetSectorsInBox | ( | T_sword32 | x, |
T_sword32 | y, | ||
T_word16 | radius, | ||
T_word16 | maxSectors, | ||
T_word16 * | p_sectors, | ||
T_word16 * | p_numSectors | ||
) |
T_word16 Collide3dGetWallsInBox | ( | T_sword32 | x, |
T_sword32 | y, | ||
T_word16 | radius, | ||
T_word16 | maxWalls, | ||
T_word16 * | p_walls | ||
) |
Collide3dGetLinesInBox takes the given square (coordinate and square radius) and determines all walls that collide with this box.
x | – X Center of box |
y | – Y Center of box |
radius | – Radius of box |
maxWalls | – Max walls allowed to find |
p_walls | – Where to put the walls |
E_Boolean Collide3dMoveToXYZ | ( | T_3dObject * | p_obj, |
T_sword32 | newX, | ||
T_sword32 | newY, | ||
T_sword32 | newZ | ||
) |
Collide3dMoveToXYZ takes an object and moves to the given XYZ.
p_obj | – Object to move |
newX | – X Target end-point |
newY | – Y Target end-point |
newZ | – Z Target end-point |
E_Boolean Collide3dObjectToObjectCheckLineOfSight | ( | T_3dObject * | p_from, |
T_3dObject * | p_to | ||
) |
E_Boolean Collide3dObjectToXYCheckLineOfSight | ( | T_3dObject * | p_from, |
T_lineOfSightLast * | p_lastSight, | ||
T_sword16 | x, | ||
T_sword16 | y | ||
) |
E_Boolean Collide3dObjectToXYCheckLineOfSightWithZ | ( | T_3dObject * | p_from, |
T_sword16 | x, | ||
T_sword16 | y, | ||
T_sword16 | z | ||
) |
T_byte8 Collide3dPointOnRight | ( | T_sword32 | lineX1, |
T_sword32 | lineY1, | ||
T_sword32 | lineX2, | ||
T_sword32 | lineY2, | ||
T_sword32 | pointX, | ||
T_sword32 | pointY | ||
) |
in a line are actually used for determine a collision. Currently, only 2 types of definitions are used. A) LINE_IS_IMPASSIBLE <== used for the player and normal objects (including missiles) B) LINE_IS_IMPASSIBLE | LINE_IS_CREATURE_IMPASSIBLE <== used for normal creatures
T_void Collide3dUpdateLineOfSightLast | ( | T_lineOfSightLast * | p_lastSight, |
T_3dObject * | p_target | ||
) |
TARGET_UNIX This routine adds a sector to the surrounding sector list if it is not already in the sector list.
sector | – Sector to add |
T_sword16 ICheckLineHitsLine | ( | T_sword16 | x1, |
T_sword16 | y1, | ||
T_sword16 | x2, | ||
T_sword16 | y2, | ||
T_word16 | lineNum | ||
) |
ICheckLineHitsLine takes in the coordinates of a line and determines if it hits the given line number on the map. If they do hit, the distance to that line is returned.
x1 | – X First point of line to check |
y1 | – X First point of line to check |
x2 | – Y Second point of line to check |
y2 | – Y Second point of line to check |
lineNum | – Line to check collision with |
!! DIVIDE ZERO ERROR HERE
E_Boolean IIsFloorAndCeilingOk | ( | T_word16 | lineNum, |
E_Boolean | f_add, | ||
T_3dObject * | p_obj | ||
) |
Given a line/wall on the map, determine if the floor and ceiling of both sides of the line are in agreement with what is allowed for going over edges. In addition, note if we wish to add the sectors to the surrounding sector list.
lineNum | – Wall to check floors and ceilings. |
f_add | – Flag where TRUE=add to sector list |
p_obj | – Source object being checked |
T_void ILineHitInBlock | ( | T_sword16 | lastX, |
T_sword16 | lastY, | ||
T_sword16 | x1, | ||
T_sword16 | y1, | ||
T_sword16 | x2, | ||
T_sword16 | y2, | ||
T_sword32 | index, | ||
T_sword16 | radius, | ||
T_3dObject * | p_obj | ||
) |
ILineHitInBlock checks all the lines/walls in a block map to determine if there is a collision. At the same time it upkeeps a list of sectors this square is over and what are the highest and lowest sector of that square.
lastX | – Old X location for angular information |
lastY | – Old Y location for angular information |
x1 | – Left corner of square |
y1 | – Upper corner of square |
x2 | – Right corner of square |
y2 | – Lower corner of square |
index | – Index to list of walls to consider |
radius | – Radius of the given box |
p_obj | – Source object being checked |
T_sword16 IMoveToXYWithStep | ( | T_sword32 * | oldX, |
T_sword32 * | oldY, | ||
T_sword32 | newX, | ||
T_sword32 | newY, | ||
T_sword32 | radius, | ||
T_sword32 | step, | ||
T_sword32 | foot, | ||
T_sword32 | head, | ||
T_sword16 | height, | ||
T_3dObject * | p_obj | ||
) |
IMoveToXYWithStep moves the player to given new location and must also be given the amount of distance is being traveled.
NOTE: G_currentHeight MUST be set in order for this routine to work correctly.
oldX | – X Start location and place to put final ending location. |
oldY | – Y Start location and place to put final ending location. |
newX | – End X location to move to |
newY | – End Y location to move to |
radius | – Radius of collision detection. |
step | – Amount to step along direction |
foot | – Foot level |
head | – Head level |
height | – Height of this object |
p_obj | – Object doing the movement |
IUpdateSectorHeights is used to update the group of variables that tell what are the heightest and lowest sectors in a square and what their values are.
sector | – sector to update |
E_Boolean LineHit | ( | T_sword16 | lastX, |
T_sword16 | lastY, | ||
T_sword16 | x1, | ||
T_sword16 | y1, | ||
T_sword16 | x2, | ||
T_sword16 | y2, | ||
T_sword16 | radius, | ||
T_3dObject * | p_obj | ||
) |
LineHit is used to determine if any line collides with the given box. It also works to determine the sectors, their heights, etc. in the area.
NOTE: Due to the way this routine works (find the four corners) and the size of the map blocks, do NOT call this routine with a box bigger than 256x256.
lastX | – Old X location for angular information |
lastY | – Old Y location for angular information |
x1 | – Left corner of square |
y1 | – Upper corner of square |
x2 | – Right corner of square |
y2 | – Lower corner of square |
radius | – Radius of the given box |
p_obj | – Source object |
E_Boolean MoveTo | ( | T_sword32 | oldX, |
T_sword32 | oldY, | ||
T_sword32 | newX, | ||
T_sword32 | newY, | ||
T_sword32 | distance, | ||
T_3dObject * | p_obj | ||
) |
MoveTo takes a given object and tries to move it to another location. If a collision is detected, a flag is returned and the global variables are filled with additional information.
oldX | – Start X point |
oldY | – Start Y point |
newX | – Target X end-point |
newY | – Target Y end-point |
distance | – How far along this is (status) |
p_obj | – Object being moved |
E_Boolean MoveToFast | ( | T_sword32 * | oldX, |
T_sword32 * | oldY, | ||
T_sword32 | newX, | ||
T_sword32 | newY, | ||
T_sword32 | distance, | ||
T_sword32 | radius, | ||
T_sword32 | foot, | ||
T_sword32 | head, | ||
T_sword16 | height, | ||
T_3dObject * | p_movingObject | ||
) |
MoveToFast takes a given object and tries to move it to another location. If a collision is detected, a flag is returned and the global variables are filled with additional information.
oldX | – X Start point, and returned final point |
oldY | – Y Start point, and returned final point |
newX | – X Target end-point |
newY | – Y Target end-point |
distance | – How far along this is (status) |
radius | – Size of object |
foot | – Foot height (foot + climbHeight) |
head | – top of head |
height | – Height of object (fully) |
p_movingObject | – Object being moved |
T_void ProjectXYOntoLine | ( | T_sword32 * | pointX, |
T_sword32 * | pointY, | ||
T_sword32 | slopeX, | ||
T_sword32 | slopeY | ||
) |
ProjectXYOntoLine does the calculation necessary to do a linear projection of a vector going through the origin (the point) along a given line through the origin (the slope). The new point is returned by reference.
NOTE: Large values can cause overflow. Always be careful.
pointX | – X Point to project |
pointY | – Y Point to project |
slopeX | – X Slope to project along |
slopeY | – Y Slope to project along |
T_word16 View3dFindLineHits | ( | T_sword16 | x1, |
T_sword16 | y1, | ||
T_sword16 | x2, | ||
T_sword16 | y2, | ||
T_word16 | maxHits, | ||
T_sword16 * | lines | ||
) |
View3dFindLineHits takes the given line coordinates and array and determines a list of lines that intersect. Instead of returning intersection coordinates, distances to that line is returned.
x1 | – First X point of line to check |
y1 | – First Y point of line to check |
x2 | – Second X point of line to check |
y2 | – Second Y point of line to check |
maxHits | – Maximum number of array points |
lines | – List of lines and distances found. The array alternates between line number and then distance. |
View3dGetCeilingBelow returns the lowest ceiilng that the collisional move moved over.
below | – Returned ceiling |
View3dGetFloorAbove returns the highest floor that the collisional move moved over.
above | – Returned floor |
View3dGetFloorAndCeilingHeight is used to get the highest and lowest floor and ceiling of the last collisional move.
floor | – Returned floor height |
ceiling | – Returned ceiling height |
This routine returns a pointer to a list of sectors and the number sectors in that list.
NOTE: The data at the returned pointer is NOT to be modified, just copied.
numSectors | – Returned number of sectors in list. |
T_sword16 View3dMoveTo | ( | T_sword32 * | oldX, |
T_sword32 * | oldY, | ||
T_word16 | angle, | ||
T_sword32 | step, | ||
T_sword32 | radius, | ||
T_sword32 | foot, | ||
T_sword32 | head, | ||
T_sword16 | height, | ||
T_3dObject * | p_obj | ||
) |
View3dMoveTo is used to move the player from the current point to a new point.
oldX | – X Start location and place to put final ending location. |
oldY | – Y Start location and place to put final ending location. |
angle | – What angle to move to |
step | – Amount to step along direction |
radius | – Radius of collision detection. |
foot | – Foot height of object moving |
head | – Head height of object moving |
height | – Current height. |
p_obj | – Pointer to object moving |
T_sword16 View3dMoveToFast | ( | T_sword32 * | oldX, |
T_sword32 * | oldY, | ||
T_word16 | angle, | ||
T_sword32 | step, | ||
T_sword32 | radius, | ||
T_sword32 | foot, | ||
T_sword32 | head, | ||
T_sword32 | height, | ||
T_3dObject * | p_obj | ||
) |
View3dMoveToFast is the same as View3dMoveTo but does not try to slide and thus is a faster version.
T_sword16 View3dMoveToXY | ( | T_sword32 * | oldX, |
T_sword32 * | oldY, | ||
T_sword32 | newx, | ||
T_sword32 | newy, | ||
T_sword32 | radius, | ||
T_sword32 | foot, | ||
T_sword32 | head, | ||
T_sword16 | height, | ||
T_3dObject * | p_obj | ||
) |
View3dMoveTo is used to move the player from the current point to a new point.
oldX | – Start X location and place to put final ending location. |
oldY | – Start Y location and place to put final ending location. |
newx | – New X location to move to |
newy | – New Y location to move to |
radius | – Radius of collision detection. |
foot | – Foot height of object |
head | – Head height of object |
height | – Current height. |
p_obj | – Object moving |
T_sword16 View3dMoveToXYFast | ( | T_sword32 * | oldX, |
T_sword32 * | oldY, | ||
T_sword32 | newx, | ||
T_sword32 | newy, | ||
T_sword32 | radius, | ||
T_sword32 | foot, | ||
T_sword32 | head, | ||
T_sword16 | height, | ||
T_3dObject * | p_obj | ||
) |
View3dMoveToXYFast is used to move from a point to another point using the fast version of the algorithms.
oldX | – Start X location and place to put final ending location. |
oldY | – Start Y location and place to put final ending location. |
newx | – New X location to move to |
newy | – New Y location to move to |
foot | – Foot height of object |
head | – Head height of object |
radius | – Radius of collision detection. |
height | – Current height. |
p_obj | – Object moving |
E_Boolean View3dObjectHitFast | ( | T_sword16 | x, |
T_sword16 | y, | ||
T_word16 | radius, | ||
T_sword16 | lastX, | ||
T_sword16 | lastY, | ||
T_sword16 | zBottom, | ||
T_sword16 | zTop, | ||
T_sword16 | height, | ||
T_3dObject * | p_movingObject | ||
) |
View3dObjectHitFast is used to determine if an object will collide with another object or volume.
x | – Center X location to check |
y | – Center Y location to check |
radius | – Radius around point to check |
lastX | – Last X location for angular info. |
lastY | – Last Y location for angular info. |
zBottom | – Bottom of the object |
zTop | – Top of the object |
height | – Height of full object |
p_movingObject | – Object being moved |
View3dSetExceptObject declares what object is to be consider non- collidable
exceptId | – ID of object to exclude |
T_void View3dSetExceptObjectByPtr | ( | T_objMoveStruct * | p_objMove) |
View3dSetExceptObjectByPtr declares what object is to be consider non- collidable
p_objMove | – Direct pointer to object's move struc to exclude. |
T_word16 G_numHits = 0 |