XNA for C#
DirectX 9 for C#
DirectX 9 for C++
DirectX 9 for VB
Forum
   August 27: 2D-7: Writing text
My Book: Out Now!
      
       Go to section on this site

Additional info


Latest Forum posts

 DX vs XNA vs OGL
  Posted by: Rich_Zap
  When: 28/08/2008 at 10:54:39

 understanding of SetUpIndices
  Posted by: YoYoFreakCJ
  When: 28/08/2008 at 05:51:04

 billboard does not rotate after scaling
  Posted by: kigunda
  When: 28/08/2008 at 04:55:29

 exception error
  Posted by: Rich_Zap
  When: 28/08/2008 at 03:34:29

 exception error
  Posted by: besi
  When: 28/08/2008 at 00:14:11

 Having trouble with effect file
  Posted by: Anonymous
  When: 27/08/2008 at 22:15:15

 Polygon Clipping for Octree
  Posted by: lbmurali
  When: 27/08/2008 at 18:13:55

 understanding of SetUpIndices
  Posted by: vToMy
  When: 27/08/2008 at 18:05:45

 A Typo with loading the Font
  Posted by: riemer
  When: 27/08/2008 at 15:26:43

 mistake found
  Posted by: riemer
  When: 27/08/2008 at 15:22:31


Ads

ÁöÇüÀÇ Normal¿¡ ´ëÇÑ Á÷°üÀûÀÎ Á¢±Ù

ÀÌÁ¦ ¿ì¸®ÀÇ ÁöÇüÀÇ ¸ðµç vertexµé¿¡ Normal vector¸¦ Àû¿ëÇÏ¿© ±×·¡ÇÈ Ä«µå°¡ Á¶¸íÀ» °è»êÇÒ ¼ö ÀÖµµ·Ï ÇØ º¸°Ú½À´Ï´Ù. À̹ø tutorialÀ» ÅëÇØ Á¶¸í ¼³Á¤¿¡ ´ëÇØ ½±°Ô ÀÌÇØÇÏ°í ½±°Ô ±¸ÇöÇÏ´Â ¹æ¹ýÀ» ãÀ» ¼ö ÀÖÀ» °Í ÀÔ´Ï´Ù. »ç½Ç, ¼öÇÐÀûÀ¸·Î 100% ¿Ïº®ÇÏÁö´Â ¾ÊÁö¸¸ ºñ±³Àû ÀûÀº °è»êÀ¸·Î ºñ±³Àû ±×·²µíÇÑ Á¶¸íÀÌ Ç¥ÇöÇÒ ¼ö ÀÖ´Ù´Â µ¥ ¸¸Á·Çϵµ·Ï ÇսôÙ. Á» ´õ ¼öÇÐÀûÀÎ ³»¿ëÀº ´ÙÀ½ ±âȸ¿¡ »ìÆìº¸µµ·Ï ÇϰڽÀ´Ï´Ù.

¿©±â¿¡ ±âÃÊÀûÀÎ ¼³¸íÀ» À§ÇØ Reimer¾¾°¡ ¸¸µç ±×¸²ÀÌ ÀÖ½À´Ï´Ù. 2°³ÀÇ ÆÄ¶õ»ö ¼±Àº ¿ì¸®ÀÇ ÁöÇü ¾È¿¡ Á¸ÀçÇÏ´Â ÀÓÀÇÀÇ °æ°è¼±(Grid) ÀÔ´Ï´Ù. ¿ì¸®°¡ ã°íÀÚ ÇÏ´Â °ÍÀº ºÓÀº»ö ¼±À¸·Î Ç¥ÇöµÈ µÎ ÆÄ¶õ»ö ¼±µéÀÌ °øÀ¯ÇÏ´Â Á¡(Point)ÀÇ Normal vectorÀÔ´Ï´Ù. ±×¸®°í ÇÏ´Ü¿¡ º¸ÀÌ´Â °ËÀº ¼±Àº Á¡µé(Points)»çÀÌÀÇ ´ÜÀ§ °Å¸® ÀÔ´Ï´Ù.

