-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
Hi,
as promised, the orthographic camera that uses (nearly)* the same convention as the perspective camera and the draw/rasterize/etc are using:
void t2d_make_orthographic_camera(t2d_pipeline *pipeline, float width_scale, float aspect, float near, float far){
pipeline->proj_matrix = matrix_zero();
pipeline->proj_matrix.m[0][0] = 2.0f/width_scale;
pipeline->proj_matrix.m[1][1] = 2.0f*aspect/width_scale;
pipeline->proj_matrix.m[2][2] = -1.0f/(far-near);
pipeline->proj_matrix.m[3][2] = -far/(far-near);
pipeline->proj_matrix.m[3][3] = 1.0f;
}
'world space' to 'projected space' mapping:
- X
[-width_scale/2, +width_scale/2]==>[-1.0, +1.0] - Y
[-width_scale/(2*aspect), +width_scale/(2*aspect)]==>[-1.0, +1.0] - Z
[-near...-far]==>[-1.0, 0.0] - W
don't modify (was at 1.0, stay at 1.0)
Example:
// 20.0f: This means that the world is projected and scaled so that [-10...+10] in the world is now [0...widht-1] on your screen
t2d_make_orthographic_camera(&pipeline, 20.0f, (float)ctx.width/(float)ctx.height, 0.1f, 100);
*Only the 1/z scaling of the zBuffer is not possible without hacking the draw/rasterize code, it uses linear scaling, but with same/compatible bounds, so it should work
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels