翻譯|使用教程|編輯:況魚杰|2019-09-17 10:29:42.263|閱讀 251 次
概述:本系列教程整理了VectorDraw Developer Framework(VDF)最常見問題,教程整理的很齊全,非常適合新手學(xué)習(xí),本節(jié)教程將會(huì)介紹如何在3D視圖中檢查對(duì)象是否隱藏在另一個(gè)對(duì)象中。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
VectorDraw Developer Framework(VDF)是一個(gè)用于應(yīng)用程序可視化的圖形引擎庫。有了VDF提供的功能,您可以輕松地創(chuàng)建、編輯、管理、輸出、輸入和打印2D和3D圖形文件。
VectorDraw Developer Framework試用版下載
問:
如何在3D視圖中檢查對(duì)象是否隱藏在另一個(gè)對(duì)象中?例如,我有兩個(gè)多面體,一個(gè)是z = 100的大面積,另一個(gè)是z = 0的面,并且視圖是只有一個(gè)多面體是可見的,另一個(gè)多面體是在大面體后面,并且是完全看不見的在屏幕上。
答:
你需要一些OpenGL代碼來檢查一個(gè)對(duì)象是否落后于另一個(gè)對(duì)象(不可見)。
您需要的代碼如下:
vdPolyface purple; // this is the polyface to check if is behind the green polyface void test() { // just create the objects vdPolyface pf1 = new vdPolyface(doc); pf1.CreateBox(new gPoint(0, 0), 1, 1, 1, 0); pf1.PenColor = new vdColor(Color.Purple); doc.Model.Entities.AddItem(pf1); purple = pf1; // this is the polyface to check if is behind the green polyface vdPolyface pf2 = new vdPolyface(doc); pf2.CreateBox(new gPoint(-2, 2), 4, 4, 4, 0); pf2.PenColor = new vdColor(Color.Green); doc.Model.Entities.AddItem(pf2); // this is the green polyface that hides the purple one doc.RenderMode = vdRender.Mode.Shade; //doc.CommandAction.View3D("VINW"); doc.CommandAction.View3D("VINE"); } bool IsObjectVisible = false; void test1() // this is the method that checks the “visibility” using the OnDrawAfter event { IsObjectVisible = false; doc.OnDrawAfter += new vdDocument.DrawAfterEventHandler(TestObjectVisibility_OnDrawAfter); doc.RenderMode = vdRender.Mode.Shade; doc.Redraw(true); doc.OnDrawAfter -= new vdDocument.DrawAfterEventHandler(TestObjectVisibility_OnDrawAfter); MessageBox.Show(IsObjectVisible ? "Object is visible" : "Object is not visible"); } void TestObjectVisibility_OnDrawAfter(object sender, vdRender render) { double[] _modelMatrix = new double[16], _projMatrix = new double[16]; int[] _viewport = new int[4]; double pwinx = 0.0, pwiny = 0.0, pwinz = 0.0; //GET the active world to view and view to pixel matrixes VectorDraw.Render.OpenGL.OpenGLImports.glGetDoublev(VectorDraw.Render.OpenGL.OpenGLImports.Parameters.GL_PROJECTION_MATRIX, _projMatrix); VectorDraw.Render.OpenGL.OpenGLImports.glGetDoublev(VectorDraw.Render.OpenGL.OpenGLImports.Parameters.GL_MODELVIEW_MATRIX, _modelMatrix); VectorDraw.Render.OpenGL.OpenGLImports.glGetIntegerv(VectorDraw.Render.OpenGL.OpenGLImports.Parameters.GL_VIEWPORT, _viewport); Rectangle winrc = new Rectangle(_viewport[0], _viewport[1], _viewport[2], _viewport[3]); foreach (gPoint pt in purple.VertexList) { VectorDraw.Render.OpenGL.OpenGLImports.gluProject(pt.x, pt.y, pt.z, _modelMatrix, _projMatrix, _viewport, ref pwinx, ref pwiny, ref pwinz); Point winPt = new Point((int)pwinx, (int)pwiny); if (!winrc.Contains(winPt)) continue; //Get the existing depth in previous calculated pixel double depth = VectorDraw.Render.OpenGL.OpenGLImports.glReadPixelDepth((int)(pwinx), (int)(pwiny)); //the pt is visible if the pwinz is smaller than the existing(it is closest to eye) double def = pwinz - depth; if (def <= 0.000001) { IsObjectVisible = true; break; } } }
相關(guān)資料推薦:
VectorDraw Developer Framework(VDF)示例
如果您對(duì)想要購買正版授權(quán)VectorDraw Developer Framework(VDF),可以聯(lián)系咨詢相關(guān)問題。
關(guān)注慧聚IT微信公眾號(hào) ???,了解產(chǎn)品的最新動(dòng)態(tài)及最新資訊。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自: