PDA

View Full Version : Fitting a huge drawing



devdept
04-14-2010, 07:10 AM
Hi All,

Trying to fit a drawing with some points at Z coord like 6e+101 we got the perspective projection matrix with -Infinity as m[14] value. Is there a way to make a compromise and avoid the program to crash?

Can I replace the -Infinity with a finite value for example?

The real values for m[14] below are:

zNear = 9.62e+171
zFar = 1.30e+172
deltaZ = 3.46e+171

[EDIT] I forgot to mention that other OpenGL based CAD systems can fit this model.

Thanks,

Alberto


double radians = fovy/2*Math.PI/180;

double deltaZ = zFar - zNear;
double sine = Math.Sin(radians);

if (deltaZ == 0 || sine == 0 || aspect == 0)

return;

double cotangent = Math.Cos(radians)/sine;

double[] m = new double[16];

m[0] = cotangent/aspect; // m[0][0] = cotangent / aspect;
m[5] = cotangent; // m[1][1] = cotangent;
m[10] = -(zFar + zNear)/deltaZ; // m[2][2] = -(zFar + zNear) / deltaZ;
m[11] = -1; // m[2][3] = -1;
m[14] = -2*zNear*zFar/deltaZ; // m[3][2] = -2 * zNear * zFar / deltaZ;

devdept
04-14-2010, 08:43 AM
Maybe I can set the m[14] to double.MAX value and compute a new near plane value accordingly?

Thanks,

Alberto

dorbie
04-16-2010, 04:52 PM
Place bounds on the size and scale the model down by the ratio of the original and adjusted clip.

You can do this around teh eye but you'd be better off bringing all of this into some sane range and compensating.

CAD applications often have scale/unit multipliers somewhere in their system.

devdept
04-17-2010, 05:51 AM
Hi dorbie,

I know but in this - quite abusurd and unique - case we were trying simply to avoid a crash.

Do you think that passing +/- double.Max and change near plane position will help?

Thanks,

Alberto