Example #1
0
// Determines whether this AABB intersects another AABB
bool AABB::intersectsAABB(const AABB& box) const {
   const IAPoint &min2 = box.m_min, &max2 = box.m_max;

   // Check if x, y, and z planes are inside of the other AABB's x, y, and z planes
   return ((X_COORD(m_max) > X_COORD(min2)) && (X_COORD(m_min) < X_COORD(max2)) &&
           (Y_COORD(m_max) > Y_COORD(min2)) && (Y_COORD(m_min) < Y_COORD(max2)) &&
           (Z_COORD(m_max) > Z_COORD(min2)) && (Z_COORD(m_min) < Z_COORD(max2)));
}
Example #2
0
// Find an island entry
struct island_data *closest_island(int x, int y) {
	struct island_data *isle, *best = NULL;
	int b = USE_SIZE;

	for (isle = island_list; isle; isle = isle->next)
		if (compute_distance(X_COORD(isle->loc), Y_COORD(isle->loc), x, y) < b) {
			best = isle;
			b = compute_distance(X_COORD(isle->loc), Y_COORD(isle->loc), x, y);
		}

	return best;
}
Example #3
0
/**
* Convert terrain from one thing to another near other terrain.
* 
* @param int from Terrain to convert from.
* @param int to Terrain to convert to.
* @param int near Terrain it must be near.
* @param int dist Distance it must be within.
*/
void replace_near(int from, int to, int near, int dist) {
	int x, y, hor, ver, at, loc;
	int found;
	
	for (x = 0; x < USE_WIDTH; ++x) {
		for (y = 0; y < USE_HEIGHT; ++y) {
			at = MAP(x, y);
			
			if (grid[at].type == from) {
				found = 0;
				for (hor = -dist; hor <= dist && !found; ++hor) {
					for (ver = -dist; ver <= dist && !found; ++ver) {
						loc = shift(at, hor, ver);
						
						if (loc != -1 && grid[loc].type == near && compute_distance(X_COORD(at), Y_COORD(at), X_COORD(loc), Y_COORD(loc)) <= dist) {
							change_grid(at, to);
							found = 1;
						}
					}
				}
			}
		}
	}
}
Example #4
0
// This takes an initial point 'origin' and translates it by x,y
// may return -1 if no valid location
inline int shift(int origin, int x_shift, int y_shift) {
	int loc = origin, y_coord, x_coord;
	
	// sanity
	if (loc < 0 || loc >= USE_SIZE) {
		return -1;
	}
	
	x_coord = X_COORD(loc);
	y_coord = Y_COORD(loc);

	// handle X
	if (x_coord + x_shift < 0) {
		if (USE_WRAP_X) {
			loc += x_shift + USE_WIDTH;
		}
		else {
			// off the left side
			return -1;
		}
	}
	else if (x_coord + x_shift >= USE_WIDTH) {
		if (USE_WRAP_X) {
			loc += x_shift - USE_WIDTH;
		}
		else {
			// off the right side
			return -1;
		}
	}
	else {
		loc += x_shift;
	}
	
	// handle Y
	if (y_coord + y_shift < 0) {
		if (USE_WRAP_Y) {
			loc += (y_shift * USE_WIDTH) + USE_SIZE;
		}
		else {
			// off the bottom
			return -1;
		}
	}
	else if (y_coord + y_shift >= USE_HEIGHT) {
		if (USE_WRAP_Y) {
			loc += (y_shift * USE_WIDTH) - USE_SIZE;
		}
		else {
			// off the top
			return -1;
		}
	}
	else {
		loc += (y_shift * USE_WIDTH);
	}

	// again, we can ONLY return map locations
	if (loc >= 0 && loc < USE_SIZE) {
		return loc;
	}
	else {
		return -1;
	}
}
Example #5
0
// Determines whether this AABB contains the given point
bool AABB::contains(const IAPoint &p) const {
   // Check if x, y, and z coords are inside of the planes defined by my six x, y, and z sides
   return ((X_COORD(m_max) > X_COORD(p)) && (X_COORD(m_min) < X_COORD(p)) &&
           (Y_COORD(m_max) > Y_COORD(p)) && (Y_COORD(m_min) < Y_COORD(p)) &&
           (Z_COORD(m_max) > Z_COORD(p)) && (Z_COORD(m_min) < Z_COORD(p)));
}