ÀÌ·¸°Ô »ý°¢ÇØ º¾½Ã´Ù. ¾îÂ÷ÇÇ 2°³ÀÇ ÆÄ¶õ»ö ¼±Àº XÁÂÇ¥¿Í YÁÂÇ¥·Î½á Á¸ÀçÇϱ⠶§¹®¿¡ ¾ðÁ¦³ª Á÷°¢ÀÔ´Ï´Ù. ZÃà ÁÂÇ¥°ªÀÌ ¾ø´Â »óŶó¸é ÀÌ °æ°è¼±(Grid)´Â ÆòÆòÇÏ°Ô ´©¿öÀÖ´Â °Íó·³ º¸ÀÏ °ÍÀ̰í, Normal vector´Â ¼öÁ÷À¸·Î À§ÂÊÀ» ÇâÇØ ÀÖ°ÚÁö¿ä. ¸¸¾à ±×¸²°ú °°ÀÌ ÃÊ·Ï»ö ¼±ÀÇ ±æÀ̸¸Å­ ZÃà ÁÂÇ¥°ª(³ôÀ̰ª)ÀÌ ÁÖ¾îÁø´Ù¸é ´ç¿¬È÷ °æ°è¼±(Grid)´Â ±×¸¸Å­ ±â¿ï¾îÁö°Ô µÉ °ÍÀÔ´Ï´Ù. ±â¿ï¾îÁö´Â Á¤µµ´Â ¿ÞÂÊ Á¡(Point)¿¡ ÁÖ¾îÁø ³ôÀÌ¿Í ¿À¸¥ÂÊ Á¡(Point)¿¡ ÁÖ¾îÁø ³ôÀÌÀÇ Â÷ÀÌÀÇ Àý¹ÝÀÔ´Ï´Ù.

µû¶ó¼­, µÎ °æ°è¼±(Grid)°¡ °øÀ¯ÇÏ´Â Á¡(Point)¿¡¼­ ÃÊ·Ï»ö ¼±ÀÇ ±æÀÌÀÇ Àý¹Ý°ú ¼öÁ÷ÇÏ´Â °ËÀº»ö ¼± - Á¡µé(Points)ÀÇ ´ÜÀ§ ±æÀ̸¦ ³»ÀûÀÌ ¹Ù·Î ¿ì¸®¿¡°Ô ÇÊ¿äÇÑ Normal vector°¡ µË´Ï´Ù. Reimer¾¾°¡ ¸¸µç ±×¸²°ú ºñ±³ÇØ º¾½Ã´Ù.



¼³¸íÀÌ ±æ¾î Á³Áö¸¸, ÄÚµå·Î ±¸ÇöÇϱⰡ ¾î·Á¿î ³»¿ëÀº ¾Æ´Õ´Ï´Ù. ÀÌÁ¦ »õ Windows Game ÇÁ·ÎÁ§Æ®¸¦ »ý¼ºÇϰí Adding Color ÇÁ·ÎÁ§Æ®¿¡¼­ ¿ì¸®ÀÇ ÁöÇüÀ» °¡Á®¿É½Ã´Ù.

°¡Àå ¸ÕÀú Lighting Basic¿¡¼­ »ç¿ëÇß´ø VertexPositionNormalColored ±¸Á¶Ã¼¸¦ ¼±¾ðÇØ ÁÖ¾î¾ß ÇϰÚÁö¿ä

 public struct VertexPositionNormalColored
 {
     public Vector3 Position;
     public Color Color;
     public Vector3 Normal;
 
     public static int SizeInBytes = 7 * 4;
     public static VertexElement[] VertexElements = new VertexElement[]
     {
         new VertexElement( 0, 0, VertexElementFormat.Vector3, VertexElementMethod.Default, VertexElementUsage.Position, 0 ),
         new VertexElement( 0, sizeof(float) * 3, VertexElementFormat.Color, VertexElementMethod.Default, VertexElementUsage.Color, 0 ),
         new VertexElement( 0, sizeof(float) * 4, VertexElementFormat.Vector3, VertexElementMethod.Default, VertexElementUsage.Normal, 0 ),
     };
 }

Àü¿ª º¯¼ö verticesµµ ÀçÁ¤ÀÇ ÇØÁݽôÙ.

 VertexPositionNormalColored[] vertices;

ÀÌÁ¦ »õ·Î Á¤ÀÇµÈ vertexµéÀº Normal vector¸¦ °¡Áú ¼ö ÀÖÀ¸¹Ç·Î SetupVerticesÇÔ¼ö¿¡ ´ÙÀ½°ú °°ÀÌ Normal vector¸¦ ¼³Á¤ÇÏ´Â Äڵ带 Ãß°¡ÇØ ÁݽôÙ.

 for (int x = 1; x < WIDTH-1; x++)
 {
     for (int y = 1; y < HEIGHT-1; y++)
     {
         Vector3 normX = new Vector3((vertices[x - 1 + y * WIDTH].Position.Z - vertices[x + 1 + y * WIDTH].Position.Z) / 2, 0, 1);
         Vector3 normY = new Vector3(0, (vertices[x + (y - 1) * WIDTH].Position.Z - vertices[x + (y + 1) * WIDTH].Position.Z) / 2, 1);
         vertices[x + y * WIDTH].Normal = normX + normY;
         vertices[x + y * WIDTH].Normal.Normalize();
     }
 }

ÁöÇüÀÇ ¿Ü°û¼±À» Á¦¿ÜÇÏ°í ¸ÕÀú XÃà ¹æÇâÀÇ NormalÀ» °è»êÇϰí YÃà ¹æÇâÀ» NormalÀ» °è»êÇÏ¿© ÀÌ µÎ Normal vector¸¦ ÇÕÃÄ ÁöÇüÀÇ vertex°¡ °¡Áö´Â Normal vector¸¦ ±¸ÇÕ´Ï´Ù.

