All pastes #637459 Raw Edit

Unnamed

public text v1 · immutable
#637459 ·published 2007-07-28 22:17 UTC
rendered paste body

in convertblender.c:

/* RE_scatter_init(G.scene->camera); */
void RE_scatter_init(Object *camera)
{
    extern struct Render R;
    Render *re;
    float cammat[4][4];
    int winx, winy;
    
    /* check if we have a camera */
    if(camera==NULL) {
        printf("scatter: no camera\n");
        return;
    }
    
    /* setup Render */
    re= RE_NewRender("_world to image Z space mat__");
    winx= (G.scene->r.size*G.scene->r.xsch)/100;
    winy= (G.scene->r.size*G.scene->r.ysch)/100;
    RE_InitState(re, &G.scene->r, winx, winy, NULL);
    
    RE_SetCamera(re, camera);

    Mat4Ortho(camera->obmat);
    Mat4Invert(cammat, camera->obmat);
    RE_SetView(re, cammat);

    R = *re;
}

/* co is {x pixel, y pixel, z from pass} */
void RE_scatter_map_screen_to_world(float *co)
{
	float fac, x, y, z, view[3];

	x = co[0];
	y = co[1];
	z = co[2];
	
	view[2]= -ABS(R.clipsta);
	
	x= (x/(float)R.winx);
	view[0]= R.viewplane.xmin + x*(R.viewplane.xmax - R.viewplane.xmin);
	
	y= (y/(float)R.winy);
	view[1]= R.viewplane.ymin + y*(R.viewplane.ymax - R.viewplane.ymin);

	co[2]= -z;

	fac= co[2]/view[2];
	co[0]= fac*view[0];
	co[1]= fac*view[1];

	mat4_project(R.viewinv, co);
}

void RE_scatter_map_world_to_screen(float *co)
{
	float fac, x, y, z, view[3];

	mat4_project(R.viewmat, co);

	z = -co[2];

	view[2]= -ABS(R.clipsta);
	fac = co[2]/view[2];
	view[0] = co[0]/fac;
	view[1] = co[1]/fac;

	x = (view[0] - R.viewplane.xmin)/(R.viewplane.xmax - R.viewplane.xmin);
	x = x*R.winx;

	y = (view[1] - R.viewplane.ymin)/(R.viewplane.ymax - R.viewplane.ymin);
	y = y*R.winy;

	co[0] = x;
	co[1] = y;
	co[2] = z;
}