Пример #1
0
LookupNode<GameObject *,ObjIdType> * ObjectManager::get(const ObjIdType & id, const unsigned int & turn, const unsigned int & frame )
{
    if (!Singleton<ObjectManager>::isInit())
	return NULL;


    if (turn >= turns() || frame >= frames())
	return NULL;

    return Single::get()->m_objects.node(id,turn,frame);
}
Пример #2
0
bool pointInPoly (const VECTOR3 * const point, int points, const VECTOR3 * const poly)
{
	VECTOR3
		u, v,
		plane;
	enum dim_drop
		drop;
	int
		i = 0,
		side,
		sideMatch = 10;
	float
		x, y,
		px[2], py[2];
	if (points < 3)
		return false;
	u = vectorSubtract (&poly[1], &poly[0]);
	v = vectorSubtract (&poly[2], &poly[0]);
	plane = vectorCross (&u, &v);
	drop =
		(fabs(plane.x) > fabs(plane.y))
			? (fabs(plane.x) > fabs(plane.z))
				? DROP_X
				: DROP_Z
			: (fabs(plane.y) > fabs(plane.z))
				? DROP_Y
				: DROP_Z;

	//printf ("dropping %c\n", drop == DROP_X ? 'X' : drop == DROP_Y ? 'Y' : 'Z');
	x = (drop == DROP_X) ? point->y : point->x;
	y = (drop == DROP_Z) ? point->y : point->z;
	px[1] = (drop == DROP_X) ? poly[points-1].y : poly[points-1].x;
	py[1] = (drop == DROP_Z) ? poly[points-1].y : poly[points-1].z;
	while (i < points)
	{
		px[0] = px[1];
		py[0] = py[1];
		px[1] = (drop == DROP_X) ? poly[i].y : poly[i].x;
		py[1] = (drop == DROP_Z) ? poly[i].y : poly[i].z;
		side = turns (x, y, px[0], py[0], px[1], py[1]);

		//printf ("%.2f, %.2f vs. %.2f, %.2f -> %.2f, %.2f: %c\n", x, y, px[0], py[0], px[1], py[1], d == RIGHT ? 'R' : d == LEFT ? 'L' : 'T');

		if (sideMatch != 10 && side != sideMatch)
			return false;
		sideMatch = side;
		i++;
	}
	return true;
}
Пример #3
0
bool pointInHex (const VECTOR3 * const point)
{
	int
		i = 0,
		j,
		t;
	//printf ("intersection point: %.2f, %.2f, %.2f\n", point->x, point->y, point->z);
	while (i < 6)
	{
		j = i == 5 ? 0 : i + 1;
		t = turns (point->x, point->z, H[i][X], H[i][Y], H[i][X] + H[j][X], H[i][Y] + H[j][Y]);
		//printf ("%d: %s\n", i, t == LEFT ? "LEFT" : t == RIGHT ? "RIGHT" : "THROUGH");
		if (t == RIGHT)
			return false;
		i++;
	}
	return true;
}
Пример #4
0
void position_baryPoints (Entity e, SUBHEX * platters, float * weights)
{
	POSITION
		pos = component_getData (entity_getAs (e, "position"));
	hexPos
		base;
	int
		x, y;
	unsigned int
		r, k, i,
		third;
	VECTOR3
		inversePos,
		distance[2];
	if (!pos)
		return;
	base = pos->position;
	
	// 1. change the platter to focus < 1 ? 1 : focus instead of just 1
	platters[0] = hexPos_platter (base, 1);
	assert (platters[0] != NULL);
	// 2. figure out a way to do the barycentric math when not using a span 1 platter
	v2c (&pos->pos, &x, &y);
	hex_xy2rki (x, y, &r, &k, &i);
	platters[1] = mapHexAtCoordinateAuto (platters[0], 0, XY[k][X], XY[k][Y]);
	distance[0] = mapDistanceBetween (platters[0], platters[1]);
	if (turns (pos->pos.x, pos->pos.z, 0.0, 0.0, distance[0].x, distance[0].z) == RIGHT)
		third = (k + 1) % 6;
	else
		third = (k + 5) % 6;
	platters[2] = mapHexAtCoordinateAuto (platters[0], 0, XY[third][X], XY[third][Y]);
	distance[1] = mapDistanceBetween (platters[0], platters[2]);

	inversePos = vectorMultiplyByScalar (&pos->pos, -1);
	//printf ("have pos %.2f,%.2f w/ 0,0; %.2f,%.2f; %.2f,%.2f\n", pos->pos.x, pos->pos.z, distance[0].x, distance[0].z, distance[1].x, distance[1].z);
	baryWeights (&inversePos, &distance[0], &distance[1], weights);
}