0
\$\begingroup\$

I'm very new to the world of Computer Graphics, and I'm struggling to find resources to help me understand how to draw my mesh (I have loaded everything into vertex and index buffers), I am not using a 3D API, instead I am just using C# and a 2D Graphics canvas to draw my mesh.

Everything is currently loading, but I have suspicions that I am reading my faces in as quads instead of triangles, could somebody A) Clarify whether I am draw a quad instead of a triangle B) If I am drawing quads, how do I draw a triangle? This has been a headache for me for a few hours...

for (int i = 0; i < m_numFaces; i++)
{
     Face face = m_meshData[i];

     // Draw the face
     for (int j = 0; j < 3; j++)
     {
                m_graphicsContext.DrawLine(m_pen,
                     // Get the X,Y points of this face 
                     (int)face.GetPointAtIndex(j).points[0],
                     (int)face.GetPointAtIndex(j).points[1],
                     (int)face.GetPointAtIndex(j + 1).points[0],
                     (int)face.GetPointAtIndex(j + 1).points[1]);
     }
                // Draw from first point back to last line
                m_graphicsContext.DrawLine(m_pen,
                     (int)face.GetPointAtIndex(2).points[0],
                     (int)face.GetPointAtIndex(2).points[1],
                     (int)face.GetPointAtIndex(0).points[0],
                     (int)face.GetPointAtIndex(0).points[1]);
}
\$\endgroup\$
  • \$\begingroup\$ Is Face imported from Solidworks? \$\endgroup\$ – Jon Apr 10 '15 at 5:49
  • \$\begingroup\$ No, it's all written by myself - Face is simply an array of vectors with some code to perform transformations. \$\endgroup\$ – Alesso Apr 10 '15 at 13:22
  • \$\begingroup\$ Comment the code you've posted and try drawing a line with explicit coordinates (0,0) and (100,100). Does it appear on screen? \$\endgroup\$ – Jon Apr 10 '15 at 20:20
1
\$\begingroup\$

You're currently drawing the following lines:

  • From point 0 to point 1.
  • From point 1 to point 2.
  • From point 2 to point 3 (wrong!).
  • From point 2 to point 0.

j < 3 should be j < 2.

\$\endgroup\$
  • \$\begingroup\$ Do I need the second draw block? Or just the first? \$\endgroup\$ – Alesso Apr 9 '15 at 22:30
  • \$\begingroup\$ @Alesso Your loop draws the first three (which should be the first two). Your draw call outside the loop draws the last one. \$\endgroup\$ – user253751 Apr 9 '15 at 22:32
  • \$\begingroup\$ I see - so I only draw 0->1, 1->2 then 2->0 outside of the loop? \$\endgroup\$ – Alesso Apr 9 '15 at 22:33
  • \$\begingroup\$ I updated my code to be j < 2 the mesh that has been drawn still looks the same as it did before. Why is this? \$\endgroup\$ – Alesso Apr 9 '15 at 22:37
  • \$\begingroup\$ @Alesso Then maybe the problem you're seeing isn't the one I told you about; without more information I can't really help you. \$\endgroup\$ – user253751 Apr 10 '15 at 0:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.