¶ÇÇÑ ¿Ü°û¼± ºÎºÐÀÇ vertexµéÀÇ Normal vector ¶ÇÇÑ ÇÊ¿äÇϹǷΠÁöÇüÀÇ °¢ vertexÀÇ °ªÀ» ÁöÁ¤ÇÏ´Â Loop¿¡¼­ ¸ðµç vertexµéÀÇ Normal vectorÀ» ÃʱâÈ­ ½ÃÄÑÁÖµµ·Ï ÇսôÙ.

 vertices[x + y * WIDTH].Position = new Vector3(x, y, heightData[x, y]);
 vertices[x + y * WIDTH].Normal = new Vector3(0, 0, 1);

ÀÌÁ¦ Normal vectorÀÇ ¼³Á¤Àº ¸ðµÎ ³¡³µ½À´Ï´Ù. ÇÏÁö¸¸ ¾ÆÁ÷ ÇÒ ÀÏÀÌ ¾à°£ ´õ ³²¾ÆÀֳ׿ä. ÀÌÀü tutorial°ú´Â ´Ù¸£°Ô ¿ì¸®ÀÇ ÁöÇü¿¡¼­´Â Indexbuffer¸¦ »ç¿ëÇϰí Àֱ⠶§¹®¿¡ ´õ ¸¹Àº vertexµéÀ» ´ãÀ» ¼ö ÀÖµµ·Ï VertexbufferÀÇ Å©±â¸¦ Å©°Ô Àâ¾ÆÁÖ¾î¾ß ÇÕ´Ï´Ù.

SetupVerticesÇÔ¼ö¿¡¼­ Vertexbuffer¸¦ »ý¼ºÇÏ´Â Äڵ带 ´ÙÀ½°ú °°ÀÌ ¼öÁ¤ÇսôÙ.

 vb = new VertexBuffer(device, VertexPositionNormalColored.SizeInBytes * WIDTH*HEIGHT, ResourceUsage.WriteOnly, ResourceManagementMode.Automatic);
 vb.SetData(vertices);

±×¸®°í DrawÇÔ¼ö¿¡ ÀÌÀü tutorial°ú °°ÀÌ Á¶¸íÀ» ¼³Á¤ÇØ ÁݽôÙ.

 effect.Parameters["xEnableLighting"].SetValue(true);
 effect.Parameters["xLightDirection"].SetValue(new Vector3(0.5f, 0.5f, -1));

¸¶Áö¸·À¸·Î µð¹ÙÀ̽º¿¡°Ô ¿ì¸®°¡ »ç¿ëÇÏ´Â vertexµéÀÇ Çü½ÄÀÌ VertexPositionNormalColoredÀÓÀ» ¾Ë·ÁÁݽôÙ.

 device.Vertices[0].SetSource(vb, 0, VertexPositionNormalColored.SizeInBytes);
 device.Indices = ib;
 device.VertexDeclaration = new VertexDeclaration(device, VertexPositionNormalColored.VertexElements);
 device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, WIDTH*HEIGHT, 0, (WIDTH-1)*(HEIGHT-1)*2);

ÀÌÁ¦ F5(µð¹ö±×)۸¦ ´­·¯ ½ÇÇàÇϸé Á¶¸íÀÌ ¼³Á¤µÈ ¿ì¸®ÀÇ ÁöÇüÀ» È®ÀÎÇÒ ¼ö ÀÖ½À´Ï´Ù.






Google
 
Webwww.riemers.net


If you appreciate the amount of time I spend creating and updating
these pages, feel free to donate -- any amount is welcome !



- Website design & XNA + DirectX code : Riemer Grootjans -
©2003 - 2008 Riemer Grootjans
Translations

This site in English
This site in Korean
This site in Czech

Microsoft MVP Award



2007 - 2008 MVP Award
DirectX - XNA

Contents

[Tutorials]
[XNA in C#]
Series 1: ÁöÇü
XNAÀÇ ½ÃÀÛ
ÀÌÆåÆ® ÆÄÀÏ
ù ¹øÂ° »ï°¢Çü
¿ùµå ÁÂÇ¥°è
ȸÀü, À§Ä¡ º¯È¯
À妽º
ÁöÇü »ý¼ºÀÇ ±âº»
ÆÄÀϷκÎÅÍ ÁöÇü »ý¼º
Űº¸µå ÀÔ·Â
[tut10]
[tut11]
[tut12]
[tut13]
-- Expand all --


Thank you!

Support this site --
any amount is welcome !

Stay up-to-date

I don't have the time to keep a News section, so stay informed about the updates by clicking on this RSS file!