vb.net - OpenGL Fitting Viewer to Object (written in VB .NET but C# answers will work too) -
background
i attempting make simple cad viewer. have chosen start .stl files which, of don't know, bunch of triangles form part on screen. when outputting cad software, can output text file version if stl. lists of points:
solid facet normal -7.8662990e-02 +8.3699658e-01 -5.4152455e-01 outer loop vertex +3.3529416e+03 -3.7456115e+02 +8.5293264e+02 vertex +3.3530518e+03 -3.7467327e+02 +8.5274334e+02 vertex +3.3527449e+03 -3.7467680e+02 +8.5278246e+02 endloop endfacet facet normal -1.7741169e-02 +8.8266388e-01 -4.6966979e-01 outer loop vertex +3.3527449e+03 -3.7467680e+02 +8.5278246e+02 vertex +3.3522178e+03 -3.7464933e+02 +8.5285399e+02 vertex +3.3524442e+03 -3.7463108e+02 +8.5287975e+02 endloop endfacet
and forth.. can loop through points , create triangles:
dim integer = 0 until + 2 >= listview1.items.count gl.glpushmatrix() gl.glbegin(gl.gl_triangles) gl.glcolor3f(1.0, 0.0, 0.0) gl.glvertex3f(convert.tosingle(listview1.items.item(i).subitems(0).text), convert.tosingle(listview1.items.item(i).subitems(1).text), convert.tosingle(listview1.items.item(i).subitems(2).text)) gl.glcolor3f(1.0, 0.0, 0.0) gl.glvertex3f(convert.tosingle(listview1.items.item(i + 1).subitems(0).text), convert.tosingle(listview1.items.item(i + 1).subitems(1).text), convert.tosingle(listview1.items.item(i + 1).subitems(2).text)) gl.glcolor3f(1.0, 0.0, 0.0) gl.glvertex3f(convert.tosingle(listview1.items.item(i + 2).subitems(0).text), convert.tosingle(listview1.items.item(i + 1).subitems(1).text), convert.tosingle(listview1.items.item(i + 2).subitems(2).text)) gl.glend() gl.glpopmatrix() = + 3 loop
problem
my method seems work when manually put in triangles, when doing shown above, can't find are. believe 1 of 2 reasons. either world not big enough locations specified since in range of (x=3352, y=-374, z=852), when starting off viewing (x=0, y=0, z=0),
how know, or change, size of world if possibly problem?
here use setting world far:
glctrl.initializecontexts() gl.glclearcolor(0, 0, 0, 0) gl.glmatrixmode(gl.gl_projection) gl.glloadidentity() gl.glortho(-1, 1, -1, 1, -1, 1) gl.glmatrixmode(gl.gl_modelview) gl.glloadidentity() glctrl.focus() 'start gameloop gameloop()
if seems not problem, may not going triangles correctly? go them using translate:
gl.gltranslatef(view_location.x, view_location.y, view_location.z)
and use coordinates close ones listed above, , try zoom , pan still can't find anything.
i answer own question. answer gl.gltranslatef inverse thought. solution is:
gl.gltranslatef(-view_location.x, -view_location.y, -view_location.z)
Comments
Post a Comment