static void update_viewproj_matrix(struct gs_device *device)
{
	struct gs_shader *vs = device->cur_vertex_shader;
	struct matrix4 cur_proj;

	gs_matrix_get(&device->cur_view);
	matrix4_copy(&cur_proj, &device->cur_proj);

	if (device->cur_fbo) {
		cur_proj.x.y = -cur_proj.x.y;
		cur_proj.y.y = -cur_proj.y.y;
		cur_proj.z.y = -cur_proj.z.y;
		cur_proj.t.y = -cur_proj.t.y;

		glFrontFace(GL_CW);
	} else {
		glFrontFace(GL_CCW);
	}

	gl_success("glFrontFace");

	matrix4_mul(&device->cur_viewproj, &device->cur_view, &cur_proj);
	matrix4_transpose(&device->cur_viewproj, &device->cur_viewproj);

	if (vs->viewproj)
		gs_shader_set_matrix4(vs->viewproj, &device->cur_viewproj);
}
Exemple #2
0
void
heightfield_set_world_matrix(heightfield hf, matrix4 world)
{
  matrix4_copy(SF_OBJECT3D(hf)->world, world);
}
Exemple #3
0
void Computation::traverse(Bone * ptr, int skelNum, double transform[4][4], char c){

	if (ptr != NULL) {

		double Rx[4][4], Ry[4][4], Rz[4][4], M[4][4]; //store rotation matrices.
		double transformBackUp[4][4];
		double translation[4][4];

		double C[4][4], Cinv[4][4];

		matrix4_copy(transform, transformBackUp);

		//create homogeneous transformation to next frame.

		identity(M);
		identity(translation);
		identity(Rx);
		identity(Ry);
		identity(Rz);

		// compute C
		rotationZ(Rz, ptr->axis_z);
		rotationY(Ry, ptr->axis_y);
		rotationX(Rx, ptr->axis_x);

		matrix4_mult(Rz, Ry, C);
		matrix4_mult(C, Rx, C);

		// compute M
		rotationX(Rx, (ptr->rx));
		rotationY(Ry, (ptr->ry));
		rotationZ(Rz, (ptr->rz));

		matrix4_mult(Rz, Ry, M);
		matrix4_mult(M, Rx, M);

		M[0][3] += ptr->tx;
		M[1][3] += ptr->ty;
		M[2][3] += ptr->tz;

		matrix4_mult(transform, C, transform);
		matrix4_mult(transform, M, transform);

		if(c == 'g') computeCM(ptr, skelNum, transform);
		if(c == 'h') computePos(ptr, transform);

		translation[0][3] = ptr->dir[0]*ptr->length;
		translation[1][3] = ptr->dir[1]*ptr->length;
		translation[2][3] = ptr->dir[2]*ptr->length;

		matrix4_mult(transform, translation, transform);
		matrix4_transpose(C, Cinv);
		matrix4_mult(transform, Cinv, transform);

		traverse(ptr->child, skelNum, transform, c);

		traverse(ptr->sibling, skelNum, transformBackUp, c);


	}

}
static void recalculate_transition_matrix(obs_source_t *tr, size_t idx)
{
    obs_source_t *child;
    struct matrix4 mat;
    struct vec2 pos;
    struct vec2 scale;
    float tr_cx = (float)tr->transition_actual_cx;
    float tr_cy = (float)tr->transition_actual_cy;
    float source_cx;
    float source_cy;
    float tr_aspect = tr_cx / tr_cy;
    float source_aspect;
    enum obs_transition_scale_type scale_type = tr->transition_scale_type;

    lock_transition(tr);

    child = tr->transition_sources[idx];
    if (!child) {
        unlock_transition(tr);
        return;
    }

    source_cx = (float)obs_source_get_width(child);
    source_cy = (float)obs_source_get_height(child);
    unlock_transition(tr);

    if (source_cx == 0.0f || source_cy == 0.0f)
        return;

    source_aspect = source_cx / source_cy;

    if (scale_type == OBS_TRANSITION_SCALE_MAX_ONLY) {
        if (source_cx > tr_cx || source_cy > tr_cy) {
            scale_type = OBS_TRANSITION_SCALE_ASPECT;
        } else {
            scale.x = 1.0f;
            scale.y = 1.0f;
        }
    }

    if (scale_type == OBS_TRANSITION_SCALE_ASPECT) {
        bool use_width = tr_aspect < source_aspect;
        scale.x = scale.y = use_width ?
                            tr_cx / source_cx :
                            tr_cy / source_cy;

    } else if (scale_type == OBS_TRANSITION_SCALE_STRETCH) {
        scale.x = tr_cx / source_cx;
        scale.y = tr_cy / source_cy;
    }

    source_cx *= scale.x;
    source_cy *= scale.y;

    vec2_zero(&pos);
    add_alignment(&pos, tr->transition_alignment,
                  (int)(tr_cx - source_cx),
                  (int)(tr_cy - source_cy));

    matrix4_identity(&mat);
    matrix4_scale3f(&mat, &mat, scale.x, scale.y, 1.0f);
    matrix4_translate3f(&mat, &mat, pos.x, pos.y, 0.0f);
    matrix4_copy(&tr->transition_matrices[idx], &mat);
}