|
|
|
|
|
|
Additional info
|
|
|
|
|
Latest Forum posts
|
|
|
|
|
Ads
|
|
|
|
|
|
|
|
|
|
|
|
index¸¦ ÀÌ¿ëÇÑ vertex Àç»ç¿ë |
Áö±Ý±îÁö ¿ì¸®ÀÇ »ï°¢ÇüÀº ¿òÁ÷ÀÌ°í µÚÁýÈ÷°Å³ª ºù±Ûºù±Û µ¹±âµµ ÇÏ¸é¼ ¿ì¸®°¡ XNA¸¦ °øºÎÇϴµ¥ Å« µµ¿òÀ» ÁÖ¾ú½À´Ï´Ù. ÇÏÁö¸¸ ¾Æ½±°Ôµµ ÀÌÁ¦ ¿ì¸®ÀÇ »ï°¢Çü°ú Çì¾îÁ®¾ß ÇÒ ½Ã°£ÀÌ ¿Â °Í °°³×¿ä. ÇÏÁö¸¸ ¿ì¸®ÀÇ »ï°¢Çü(vertex)°ú ¾ÆÁÖ À̺°ÇÏ´Â °ÍÀº ¾Æ´Õ´Ï´Ù. ´Ù·ç´Â ¹æ¹ýÀÌ ´Þ¶óÁö´Â °Í»Ó, ¸ðµç °´Ã¼ÀÇ ±âº»Àº »ï°¢Çü(triangle)À̰í, »ï°¢ÇüÀº 3°³ÀÇ vertex·Î ±¸¼ºµÇ¾î ÀÖ´Ù´Â »ç½ÇÀº º¯ÇÔÀÌ ¾øÀ¸´Ï±î¿ä. ±×·³ ´ÙÀ½ ±×¸²À» »ìÆìº¾½Ã´Ù.
»ï°¢ÇüÀ» ±×¸®´Â µ¥´Â ÀÍÈ÷ ¾Ë°í ÀÖ´Â ¹Ù¿Í °°ÀÌ 3°³ÀÇ vertex°¡ ÇÊ¿äÇÕ´Ï´Ù. ±×¸²¿¡¼´Â 2°³ÀÇ »ï°¢ÇüÀÌ ±×·ÁÁ® ÀÖÀ¸´Ï 6°³ÀÇ vertex°¡ ÇÊ¿äÇϰڳ׿ä. ±×·¯³ª ±×¸²°ú °°ÀÌ ÇÑ ¸éÀÌ Á¢ÇØÀÖ´Â »ï°¢Çü 2°³¸¦ ±×¸®´Âµ¥ 6°³ÀÇ vertex¸¦ »ç¿ëÇÑ´Ù¸é ¸í¹éÇÑ ¸Þ¸ð¸® ³¶ºñ°¡ µÇ°í ¸¿´Ï´Ù.
ÇÑ ¸éÀÌ ÀÎÁ¢ÇÑ 2°³ÀÇ »ï°¢ÇüÀº 6°³°¡ ¾Æ´Ï¶ó 4°³ÀÇ vertex¸¸À¸·Îµµ Ç¥ÇöÇÒ ¼ö ÀÖ½À´Ï´Ù. ±×¸²¿¡¼ º¸ÀÌ´Â °Í°ú °°ÀÌ Ã¹¹øÂ° »ï°¢ÇüÀº 1¹ø, 2¹ø, 3¹ø vertex·Î ±×¸®°í µÎ¹øÂ° »ï°¢ÇüÀº 2¹ø, 3¹ø, 4¹ø vertex·Î ±×¸± ¼ö ÀÖ½À´Ï´Ù. ÀÌ·¯ÇÑ ¹æ¹ýÀº Áߺ¹À¸·Î ³¶ºñµÇ´Â vertex°¡ ¾ø°Ô ÇØÁÝ´Ï´Ù.
À̰ÍÀÌ index bufferÀÇ ±âº» ¹è°æÀÔ´Ï´Ù.
µÎ°³ÀÇ »ï°¢ÇüÀ» ±×¸° ±×¸²À» Çϳª ´õ »ìÆì º¾½Ã´Ù.
ÇϳªÀÇ Á¡ÀÌ Á¢ÇØÀÖÀ¸¹Ç·Î ±×¸²°ú °°Àº 2°³ÀÇ »ï°¢ÇüÀ» ±×¸®´Â µ¥´Â 5°³ÀÇ vertex°¡ ÇÊ¿äÇϰڳ׿ä. ÀÌ ±×¸²Àº ÄÚµå·Î Ç¥ÇöÇØ º¸µµ·Ï ÇսôÙ.
»õ·Î¿î Windows Game ÇÁ·ÎÁ§Æ®¸¦ »ý¼ºÇϰí ÀÌÀü tutorial·Î ºÎÅÍ ÇÊ¿äÇÑ ÆÄÀϵéÀ» º¹»çÇØ ¿É½Ã´Ù. ¹°·Ð ÄÚµå´Â ÀÌÀü tutorial¿¡¼ À̾îÁý´Ï´Ù.
¸ÕÀú Àü¿ª º¯¼ö¸¦ ¼±¾ðÇÕ´Ï´Ù.
VertexBuffer vb; IndexBuffer ib;
DirectX¸¦ ´Ù·ïºÃ´Ù¸é Àͼ÷ÇÏ°Ô ´À²¸Áú °Í ÀÔ´Ï´Ù. Àü¿ªº¯¼ö·Î vertex buffer¿Í index buffer¸¦ ¼±¾ð Çß½À´Ï´Ù.
ÀÌÁ¦ ¿ì¸®°¡ ±×¸± »ï°¢ÇüÀº ÀÌÀü±îÁöÀÇ »ï°¢Çü°ú´Â ÀüÇô ´Ù¸£±â ¶§¹®¿¡ vertex°ªµéÀ» ¹Ù²Ù¾îÁÙ Çʿ䰡 ÀÖ½À´Ï´Ù. SetupVerticesÇÔ¼ö¸¦ ´ÙÀ½°ú °°ÀÌ ¼öÁ¤ÇÕ´Ï´Ù.
private void SetupVertices() { vertices = new VertexPositionColor[5]; vertices[0].Position = new Vector3(0.0f, 0.0f, 0.0f); vertices[0].Color = Color.White; vertices[1].Position = new Vector3(5.0f, 0.0f, 0.0f); vertices[1].Color = Color.White; vertices[2].Position = new Vector3(10.0f, 0.0f, 0.0f); vertices[2].Color = Color.White; vertices[3].Position = new Vector3(5.0f, 5.0f, 0.0f); vertices[3].Color = Color.White; vertices[4].Position = new Vector3(10.0f, 5.0f, 0.0f); vertices[4].Color = Color.White; vb = new VertexBuffer(device, VertexPositionColor.SizeInBytes * 5, ResourceUsage.WriteOnly, ResourceManagementMode.Automatic); vb.SetData(vertices); }
Äڵ忡¼ º¸´Â °Í°ú °°ÀÌ ±âÁ¸ vertexµéÀÇ °ªÀÌ ¼öÁ¤µÇ°í 2°³ÀÇ vertex°¡ Ãß°¡µÇ¾ú½À´Ï´Ù. ¸¶Áö¸· µÎ ¶óÀÎÀº vertex buffer¸¦ »ý¼ºÇϰí vertices ¹è¿À» buffer¿¡ ÀúÀåÇÕ´Ï´Ù.
´ÙÀ½À¸·Î ÇÔ¼ö¸¦ Çϳª Ãß°¡ÇØ º¾½Ã´Ù. ÇÔ¼öÀÇ À̸§Àº SetupIndicesÀ̰í Á¢±ÙÀÚ´Â private, return typeÀº voidÀÔ´Ï´Ù.
private void SetupIndices() { short[] indices = new short[6]; indices[0] = 3; indices[1] = 1; indices[2] = 0; indices[3] = 4; indices[4] = 2; indices[5] = 1; ib = new IndexBuffer(device, typeof(short), 6, ResourceUsage.WriteOnly, ResourceManagementMode.Automatic); ib.SetData(indices); }
ù ¹øÂ° ¶óÀÎÀº »ï°¢Çü ¸ð¾çÀ» ±×¸®´Âµ¥ »ç¿ëµÉ index buffer¸¦ ä¿ö ³ÖÀ» ¹è¿À» »ý¼ºÇÕ´Ï´Ù. Bu¹è¿ÀÇ item ¼ø¼´Â ±×·ÁÁú ¼ø¼¸¦ ÀǹÌÇϰí, ÇØ´ç item¿¡ µé¾î°¡´Â °ªÀº ÀÌ¹Ì ¼³Á¤µÈ vertexÀÇ ¹øÈ£ÀÔ´Ï´Ù. Áï, µÎ ¹øÂ° ¶óÀÎ indices[0] = 3ÀÇ Àǹ̴ vertices[3]À» °¡Àå ¸ÕÀú ±×¸®°Ú´Ù´Â °Í ÀÔ´Ï´Ù. ±×¸®°í ¼¼ ¹øÂ° ¶óÀÎ indices[1] = 1ÀÇ Àǹ̴ ´ç¿¬È÷ µÎ ¹øÂ°·Î´Â vertices[1]À» ±×¸®°Ú´Ù´Â °ÍÀÌ µÇ°ÚÁö¿ä. Äڵ忡¼ ¹Ì·ç¾îº¸¾Æ vertices[3] ¡æ vertices[1] ¡æ vertices[0] ¡æ vertices[4] ¡æ vertices[2] ¡æ vertices[1]ÀÇ ¼ø¼·Î vertexµéÀ» ±×¸®°Ô µÉ °ÍÀÔ´Ï´Ù. ´ç¿¬ÇÑ ¾ê±âÁö¸¸ index buffer¿¡µµ ½Ã°è ¹æÇâ(clock-wise) ¼ø¼·Î vertex¹øÈ£°¡ ä¿öÁ®¾ß ÇÕ´Ï´Ù. index buffer¸¦ »ç¿ëÇÑ´Ù°í ÇØµµ °á±¹ ±×¸®°íÀÚ ÇÏ´Â °ÍÀº »ï°¢ÇüÀ̴ϱî¿ä. vertices[1]Àº µÎ ¹ø ¾²¿©¼ ¶È°°Àº vertex¸¦ µÎ ¹ø ¼±¾ðÇÏ´Â ¼ö°í¸¦ ´ú¾îÁÖ¾ú½À´Ï´Ù. index buffer ¾øÀÌ vertexµé·Î¸¸ ÀÌ »ï°¢ÇüµéÀ» ±×¸®·Á Çß´Ù¸é vertice[1]À» Àç»ç¿ëÇÏÁö ¸øÇÏ°í ¶È°°Àº ÁÂÇ¥°ªÀ» °¡Áö´Â vertexÀÎ vertice[6]À» ¼±¾ðÇØ¾ß¸¸ ÇϹǷΠ±×¸¸Å ¸Þ¸ð¸®¿Í ¼öÇà ½Ã°£¿¡¼ ¼ÕÇØ¸¦ º¸¾Ò°ÚÁö¿ä. ¸¶Áö¸·ÀÇ µÎ ¶óÀÎÀº ½ÇÁ¦·Î index buffer¸¦ »ý¼ºÇϰí buffer¿¡ ÀÌ¹Ì ¸¸µé¾î ³õÀº ¹è¿À» ä¿ö³Ö½À´Ï´Ù.
ÀÌÁ¦ InitializeÇÔ¼ö¿¡ ´ÙÀ½°ú °°ÀÌ Ãß°¡ÇսôÙ.
... SetupVertices(); SetupIndices(); ...
ÀÌÁ¦ index buffer°¡ ÁغñµÇ¾úÀ¸´Ï »ï°¢ÇüµéÀ» ±×·Áº¾½Ã´Ù. DrawÇÔ¼öÀÇ ±âÁ¸ÀÇ ¿ì¸®ÀÇ »ï°¢ÇüÀ» ±×¸®´Â Äڵ带 ´ÙÀ½ÀÇ ÄÚµå·Î ´ëüÇÕ´Ï´Ù.
device.Vertices[0].SetSource(vb, 0, VertexPositionColor.SizeInBytes); device.Indices = ib; device.VertexDeclaration = new VertexDeclaration(device, VertexPositionColor.VertexElements); device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 5, 0, 2);
ù ¹øÂ° ¶óÀΰú µÎ ¹øÂ° ¶óÀÎÀº µð¹ÙÀ̽º¿¡°Ô »ç¿ëµÉ vertex buffer¿Í index buffer°¡ ¹«¾ùÀÎÁö ¾Ë·ÁÁÖ´Â ÄÚµåÀÔ´Ï´Ù. ´ç¿¬ÇÑ ¾ê±âÀÔ´Ï´Ù¸¸, °¢ bufferµéÀ» ¼±¾ðÇÏ°í ±× ³»¿ëÀ» ä¿ö ³Ö¾ú´Ù°í ÇØµµ µð¹ÙÀ̽º¿¡°Ô °¡¸£ÃÄÁÖÁö ¾Ê´Â´Ù¸é ÀÛµ¿ÇÏÁö ¾Ê½À´Ï´Ù. ù ¹øÂ° ¶óÀÎÀº vertex buffer, µÎ ¹øÂ° ¶óÀÎÀº index buffer¸¦ ¼³Á¤ÇÏ´Â ÄÚµåÀÔ´Ï´Ù. ´Ü, vertex buffer¸¦ ÁöÁ¤ÇÒ ¶§´Â ÇÑ vertex°¡ ¸î ¹ÙÀÌÆ®ÀÎÁö °°ÀÌ ¼³Á¤ÇØÁÖ¾î¾ß Çϴµ¥ ¿î ÁÁ°Ôµµ VertexPositionColor ±¸Á¶Ã¼°¡ ÀÌ¹Ì Á¦°øÇØÁÖ°í ÀÖ½À´Ï´Ù. ¼¼ ¹øÂ° ¶óÀÎÀº Áö±Ý²¯ ÀÍÈ÷ »ç¿ëÇØ¿Â ÄÚµåÀ̱º¿ä. µð¹ÙÀ̽º¿¡°Ô vertexÀÇ ¼Ó¼ºÀ» ¾Ë·ÁÁÝ´Ï´Ù. ¸¶Áö¸·À¸·Î ³× ¹øÂ° ¶óÀÎÀº index buffer¸¦ »ç¿ëÇÏ¿© »ï°¢ÇüÀ» ±×¸®´Â ÄÚµåÀÔ´Ï´Ù. parameter·Î´Â ºÐ¸®µÈ µÎ °³ÀÇ »ï°¢ÇüÀ» ±×¸± °Í À̹ǷΠTriangleList¸¦ »ç¿ëÇß½À´Ï´Ù. ´ÙÀ½ 0Àº index bufferÀÇ ½ÃÀÛ À§Ä¡¸¦ ³ªÅ¸³À´Ï´Ù. Indices[0]ºÎÅÍ ±×¸®°Ô µÇ°Ú³×¿ä. ´ÙÀ½À¸·Î º¸¿©Áö°Ô µÉ indexÀÇ ÃÖ¼Ò °³¼ö¿Í ÃÖ´ë °³¼ö°¡ À̾îÁö°í, vertex bufferÀÇ ½ÃÀÛ À§Ä¡¸¦ ÁöÁ¤ÇÑ ÈÄ, ¸¶Áö¸·À¸·Î ±×·ÁÁö°Ô µÉ »ï°¢ÇüÀÇ °³¼ö¸¦ ÁöÁ¤ÇÕ´Ï´Ù.
ÀÌÁ¦ ´çÀåÀÌ¶óµµ »ï°¢ÇüÀ» ±×¸± ¼ö ÀÖÁö¸¸ ¾ÆÁ÷ ÇÒ ÀÏÀÌ Á¶±Ý ´õ ³²¾Ò½À´Ï´Ù. DrawÇÔ¼ö¸¦ º¸¸é ÀÌÀü tutorial¿¡¼ »ç¿ëÇÑ »ï°¢ÇüÀÇ È¸Àü ÁÂÇ¥°è¸¦ »ý¼ºÇÏ´Â Äڵ尡 ¾ÆÁ÷ ³²¾ÆÀÖ½À´Ï´Ù. ¿øÇÑ´Ù¸é ³²°ÜµÎ¾îµµ »ó°üÀº ¾øÁö¸¸ À̹ø tutorial¿¡¼´Â »ï°¢ÇüÀ» ȸÀü½ÃŰ´Â °ÍÀÌ ¸ñÀûÀÌ ¾Æ´Ï°í, ¶Ç °á°ú¸¦ È®ÀÎÇϴµ¥ ¹æÇذ¡ µÇÁö ¾Êµµ·Ï ÀÌ Äڵ带 ´ÙÀ½ÀÇ ÄÚµå·Î ´ëüÇսôÙ.
Matrix worldMatrix = Matrix.Identity;
identity matrix´Â unit matrix·Î °¡Àå ±âº»ÀÌ µÇ´Â ÁÂÇ¥°èÀÔ´Ï´Ù. ¿ùµå ÁÂÇ¥°è¸¦ identity matrix·Î ¼³Á¤ÇÏ¸é ¿ùµå ÁÂÇ¥°è°¡ ±âº» ÁÂÇ¥°è·Î reset µË´Ï´Ù.
¸¶Áö¸·À¸·Î °á°úÀÇ È®ÀÎÀ» Á»´õ ¼ö¿ùÇϰí Á¤È®ÇÏ°Ô Çϱâ À§ÇØ renderstate¸¦ Çϳª ´õ ¼³Á¤ÇϰڽÀ´Ï´Ù. DrawÇÔ¼öÀÇ Ã¹ ¶óÀο¡ ´ÙÀ½°ú °°Àº Äڵ带 Ãß°¡ÇսôÙ.
device.RenderState.FillMode = FillMode.WireFrame;
fillmode¸¦ wireframeÀ¸·Î ¼³Á¤Çϸé Áö±Ý±îÁöÀÇ »ï°¢Çüó·³ ³»ºÎ°¡ »öÀ¸·Î ä¿öÁöÁö ¾Ê°í vertexµé³¢¸®ÀÇ ¼±À¸·Î¸¸ »ï°¢ÇüÀÌ Ç¥ÇöµË´Ï´Ù.
ÀÌÁ¦ F5(µð¹ö±×)¸¦ ´·¯ °á°ú¸¦ È®ÀÎÇØº¾½Ã´Ù.
- Website design & XNA + DirectX code : Riemer Grootjans - ©2003 - 2008 Riemer Grootjans
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2007 - 2008 MVP Award DirectX - XNA
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Support this site -- any amount is welcome !
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|