PDA

View Full Version : how much does the precision of the opengl rendering is



xiao88yan
08-09-2013, 11:59 PM
i wan't to render a normalized cude with opengl ,the minimized coordinate is (0,0,0),the largest is(1,1,1),the depth test is enabled ,the value of the result color of the view plane(u,v) is the coordinate of the vertex(px,py,pz), ,and the z value of the view plane is vz, now assume the eyepostion is in eyepos,eyepos is a float3 value

so we can calculate a direction1 =normalized(u-eyepos.x,v-eyepos.y,vz-eyepos.z),and another direction2=normalized(px-eyepos.x,py-eyepos.y,pz-eyepos.z). theoretically ,direction1==direction2

now my question is in my program ,direction1<>direction2,why?
how much does the precision of the opengl rendering is?

tonyo_au
08-11-2013, 12:20 AM
You should never directly compare floats (or doubles) in any programming language. It is not uncommon for a calculation that you expect to generate 0 to actually generate 0.0000001. If you need to do an exact compare do (abs(a-b) < epsilon) where epsilon is a small float like 0.00001.