move window matrix translation into its own function. (no functional changes)

This commit is contained in:
Campbell Barton
2010-10-02 19:06:20 +00:00
parent 283372ab3c
commit 5faa29b01d
3 changed files with 24 additions and 26 deletions
+2
View File
@@ -149,6 +149,8 @@ void perspective_m4(float mat[4][4], float left, float right,
float bottom, float top, float nearClip, float farClip);
void orthographic_m4(float mat[4][4], float left, float right,
float bottom, float top, float nearClip, float farClip);
void window_translate_m4(float winmat[][4], float perspmat[][4],
float x, float y);
int box_clip_bounds_m4(float boundbox[2][3],
float bounds[4], float winmat[4][4]);
+20
View File
@@ -1647,6 +1647,26 @@ void perspective_m4(float mat[][4],float left, float right, float bottom, float
}
/* translate a matrix created by orthographic_m4 or perspective_m4 in viewspace XY coords (used to jitter the view)
* transforms in worldspace coords. */
void window_translate_m4(float winmat[][4], float perspmat[][4], float x, float y)
{
if(winmat[2][3] == -1.0f) {
/* in the case of a win-matrix, this means perspective always */
float v1[3]= {perspmat[0][0], perspmat[1][0], perspmat[2][0]};
float v2[3]= {perspmat[0][1], perspmat[1][1], perspmat[2][1]};
float len1= (1.0f / len_v3(v1));
float len2= (1.0f / len_v3(v2));
winmat[2][0] += len1 * winmat[0][0] * x;
winmat[2][1] += len2 * winmat[1][1] * y;
}
else {
winmat[3][0] += x;
winmat[3][1] += y;
}
}
static void i_multmatrix(float icand[][4], float Vm[][4])
{
int row, col;
+2 -26
View File
@@ -153,45 +153,21 @@ static void screen_opengl_render_apply(OGLRender *oglrender)
else {
/* simple accumulation, less hassle then FSAA FBO's */
# define SAMPLES 5 /* fixed, easy to have more but for now this is ok */
const float jit_ofs[SAMPLES][2] = {{0, 0}, {1,1}, {-1,-1}, {-1,1}, {1,-1}};
const float jit_ofs[SAMPLES][2] = {{0, 0}, {0.5f, 0.5f}, {-0.5f,-0.5f}, {-0.5f, 0.5f}, {0.5f, -0.5f}};
float winmat_jitter[4][4];
float *accum_buffer= MEM_mallocN(sizex * sizey * sizeof(float) * 4, "accum1");
float *accum_tmp= MEM_mallocN(sizex * sizey * sizeof(float) * 4, "accum2");
int j, i;
float *from, *to;
float pixelsize[2];
/* first sample buffer, also initializes 'rv3d->persmat' */
ED_view3d_draw_offscreen(scene, v3d, ar, sizex, sizey, NULL, winmat);
glReadPixels(0, 0, sizex, sizey, GL_RGBA, GL_FLOAT, accum_buffer);
if(is_ortho) {
pixelsize[0]= 0.5f / sizex;
pixelsize[1]= 0.5f / sizey;
}
else {
/* copied from view3d_main_area_setup_view */
float v1[3]= {rv3d->persmat[0][0], rv3d->persmat[1][0], rv3d->persmat[2][0]};
float v2[3]= {rv3d->persmat[0][1], rv3d->persmat[1][1], rv3d->persmat[2][1]};
float len1= (1.0f / len_v3(v1)) / (float)sizex;
float len2= (1.0f / len_v3(v2)) / (float)sizey;
pixelsize[0]= 0.5 * len1 * winmat[0][0];
pixelsize[1]= 0.5 * len2 * winmat[1][1];
}
/* skip the first sample */
for(j=1; j < SAMPLES; j++) {
copy_m4_m4(winmat_jitter, winmat);
if(is_ortho) {
winmat_jitter[3][0] += jit_ofs[j][0] * pixelsize[0];
winmat_jitter[3][1] += jit_ofs[j][1] * pixelsize[1];
}
else {
winmat_jitter[2][0] += jit_ofs[j][0] * pixelsize[0];
winmat_jitter[2][1] += jit_ofs[j][1] * pixelsize[1];
}
window_translate_m4(winmat_jitter, rv3d->persmat, jit_ofs[j][0] / sizex, jit_ofs[j][1] / sizey);
ED_view3d_draw_offscreen(scene, v3d, ar, sizex, sizey, NULL, winmat_jitter);
glReadPixels(0, 0, sizex, sizey, GL_RGBA, GL_FLOAT, accum_tmp);