restore the perspective computatoin

This commit is contained in:
Trammell hudson 2018-03-03 16:12:49 -05:00
parent a907622981
commit d6f1056f2f
Failed to extract signature
2 changed files with 10 additions and 18 deletions

View File

@ -54,17 +54,10 @@ camera_setup(
v3_t v = v3_norm(v3_cross(w, u)); v3_t v = v3_norm(v3_cross(w, u));
m44_t cam = {{ m44_t cam = {{
#if 0
{ u.p[0], v.p[0], w.p[0], 0 },
{ u.p[1], v.p[1], w.p[1], 0 },
{ u.p[2], v.p[2], w.p[2], 0 },
{ -v3_dot(u,eye), -v3_dot(v,eye), -v3_dot(w,eye), 1 },
#else
{ u.p[0], u.p[1], u.p[2], -v3_dot(u,eye) }, { u.p[0], u.p[1], u.p[2], -v3_dot(u,eye) },
{ v.p[0], v.p[1], v.p[2], -v3_dot(v,eye) }, { v.p[0], v.p[1], v.p[2], -v3_dot(v,eye) },
{ w.p[0], w.p[1], w.p[2], -v3_dot(w,eye) }, { w.p[0], w.p[1], w.p[2], -v3_dot(w,eye) },
{ 0, 0, 0, 1 }, { 0, 0, 0, 1 },
#endif
}}; }};
@ -77,10 +70,10 @@ camera_setup(
} }
// now compute the perspective projection matrix // now compute the perspective projection matrix
if(0) { if(1) {
float s = 1.0 / tan(fov * M_PI / 180 / 2); float s = 1000.0 / tan(fov * M_PI / 180 / 2);
c->near = 1; c->near = 1;
c->far = 2; c->far = 200;
float f1 = - c->far / (c->far - c->near); float f1 = - c->far / (c->far - c->near);
float f2 = - c->far * c->near / (c->far - c->near); float f2 = - c->far * c->near / (c->far - c->near);
@ -98,8 +91,7 @@ if(0) {
fprintf(stderr, " %+5.3f", pers.m[i][j]); fprintf(stderr, " %+5.3f", pers.m[i][j]);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
} }
// and apply it to the camera matrix to generate transform m44_mult(&c->r, &pers, &cam);
m44_mult(&c->r, &cam, &pers);
} else { } else {
// no perspective // no perspective
m44_t pers = {{ m44_t pers = {{
@ -109,7 +101,7 @@ if(0) {
{ 0, 0, 0, 1 }, { 0, 0, 0, 1 },
}}; }};
// and apply it to the camera matrix to generate transform // and apply it to the camera matrix to generate transform
m44_mult(&c->r, &cam, &pers); m44_mult(&c->r, &pers, &cam);
} }
@ -139,7 +131,7 @@ camera_project(
v4_t v = {{ v_in->p[0], v_in->p[1], v_in->p[2], 1 }}; v4_t v = {{ v_in->p[0], v_in->p[1], v_in->p[2], 1 }};
v4_t p = m44_multv(&c->r, &v); v4_t p = m44_multv(&c->r, &v);
p.p[2] *= -1; //p.p[2] *= -1;
// what if p->p[4] == 0? // what if p->p[4] == 0?
// pz < 0 == The point is behind us; do not display? // pz < 0 == The point is behind us; do not display?
@ -148,8 +140,8 @@ camera_project(
return 0; return 0;
// shrink by the distance // shrink by the distance
p.p[0] *= 1000 / p.p[2]; p.p[0] *= 1.0 / p.p[3];
p.p[1] *= 1000 / p.p[2]; p.p[1] *= 1.0 / p.p[3];
//p[2] /= 1000; //p[2] /= 1000;
// Transform to screen coordinate frame, // Transform to screen coordinate frame,

View File

@ -180,8 +180,8 @@ int main(
float scale = 1; float scale = 1;
float fov = 45; float fov = 45;
float prune = 0.1; float prune = 0.1;
float width = 4096; float width = 1000;
float height = 2048; float height = 1000;
while((opt = getopt_long(argc, argv ,"h?vBCHc:l:s:u:p:F:", long_options, NULL)) != -1) while((opt = getopt_long(argc, argv ,"h?vBCHc:l:s:u:p:F:", long_options, NULL)) != -1)
{ {