Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

215 lines
6.0 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: nstate.cxx
  3. *
  4. * NORMAL_STATE
  5. *
  6. * Copyright (c) 1995 Microsoft Corporation
  7. *
  8. \**************************************************************************/
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <stdlib.h>
  12. #include <math.h>
  13. #include <sys/types.h>
  14. #include <sys/timeb.h>
  15. #include <time.h>
  16. #include <windows.h>
  17. #include "sspipes.h"
  18. #include "nstate.h"
  19. #include "objects.h"
  20. #include "dialog.h"
  21. /******************************Public*Routine******************************\
  22. * NORMAL_STATE constructor
  23. *
  24. * Jul. 95 [marcfo]
  25. *
  26. \**************************************************************************/
  27. NORMAL_STATE::NORMAL_STATE( STATE *pState )
  28. {
  29. // init joint types from dialog settings
  30. bCycleJointStyles = 0;
  31. switch( ulJointType ) {
  32. case JOINT_ELBOW:
  33. jointStyle = ELBOWS;
  34. break;
  35. case JOINT_BALL:
  36. jointStyle = BALLS;
  37. break;
  38. case JOINT_MIXED:
  39. jointStyle = EITHER;
  40. break;
  41. case JOINT_CYCLE:
  42. bCycleJointStyles = 1;
  43. jointStyle = EITHER;
  44. break;
  45. default:
  46. break;
  47. }
  48. // Build the objects
  49. BuildObjects( pState->radius, pState->view.divSize, pState->nSlices,
  50. pState->bTexture, &pState->texRep[0] );
  51. }
  52. /******************************Public*Routine******************************\
  53. * NORMAL_STATE destructor
  54. *
  55. * Some of the objects are always created, so don't have to check if they
  56. * exist. Others may be NULL.
  57. \**************************************************************************/
  58. NORMAL_STATE::~NORMAL_STATE( )
  59. {
  60. delete shortPipe;
  61. delete longPipe;
  62. delete ballCap;
  63. for( int i = 0; i < 4; i ++ ) {
  64. delete elbows[i];
  65. if( ballJoints[i] )
  66. delete ballJoints[i];
  67. }
  68. if( bigBall )
  69. delete bigBall;
  70. }
  71. /**************************************************************************\
  72. * BuildObjects
  73. *
  74. * - Build all the pipe primitives
  75. * - Different prims are built based on bTexture flag
  76. *
  77. \**************************************************************************/
  78. void
  79. NORMAL_STATE::BuildObjects( float radius, float divSize, int nSlices,
  80. BOOL bTexture, IPOINT2D *texRep )
  81. {
  82. OBJECT_BUILD_INFO *pBuildInfo = new OBJECT_BUILD_INFO;
  83. pBuildInfo->radius = radius;
  84. pBuildInfo->divSize = divSize;
  85. pBuildInfo->nSlices = nSlices;
  86. pBuildInfo->bTexture = bTexture;
  87. if( bTexture ) {
  88. pBuildInfo->texRep = texRep;
  89. // Calc s texture intersection values
  90. float s_max = (float) texRep->y;
  91. float s_trans = s_max * 2.0f * radius / divSize;
  92. // Build short and long pipes
  93. shortPipe = new PIPE_OBJECT( pBuildInfo, divSize - 2*radius,
  94. s_trans, s_max );
  95. longPipe = new PIPE_OBJECT( pBuildInfo, divSize, 0.0f, s_max );
  96. // Build elbow and ball joints
  97. for( int i = 0; i < 4; i ++ ) {
  98. elbows[i] = new ELBOW_OBJECT( pBuildInfo, i, 0.0f, s_trans );
  99. ballJoints[i] = new BALLJOINT_OBJECT( pBuildInfo, i, 0.0f, s_trans );
  100. }
  101. bigBall = NULL;
  102. // Build end cap
  103. float s_start = - texRep->x * (ROOT_TWO - 1.0f) * radius / divSize;
  104. float s_end = texRep->x * (2.0f + (ROOT_TWO - 1.0f)) * radius / divSize;
  105. // calc compensation value, to prevent negative s coords
  106. float comp_s = (int) ( - s_start ) + 1.0f;
  107. s_start += comp_s;
  108. s_end += comp_s;
  109. ballCap = new SPHERE_OBJECT( pBuildInfo, ROOT_TWO*radius, s_start, s_end );
  110. } else {
  111. // Build pipes, elbows
  112. shortPipe = new PIPE_OBJECT( pBuildInfo, divSize - 2*radius );
  113. longPipe = new PIPE_OBJECT( pBuildInfo, divSize );
  114. for( int i = 0; i < 4; i ++ ) {
  115. elbows[i] = new ELBOW_OBJECT( pBuildInfo, i );
  116. ballJoints[i] = NULL;
  117. }
  118. // Build just one ball joint when not texturing. It is slightly
  119. // larger than standard ball joint, to prevent any pipe edges from
  120. // 'sticking' out of the ball.
  121. bigBall = new SPHERE_OBJECT( pBuildInfo,
  122. ROOT_TWO*radius / ((float) cos(PI/nSlices)) );
  123. // build end cap
  124. ballCap = new SPHERE_OBJECT( pBuildInfo, ROOT_TWO*radius );
  125. }
  126. }
  127. /**************************************************************************\
  128. * Reset
  129. *
  130. * Reset frame attributes for normal pipes.
  131. *
  132. \**************************************************************************/
  133. void
  134. NORMAL_STATE::Reset( )
  135. {
  136. // Set the joint style
  137. if( bCycleJointStyles ) {
  138. if( ++(jointStyle) >= NUM_JOINT_STYLES )
  139. jointStyle = 0;
  140. }
  141. }
  142. #if 0
  143. /**************************************************************************\
  144. * GetMaxPipesPerFrame
  145. *
  146. \**************************************************************************/
  147. int
  148. NORMAL_STATE::GetMaxPipesPerFrame( )
  149. {
  150. if( bTexture )
  151. return NORMAL_TEX_PIPE_COUNT;
  152. else
  153. return NORMAL_PIPE_COUNT;
  154. }
  155. #endif
  156. /*-----------------------------------------------------------------------
  157. | |
  158. | ChooseJointType |
  159. | - Decides which type of joint to draw |
  160. | |
  161. -----------------------------------------------------------------------*/
  162. #define BLUE_MOON 153
  163. int
  164. NORMAL_STATE::ChooseJointType( )
  165. {
  166. switch( jointStyle ) {
  167. case ELBOWS:
  168. return ELBOW_JOINT;
  169. case BALLS:
  170. return BALL_JOINT;
  171. case EITHER:
  172. // draw a teapot once in a blue moon
  173. if( ss_iRand(1000) == BLUE_MOON )
  174. return( TEAPOT );
  175. default:
  176. // otherwise an elbow or a ball (1/3 ball)
  177. if( !ss_iRand(3) )
  178. return BALL_JOINT;
  179. else
  180. return ELBOW_JOINT;
  181. }
  182. }