Forum: DirectX styrsystem

Forum huvudsida -> Programmering -> DirectX styrsystem

Sidor: 1

Till botten

martin310 12:37 - 16:e Juni 2009 | Post #1
Medlem
Inlägg: 132


Skicka PM
Hej!

Jag håller på med ett styrsystem i DX. Eftersom världen är i 3D, och DX inte har ett färdigt system för sådant. Håller jag på med ett eget.

Här är koden:
  1. void detect_keys(void)
  2. {
  3. static float buff1 = 0.0f;
  4. static float buff2 = 0.1f;
  5. static float buff3;
  6. static BYTE keystate[256]; // create a static storage for the key-states
  7.  
  8. dinkeyboard->Acquire(); // get access if we don't have it already
  9.  
  10. dinkeyboard->GetDeviceState(256, (LPVOID)keystate); // fill keystate with values
  11.  
  12. if(keystate[DIK_W])
  13. {
  14. buff1 = tan(direction * PI / 180.0f);
  15. buff1 /= 10.0f;
  16. buff2 -= buff1;
  17. if(buff1 == 0.0f && buff2 == 0.1f)
  18. {
  19. buff1 = 0.05f;
  20. buff2 = 0.05f;
  21. }
  22. if(quater == POS_POS)
  23. {
  24. indexZcp += buff1;
  25. indexZla += buff1;
  26. indexXcp += buff2;
  27. indexXla += buff2;
  28. }
  29. else if(quater == NEG_POS)
  30. {
  31. indexZcp += buff1;
  32. indexZla += buff1;
  33. indexXcp -= buff2;
  34. indexXla -= buff2;
  35. }
  36. else if(quater == POS_NEG)
  37. {
  38. indexZcp -= buff1;
  39. indexZla -= buff1;
  40. indexXcp += buff2;
  41. indexXla += buff2;
  42. }
  43. else if(quater == NEG_NEG)
  44. {
  45. indexZcp -= buff1;
  46. indexZla -= buff1;
  47. indexXcp -= buff2;
  48. indexXla -= buff2;
  49. }
  50. }
  51. else if(keystate[DIK_S])
  52. {
  53. buff1 = tan(direction * PI / 180.0f);
  54. buff1 /= 10.0f;
  55. buff2 -= buff1;
  56. if(buff1 == 0.0f && buff2 == 0.1f)
  57. {
  58. buff1 = 0.05f;
  59. buff2 = 0.05f;
  60. }
  61. if(quater == POS_POS)
  62. {
  63. indexZcp -= buff1;
  64. indexZla -= buff1;
  65. indexXcp -= buff2;
  66. indexXla -= buff2;
  67. }
  68. else if(quater == NEG_POS)
  69. {
  70. indexZcp -= buff1;
  71. indexZla -= buff1;
  72. indexXcp += buff2;
  73. indexXla += buff2;
  74. }
  75. else if(quater == POS_NEG)
  76. {
  77. indexZcp += buff1;
  78. indexZla += buff1;
  79. indexXcp -= buff2;
  80. indexXla -= buff2;
  81. }
  82. else if(quater == NEG_NEG)
  83. {
  84. indexZcp += buff1;
  85. indexZla += buff1;
  86. indexXcp += buff2;
  87. indexXla += buff2;
  88. }
  89. }
  90. if(keystate[DIK_A])
  91. {
  92. direction -= 0.1f;
  93. indexXcp -= 0.1f;
  94. indexZcp -= 0.1f;
  95. indexXla -= 0.1f;
  96. indexZla -= 0.1f;
  97.  
  98. if(direction < -180.0f)
  99. direction = -180.0f;
  100. else if(direction > 180.0f)
  101. direction = 180.0f;
  102.  
  103. if(direction < -90.0f)
  104. quater = NEG_NEG;
  105. else if(direction > -90.0f && direction < 0.0f)
  106. quater = NEG_POS;
  107. else if(direction > 0.0f && direction < 90.0f)
  108. quater = POS_POS;
  109. else if(direction > 90.0f)
  110. quater = POS_NEG;
  111. }
  112. else if(keystate[DIK_D])
  113. {
  114. direction += 0.1f;
  115. indexXcp += 0.1f;
  116. indexZcp += 0.1f;
  117. indexXla += 0.1f;
  118. indexZla += 0.1f;
  119.  
  120. if(direction < -180.0f)
  121. direction = -180.0f;
  122. else if(direction > 180.0f)
  123. direction = 180.0f;
  124.  
  125. if(direction < -90.0f)
  126. quater = NEG_NEG;
  127. else if(direction > -90.0f && direction < 0.0f)
  128. quater = NEG_POS;
  129. else if(direction > 0.0f && direction < 90.0f)
  130. quater = POS_POS;
  131. else if(direction > 90.0f)
  132. quater = POS_NEG;
  133. }
  134. if(keystate[DIK_SPACE])
  135. {
  136. //jump();
  137. }
  138.  
  139. return;
  140. }


Felet är att man fortfarande inte ens kan backa gubbenSmiley

Säg till om ni behöver mer kod!

EDIT: Variablen direction är ett nummer mellan -180.0f och 180.0f.

-------------------------

Hjälp jorden med Granola, det är gratis och funkar på både Windows och Linux, och försämrar inte datorns prestandad!



Senast redigerad 09:51 - 17:e Juni 2009


Sidor: 1

Forum huvudsida -> Programmering -> DirectX styrsystem
Atom feed

Du får inte posta i den här tråden | Till toppen