[英]C# How to get the size of an object generated in OpenGL from Tao library
I'm building an app that can show 3D view of STL files in a SimpleOpenGlControl using TAO.FreeGlut and TAO.OpenGL referencies.我正在构建一个应用程序,它可以使用 TAO.FreeGlut 和 TAO.OpenGL 引用在 SimpleOpenGlControl 中显示 STL 文件的 3D 视图。 I need to get the size of the displayed 3D model for some feature but can't find it.
我需要获取某些功能的显示 3D 模型的大小,但找不到。 How can I get the size of the displayed object?
如何获取显示对象的大小?
I have found a basic project that can display a STL file here https://github.com/batu92k/STL-Viewer我在这里找到了一个可以显示 STL 文件的基本项目https://github.com/batu92k/STL-Viewer
But it has very little explanation and comments are in Turk...但它几乎没有解释,评论是在土耳其语中...
I have also find some information here https://www.codeproject.com/Articles/23778/OpenGL-3D-Navigation2-With-Tao-and-C-Tao-OpenGL-Ta我也在这里找到了一些信息https://www.codeproject.com/Articles/23778/OpenGL-3D-Navigation2-With-Tao-and-C-Tao-OpenGL-Ta
But again, ot much explaination about size.但同样,没有太多关于大小的解释。
OpenGLMonitor Code: OpenGL监视器代码:
Batu_GL glController;
Batu_GL.VAO_TRIANGLES modelVAO;
BaseConfig baseConfig = new BaseConfig();
int scale = 30;
int rotationZ = 0;
public OpenGLMonitor()
{
/* dot/comma selection for floating point numbers */
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
InitializeComponent();
glController = new Batu_GL();
glController.initialize(monitor);
glController.glInit(monitor, Batu_GL.Ortho_Mode.CENTER);
rotationZ = baseConfig.rotationZ;
}
public void Draw()
{
glController.glDinamik(monitor, Batu_GL.Ortho_Mode.CENTER);
//--------------------------------------------
Gl.glEnable(Gl.GL_LIGHTING); // Activer l'éclairage
Gl.glEnable(Gl.GL_LIGHT1);
//--------------------------------------------
//--Lumiere 1
Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_AMBIENT_AND_DIFFUSE, baseConfig.light_1); // Le type et le nombre de feux sont déterminés"
Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_SPECULAR, baseConfig.specular); // La réflexion est sélectionnée parmi les types d'éclairage. Le tableau spéculaire est utilisé pour déterminer les caractéristiques de la lumière de réflexion.
Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_POSITION, baseConfig.lightPos); // La position de la lumière "0" provient du tableau "lightpos"
Gl.glEnable(Gl.GL_LIGHT0); // La lumière "0" est activée
//-------------------------------------------
//--Lumiere 2
Gl.glLightfv(Gl.GL_LIGHT1, Gl.GL_AMBIENT_AND_DIFFUSE, baseConfig.light_1);
Gl.glLightfv(Gl.GL_LIGHT1, Gl.GL_SPECULAR, baseConfig.specular);
Gl.glLightfv(Gl.GL_LIGHT1, Gl.GL_POSITION, baseConfig.lightPos2);
Gl.glEnable(Gl.GL_LIGHT1);
//-------------------------------------------
Gl.glEnable(Gl.GL_COLOR_MATERIAL); // Activation du matériau de couleur de la pièce
Gl.glColorMaterial(Gl.GL_FRONT, Gl.GL_AMBIENT_AND_DIFFUSE);
Gl.glMaterialfv(Gl.GL_FRONT, Gl.GL_SPECULAR, baseConfig.specref);
Gl.glMateriali(Gl.GL_FRONT, Gl.GL_SHININESS, 15); // Ajuster le niveau de luminosité (bonne réflexion de "1")
Gl.glEnable(Gl.GL_NORMALIZE); // Adoucissement de la transmission de la lumière
//-------------------------------------------
Gl.glRotatef(baseConfig.rotationX, -1.0f, 0.0f, 0.0f);
Gl.glRotatef(baseConfig.rotationZ, 0.0f, 0.0f, 1.0f);
rotationZ++;
rotationZ = rotationZ % 360;
Gl.glTranslatef(0.0f, 0.0f, -150.0f);
modelVAO.Draw();
monitor.SwapBuffers();
}
private void fileSelectBt_Click(object sender, EventArgs e)
{
OpenFileDialog stldosyaSec = new OpenFileDialog();
stldosyaSec.Filter = "STL Files|*.stl;*.txt;";
scale = (int)(0.05 * monitor.Width);
if (stldosyaSec.ShowDialog() == DialogResult.OK)
{
lblFilename.Text = stldosyaSec.SafeFileName;
STLReader stlReader = new STLReader(stldosyaSec.FileName);
TriangleMesh[] meshArray = stlReader.ReadFile();
modelVAO = new Batu_GL.VAO_TRIANGLES();
STLExport stlExporter = new STLExport();
modelVAO.parameterArray = stlExporter.Get_Mesh_Vertices(meshArray);
modelVAO.normalArray = stlExporter.Get_Mesh_Normals(meshArray);
modelVAO.color = Color.AntiqueWhite;
modelVAO.scale = new float[3] { scale, scale, scale };
if (!stlReader.Get_Process_Error())
{
//rotationX = 0;
drawTimer.Enabled = true;
//fileSelectBt.BackColor = Color.DeepSkyBlue;
}
else
{
drawTimer.Enabled = false;
//fileSelectBt.BackColor = Color.Tomato;
/* if there is an error, deinitialize the gl monitor to clear the screen */
glController.glInit(monitor, Batu_GL.Ortho_Mode.CENTER);
monitor.SwapBuffers();
}
}
else
{
// intentionally left blank
}
}
private void drawTimer_Tick(object sender, EventArgs e)
{
Draw();
}
} } } }
private void timer1_Tick(object sender, EventArgs e)
{
label1.Text = minPos.x + "";
label2.Text = minPos.y + "";
label3.Text = minPos.z + "";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.