示例#1
0
Mesh itemDamage(float damageValue)
{
    damageValue = limit<float>(damageValue, 0, 1);
    if(damageValue == 0)
        return Mesh();
    TextureDescriptor backgroundTexture = TextureAtlas::DamageBarGray.td();
    TextureDescriptor foregroundTexture = TextureAtlas::DamageBarGreen.td();
    if(damageValue > 1.0f / 3)
    {
        foregroundTexture = TextureAtlas::DamageBarYellow.td();
    }
    if(damageValue > 2.0f / 3)
    {
        foregroundTexture = TextureAtlas::DamageBarRed.td();
    }
    const float minX = 2 / 16.0f;
    const float maxX = 14 / 16.0f;
    float splitX = interpolate(damageValue, maxX, minX);
    const float minY = 2 / 16.0f;
    const float maxY = 4 / 16.0f;
    constexpr ColorF c = colorizeIdentity();
    const VectorF nxny = VectorF(minX, minY, 0);
    VectorF cxny = VectorF(splitX, minY, 0);
    const VectorF pxny = VectorF(maxX, minY, 0);
    const VectorF nxpy = VectorF(minX, maxY, 0);
    VectorF cxpy = VectorF(splitX, maxY, 0);
    const VectorF pxpy = VectorF(maxX, maxY, 0);
    Mesh retval = quadrilateral(foregroundTexture,
                             nxny, c,
                             cxny, c,
                             cxpy, c,
                             nxpy, c);
    retval.append(quadrilateral(backgroundTexture,
                             cxny, c,
                             pxny, c,
                             pxpy, c,
                             cxpy, c));
    return retval;
}
示例#2
0
/* find intersection of lines v0 to v1 and v2 to v3*/
static int
patch(vec2 v0, vec2 v1, vec2 v2, vec2 v3)
{
	vec1	denom;
	vec1	mu;
	vec2	v4;

	denom = (v1.x-v0.x)*(v3.y-v2.y) - (v1.y-v0.y)*(v3.x-v2.x);
	if(fabs(denom) > epsilon) {
		mu = ((v2.x-v0.x)*(v3.y-v2.y) - (v2.y-v0.y)*(v3.x-v2.x))/denom;

		/* if intersection between lines v0 to v1 and v2 to v3,
		 * call it v4 and form triangles v0,v2,v4 and v1,v3,v4
		 */
		if(mu >= 0 && mu <= 1) {
			v4.x = (1-mu)*v0.x + mu*v1.x;
			v4.y = (1-mu)*v0.y + mu*v1.y;
			triangle(v0, v2, v4);
			triangle(v1, v3, v4);
			return 0;
		}
	}

	/* else find intersection of lines v0 to v2 and v1 to v3*/
	denom = (v2.x-v0.x)*(v3.y-v1.y) - (v2.y-v0.y)*(v3.x-v1.x);
	if(fabs(denom) > epsilon) {
		mu = ((v1.x-v0.x)*(v3.y-v1.y) - (v1.y-v0.y)*(v3.x-v1.x))/denom;

		/* if intersection between v0 and v1, call it v4
		 * and form triangles v0,v1,v4 and v2,v3,v4
		 */
		if(mu >= 0 && mu <= 1) {
			v4.x = (1-mu)*v0.x + mu*v2.x;
			v4.y = (1-mu)*v0.y + mu*v2.y;
			triangle(v0, v1, v4);
			triangle(v2, v3, v4);
			return 0;
		}
	}

	/* there are no proper intersections so form quadrilateral v0,v1,v3,v2*/
	quadrilateral(v0, v1, v3, v2);
	return 1;
}
示例#3
0
文件: raytracer2.c 项目: lnieto-m/RT
static gboolean		intersection2(t_env *rt, t_vector ray, t_vector origin,
	int i)
{
	if ((rt->object[i].name == L_SPHERE && limited_sphere(ray,
		rt->object[i], origin, rt)) ||
	(rt->object[i].name == L_CYLINDER && limited_cylinder(ray,
		rt->object[i], origin, rt)) ||
	(rt->object[i].name == L_CONE && limited_cone(ray, rt->object[i]
		, origin, rt)) ||
	(rt->object[i].name == TRIANGLE && triangle(ray, rt->object[i],
		&rt->t, origin)) ||
	(rt->object[i].name == TORUS && torus(ray, rt->object[i], &rt->t
		, origin)) ||
	(rt->object[i].name == ELLIPSOIDE && ellipsoide(ray, rt->object[i],
		&rt->t, origin)) ||
	(rt->object[i].name == PARABOL && parabol(ray, rt->object[i],
		&rt->t, origin)) ||
	(rt->object[i].name == QUADRILATERAL && quadrilateral(ray,
		rt->object[i], &rt->t, origin)) ||
	(rt->object[i].name == CUBE && cube(ray, &rt->object[i], &rt->t,
		origin)))
		return (1);
	return (0);
}