Esempio n. 1
0
File: Math.cpp Progetto: knied/LD29
Matrix<float, 4, 4> look_at(const Vector<float, 3> at, const Vector<float, 3> eye, const Vector<float, 3> up) {
    Vector<float, 3> zaxis = vector_normal(at - eye);
    Vector<float, 3> xaxis = vector_normal(cross(up, zaxis));
    Vector<float, 3> yaxis = cross(zaxis, xaxis);
    
    return Matrix<float, 4, 4>(xaxis[0], xaxis[1], xaxis[2], -dot(xaxis, eye),
                               yaxis[0], yaxis[1], yaxis[2], -dot(yaxis, eye),
                               zaxis[0], zaxis[1], zaxis[2], -dot(zaxis, eye),
                               0, 0, 0, 1);
}
Esempio n. 2
0
/*
=================
line_recalculate
=================
*/
GNUC_NONNULL static void line_recalculate (const g_entity_t *ent)
{
    const double zero[3] = { 0.0, 0.0, 1.0 };
    ent_render_line_t *r = ent->render_data;
    double length, v[3], n[3];

    if (!ent->render_valid)
        return;

    if (r->width < 0.1)
    {
        r->draw = false;
        return;
    }

    vector_sub(r->finish, ent->origin, v);
    length = vector_length(v);

    if (length < 0.1)
    {
        r->draw = false;
        return;
    }

    r->draw = true;

    vector_normal(v, zero, n);
    vector_normalize(n);
    vector_mul(n, r->width / 2.0, n);

    r->verts[0] = n[0];
    r->verts[1] = n[1];
    r->verts[2] = -n[0];
    r->verts[3] = -n[1];

    vector_add(r->finish, n, &r->verts[4]);
    vector_sub(&r->verts[4], ent->origin, &r->verts[4]);
    vector_sub(r->finish, n, &r->verts[6]);
    vector_sub(&r->verts[6], ent->origin, &r->verts[6]);

    r->texcoords[0] = 0.0; r->texcoords[1] = length / r->texture->w;
    r->texcoords[2] = 1.0; r->texcoords[3] = r->texcoords[1];
    r->texcoords[4] = 0.0; r->texcoords[5] = 0.0;
    r->texcoords[6] = 1.0; r->texcoords[7] = 0.0;
}
static void SampleFace(Vector outV, Vector xv, Vector yv, Vector zv, CosineBlurFilterContext *context, RenderFlags flags, FPMColor *colorAccum, float *weightAccum)
{
	assert(colorAccum != NULL && weightAccum != NULL);
	
	FPMDimension size = context->size;
	float scaleBias = context->scaleBias;
	float scaleOffset = context->scaleOffset;
	
	float incr = 2.0f / size;
	
	FPMDimension x, y;
	for (y = 0; y < size; y++)
	{
		float fy = (float)y * incr - 1.0f;
		float fx = -1.0f;
		
		for (x = 0; x < size; x++, fx += incr)
		{
			Vector v = vector_add(vector_multiply_scalar(xv, fx), vector_add(vector_multiply_scalar(yv, fy), zv));
			v = vector_normal(v);
			float weight = dot_product(v, outV);
			if (weight <= 0.0f)  continue;
			
			FPMColor color = context->source(MakeCoordsVector(v), flags, context->sourceContext);
			if (!IsValidColor(color))
			{
				continue;
			}
			float localWeight = (scaleBias + color.a * scaleOffset);
			color = FPMColorMultiply(color, weight * localWeight);
			
			*colorAccum = FPMColorAdd(*colorAccum, color);
			*weightAccum += weight;
		}
	}
}