unsigned x, y;
unsigned i;
float aspect;
- float cyl_w_sq;
+ float cyl_radius;
+ float cyl_arc;
float sin_ksv;
float cos_ksv;
+ float distance;
+ float eye[3];
+ float look[3];
t = monitor->tessellation;
data_size = (t+1)*(t+1)*4*sizeof(float);
vertex_data = (float *)malloc(data_size);
+
aspect = (float)monitor->width/monitor->height;
- cyl_w_sq = 0.25f-(0.5f-monitor->cylinder_depth)*(0.5f-monitor->cylinder_depth);
+
+ if(monitor->cylinder_depth)
+ {
+ cyl_radius = (monitor->cylinder_depth*monitor->cylinder_depth+0.25f)/(2.0f*monitor->cylinder_depth);
+ cyl_arc = 2.0f*asin(0.5f/cyl_radius);
+ }
+
sin_ksv = monitor->keystone_vertical/sqrt(1.0f+monitor->keystone_vertical*monitor->keystone_vertical);
cos_ksv = sqrt(1.0f-sin_ksv*sin_ksv);
+ distance = monitor->perspective+sin_ksv*((sin_ksv>0)-monitor->vertical_center)/aspect;
+
+ eye[0] = 0.0f;
+ eye[1] = (monitor->vertical_center-0.5f)/aspect+sin_ksv*distance;
+ eye[2] = cos_ksv*distance;
+
+ look[0] = 0.0f;
+ look[1] = -sin_ksv;
+ look[2] = -cos_ksv;
+
for(y=0; y<=t; ++y)
for(x=0; x<=t; ++x)
{
- float xf, yf, z, rz;
- float scale;
float *v;
- xf = (float)x/t;
- yf = (float)y/t;
-
- v = vertex_data+(y*(t+1)+x)*4;
- v[2] = (monitor->x+xf*monitor->width)/screen->width;
- v[3] = ((float)screen->height-monitor->y-monitor->height+yf*monitor->height)/screen->height;
-
- z = sqrt(0.25f-(xf-0.5f)*(xf-0.5f)*4.0f*cyl_w_sq)-0.5f+monitor->cylinder_depth;
- if(monitor->keystone_vertical>0)
+ v = vertex_data+(y*(t+1)+x)*3;
+ v[0] = (float)x/t-0.5f;
+ v[1] = ((float)y/t-0.5f)/aspect;
+ v[2] = 0;
+ if(monitor->cylinder_depth)
{
- rz = (1.0f-yf)/aspect*sin_ksv+z*cos_ksv;
- yf = 1.0f-((1.0f-yf)*cos_ksv-z*aspect*sin_ksv);
- z = rz;
+ v[2] = (1.0f-cos(v[0]*cyl_arc))*cyl_radius-monitor->cylinder_depth;
+ v[0] = sin(v[0]*cyl_arc)*cyl_radius;
}
- else if(monitor->keystone_vertical<0)
- {
- rz = z*cos_ksv-yf/aspect*sin_ksv;
- yf = yf*cos_ksv+z*aspect*sin_ksv;
- z = rz;
- }
- scale = monitor->perspective/(monitor->perspective+z);
- v[0] = 0.5f+(xf-0.5f)*scale;
- v[1] = monitor->vertical_center+(yf-monitor->vertical_center)*scale;
}
+
+ for(y=t; y<=t; --y)
+ for(x=t; x<=t; --x)
+ {
+ float *v;
+ float px, py, pz;
+ float scale;
+
+ v = vertex_data+(y*(t+1)+x)*3;
+ px = v[0]-eye[0];
+ py = (v[0]-eye[0])*look[0] - (v[1]-eye[1])*look[2] + (v[2]-eye[2])*look[1];
+ pz = (v[0]-eye[0])*look[0] + (v[1]-eye[1])*look[1] + (v[2]-eye[2])*look[2];
+ scale = monitor->perspective/pz;
+
+ v = vertex_data+(y*(t+1)+x)*4;
+ v[0] = px*scale+0.5f;
+ v[1] = py*aspect*scale+monitor->vertical_center;
+ v[2] = (monitor->x+(float)x*monitor->width/t)/screen->width;
+ v[3] = 1.0f-(monitor->y+(1.0f-(float)y/t)*monitor->height)/screen->height;
+ }
+
glBindBuffer(GL_ARRAY_BUFFER, monitor->vertex_buffer);
glBufferData(GL_ARRAY_BUFFER, data_size, vertex_data, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);