Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.42 KB | None | 0 0
  1. //spiral body
  2. void NoteDisplay::DrawHoldBody2( const TapNote& tn, int iCol, int iRow, bool bIsBeingHeld, float fYHead, float fYTail, float fYStep, float fPercentFadeToFail, float fColorScale, bool bGlow,
  3. float fYStartOffset, float fYEndOffset, bool bIsActive )
  4. {
  5.  
  6. float fBeat = NoteRowToBeat(max(tn.HoldResult.iLastHeldRow, iRow));
  7.  
  8. //float fBeat = NoteRowToBeat(iRow);
  9. float fOrigEndBeat = NoteRowToBeat(iRow+tn.iDuration);
  10. float fCurBeat = GAMESTATE->m_fSongBeat;
  11. float fRelativeEndBeat = (fOrigEndBeat-fCurBeat)/(float)NoteRowToBeat(tn.iDuration);
  12.  
  13. float fLengthMult = 1.f+(fRelativeEndBeat*m_pPlayerState->m_CurrentPlayerOptions.m_fEffects[PlayerOptions::EFFECT_LONG_HOLDS]);
  14.  
  15. float fEndBeat = NoteRowToBeat(iRow+(tn.iDuration*fLengthMult));
  16.  
  17. bool spiralUV = ( m_pPlayerState->m_CurrentPlayerOptions.m_fEffects[PlayerOptions::EFFECT_SPIRAL_HOLDS] < 0 );
  18.  
  19. //
  20. // Draw the body (always wavy)
  21. //
  22. StripBuffer queue;
  23.  
  24. Sprite* pSprBody = GetHoldBodySprite( NoteRowToBeat(iRow), tn.subType == TapNote::hold_head_roll, bIsBeingHeld );
  25.  
  26. // draw manually in small segments
  27. RageTexture* pTexture = pSprBody->GetTexture();
  28. const RectF *pRect = pSprBody->GetCurrentTextureCoordRect();
  29. DISPLAY->ClearAllTextures();
  30. DISPLAY->SetTexture( 0, pTexture );
  31. DISPLAY->SetBlendMode( BLEND_NORMAL );
  32. float fhc = m_pPlayerState->m_CurrentPlayerOptions.m_fEffects[PlayerOptions::EFFECT_HOLD_CULL];
  33. CullMode C = CULL_NONE;
  34. if( fhc > 1 )
  35. C = CULL_BACK;
  36. else if( fhc > 0 )
  37. C = CULL_FRONT;
  38.  
  39. DISPLAY->SetCullMode( C );
  40. DISPLAY->SetTextureWrapping( true );
  41.  
  42.  
  43. const float fFrameWidth = pSprBody->GetZoomedWidth();
  44. const float fFrameHeight = pSprBody->GetZoomedHeight();
  45.  
  46. //const float fYBodyTop = fYHead + cache->m_iStartDrawingHoldBodyOffsetFromHead;
  47. //const float fYBodyBottom = fYTail + cache->m_iStopDrawingHoldBodyOffsetFromTail;
  48.  
  49. float fYOffsetA = ArrowEffects::GetYOffset( m_pPlayerState, iCol, fBeat );
  50. float fYOffsetB = ArrowEffects::GetYOffset( m_pPlayerState, iCol, fEndBeat );
  51.  
  52. const float fYBodyTop = ArrowEffects::GetYPos( m_pPlayerState, iCol, fYOffsetA, m_fYReverseOffsetPixels ) + cache->m_iStartDrawingHoldBodyOffsetFromHead;
  53. const float fYBodyBottom = ArrowEffects::GetYPos( m_pPlayerState, iCol, fYOffsetB, m_fYReverseOffsetPixels ) + cache->m_iStopDrawingHoldBodyOffsetFromTail;
  54.  
  55. const bool bReverse = m_pPlayerState->m_CurrentPlayerOptions.GetReversePercentForColumn(iCol) > 0.5f;
  56. bool bHoldStealth = m_pPlayerState->m_CurrentPlayerOptions.m_fAppearances[PlayerOptions::APPEARANCE_HOLD_STEALTH] > 0;
  57. bool bAnchorToBottom = bReverse && cache->m_bFlipHeadAndTailWhenReverse;
  58.  
  59. if( bGlow )
  60. fColorScale = 1;
  61.  
  62. // Only draw the section that's within the range specified. If a hold note is
  63. // very long, don't process or draw the part outside of the range. Don't change
  64. // fYBodyTop or fYBodyBottom; they need to be left alone to calculate texture
  65. // coordinates.
  66. float fDrawYBodyTop;
  67. float fDrawYBodyBottom;
  68. {
  69. float fYStartPos = ArrowEffects::GetYPos( m_pPlayerState, iCol, fYStartOffset, m_fYReverseOffsetPixels );
  70. float fYEndPos = ArrowEffects::GetYPos( m_pPlayerState, iCol, fYEndOffset, m_fYReverseOffsetPixels );
  71.  
  72. //float fYStartPos = ArrowEffects::GetYPos( m_pPlayerState, iCol, fYOffsetA, m_fYReverseOffsetPixels );
  73. //float fYEndPos = ArrowEffects::GetYPos( m_pPlayerState, iCol, fYOffsetB, m_fYReverseOffsetPixels );
  74.  
  75. fDrawYBodyTop = max( fYBodyTop, bReverse ? fYEndPos : fYStartPos );
  76. fDrawYBodyBottom = min( fYBodyBottom, bReverse ? fYStartPos : fYEndPos );
  77. }
  78.  
  79. // top to bottom
  80. bool bAllAreTransparent = true;
  81. bool bLast = false;
  82. float fVertTexCoordOffset = 0;
  83.  
  84. float fBStep = spiralUV ? (float)fYStep/(ARROW_SIZE*2.0f) : (float)fYStep/(ARROW_SIZE*0.5f);
  85.  
  86. float fReverseMult = bReverse ? -1 : 1;
  87.  
  88. // FMS_Cat start
  89. const float EPSILON = fBStep / 8.0; // 8.0 is random
  90. // FMS_Cat end
  91.  
  92. const float fHp = ArrowEffects::HoldPower( m_pPlayerState, iCol );
  93.  
  94. for( float fBc = fBeat; !bLast; fBc += fBStep )
  95. {
  96. if( fBc >= fEndBeat )
  97. {
  98. fBc = fEndBeat;
  99. bLast = true;
  100. }
  101.  
  102. if( ArrowEffects::GetYOffset( m_pPlayerState, iCol, fBc ) > fYEndOffset )
  103. {
  104. bLast = true;
  105. }
  106.  
  107. //const float fYOffset = ArrowEffects::GetYOffsetFromYPos( m_pPlayerState, iCol, fY, m_fYReverseOffsetPixels );
  108.  
  109. float fYOffset;
  110. float fYOffsetHome;
  111.  
  112. if( !bIsActive ){
  113. fYOffset = max(ArrowEffects::GetYOffset( m_pPlayerState, iCol, fBc ), fYStartOffset);
  114. fYOffsetHome = max(ArrowEffects::GetYOffset( m_pPlayerState, iCol, fBeat ), fYStartOffset);
  115. }else{
  116. fYOffset = max(ArrowEffects::GetYOffset( m_pPlayerState, iCol, fBc ), 0);
  117. fYOffsetHome = 0;
  118. }
  119.  
  120. fYOffset = min( fYOffset, fYEndOffset );
  121.  
  122. const float fY = ArrowEffects::GetYPos( m_pPlayerState, iCol, fYOffset, m_fYReverseOffsetPixels );
  123.  
  124. const float fXreal = ArrowEffects::GetXPos( m_pPlayerState, iCol, fYOffset );
  125. const float fZreal = ArrowEffects::GetZPos( m_pPlayerState, iCol, fYOffset );
  126.  
  127. const float fY2 = ArrowEffects::GetYPos( m_pPlayerState, iCol, fYOffset+fBStep, m_fYReverseOffsetPixels );
  128. const float fX2real = ArrowEffects::GetXPos( m_pPlayerState, iCol, fYOffset+fBStep );
  129. //const float fZ2 = ArrowEffects::GetZPos( m_pPlayerState, iCol, fYOffset+fBStep );
  130.  
  131. const float fXhome = ArrowEffects::GetXPos( m_pPlayerState, iCol, fYOffsetHome );
  132. const float fX2home = ArrowEffects::GetXPos( m_pPlayerState, iCol, fYOffsetHome );
  133. const float fZhome = ArrowEffects::GetZPos( m_pPlayerState, iCol, fYOffsetHome );
  134.  
  135. const float fZoomReal = ArrowEffects::GetZoom( m_pPlayerState, fYOffset, iCol )*ArrowEffects::GetZoomX( m_pPlayerState, fYOffset, iCol )*m_fHoldZoom;
  136. const float fZoomHome = ArrowEffects::GetZoom( m_pPlayerState, fYOffsetHome, iCol )*ArrowEffects::GetZoomX( m_pPlayerState, fYOffsetHome, iCol )*m_fHoldZoom;
  137.  
  138. const float fX = (fHp*fXreal)+((1-fHp)*fXhome);
  139. const float fX2 = (fHp*fX2real)+((1-fHp)*fX2home);
  140. const float fZ = (fHp*fZreal)+((1-fHp)*fZhome);
  141. const float fZoom = (fHp*fZoomReal)+((1-fHp)*fZoomHome);
  142.  
  143. const float fAng = atan2f( fY2-fY, fX2-fX );
  144.  
  145. const float fAngOffsetX = (fFrameWidth*fZoom)/2 * RageFastSin(fAng);
  146. const float fAngOffsetY = (fFrameWidth*fZoom)/2 * RageFastCos(fAng);
  147.  
  148. const float fXLeft = fX - fAngOffsetX;
  149. const float fXRight = fX + fAngOffsetX;
  150. const float fYLeft = fY + fAngOffsetY;
  151. const float fYRight = fY - fAngOffsetY;
  152. const float fZLeft = fZ;
  153. const float fZRight = fZ;
  154.  
  155. //const float fDistFromBodyBottom = fYBodyBottom - fY;
  156. //const float fDistFromBodyTop = fY - fYBodyTop;
  157.  
  158. const float fDistFromBodyBottom = spiralUV ? (fEndBeat - fBc)*fFrameHeight*0.25f*max(m_pPlayerState->m_CurrentPlayerOptions.m_fScrollSpeed,1) : fYBodyBottom - fY;
  159. const float fDistFromBodyTop = spiralUV ? (fBc - fBeat)*fFrameHeight*0.25f*max(m_pPlayerState->m_CurrentPlayerOptions.m_fScrollSpeed,1) : fY - fYBodyTop;
  160.  
  161. /*
  162. const float fTopDistFromTail = (fBc - fEndBeat)*fFrameHeight*2.0f*max(m_pPlayerState->m_CurrentPlayerOptions.m_fScrollSpeed,1);
  163. const float fTexCoordTop = SCALE( fTopDistFromTail, 0, fFrameHeight, pRect->top, pRect->bottom );
  164. */
  165.  
  166. float fTexCoordTop;
  167. if(bReverse){
  168. fTexCoordTop = SCALE( bAnchorToBottom ? fDistFromBodyBottom : fDistFromBodyTop, 0, fFrameHeight, pRect->bottom, pRect->top );
  169. }else{
  170. fTexCoordTop = SCALE( bAnchorToBottom ? fDistFromBodyTop : fDistFromBodyBottom, 0, fFrameHeight, pRect->bottom, pRect->top );
  171. }
  172.  
  173. // For very large hold notes, shift the texture coordinates to be near 0, so we
  174. // don't send very large values to the renderer.
  175. if( fBc == fBeat ) // first
  176. fVertTexCoordOffset = floorf( fTexCoordTop );
  177. fTexCoordTop -= fVertTexCoordOffset;
  178.  
  179.  
  180. const float fTexCoordLeft = pRect->left;
  181. const float fTexCoordRight = pRect->right;
  182.  
  183.  
  184.  
  185.  
  186.  
  187. float fAlphaOrGlow = ArrowGetAlphaOrGlow( bGlow, m_pPlayerState, iCol, fYOffset, fPercentFadeToFail, m_fYReverseOffsetPixels );
  188.  
  189. float fHoldAlpha = ArrowEffects::GetHoldAlpha( m_pPlayerState, iCol, fYOffset, fPercentFadeToFail, m_fYReverseOffsetPixels );
  190. float fHoldGlow = ArrowEffects::GetHoldGlow( m_pPlayerState, iCol, fYOffset, fPercentFadeToFail, m_fYReverseOffsetPixels );
  191.  
  192. if( bHoldStealth ){
  193. if( bGlow )
  194. fAlphaOrGlow = fHoldGlow;
  195. else
  196. fAlphaOrGlow = fHoldAlpha;
  197. }
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204. RageColor diffuse;
  205. RageColor glow;
  206.  
  207. float fRd = ArrowEffects::GetRedDiff( m_pPlayerState, iCol, fYOffset, fPercentFadeToFail, m_fYReverseOffsetPixels );
  208. float fGd = ArrowEffects::GetGreenDiff( m_pPlayerState, iCol, fYOffset, fPercentFadeToFail, m_fYReverseOffsetPixels );
  209. float fBd = ArrowEffects::GetBlueDiff( m_pPlayerState, iCol, fYOffset, fPercentFadeToFail, m_fYReverseOffsetPixels );
  210. float fRg = ArrowEffects::GetRedGlow( m_pPlayerState, iCol, fYOffset, fPercentFadeToFail, m_fYReverseOffsetPixels );
  211. float fGg = ArrowEffects::GetGreenGlow( m_pPlayerState, iCol, fYOffset, fPercentFadeToFail, m_fYReverseOffsetPixels );
  212. float fBg = ArrowEffects::GetBlueGlow( m_pPlayerState, iCol, fYOffset, fPercentFadeToFail, m_fYReverseOffsetPixels );
  213.  
  214. if( !m_pPlayerState->m_CurrentPlayerOptions.arrowGradientColor.empty() && !m_pPlayerState->m_CurrentPlayerOptions.arrowGradientColor[iCol].empty() ){
  215. const RageColor c = ArrowEffects::GetArrowColor( m_pPlayerState, iCol, fYOffset, m_fYReverseOffsetPixels );
  216. diffuse = RageColor( c.r, c.g, c.b, c.a*fAlphaOrGlow );
  217.  
  218. }else{
  219. diffuse = RageColor(
  220. fColorScale*fRd,
  221. fColorScale*fGd,
  222. fColorScale*fBd,
  223. fAlphaOrGlow);
  224. }
  225.  
  226.  
  227. if( !m_pPlayerState->m_CurrentPlayerOptions.arrowGlowGradientColor.empty() && !m_pPlayerState->m_CurrentPlayerOptions.arrowGlowGradientColor[iCol].empty() ){
  228. const RageColor c = ArrowEffects::GetArrowGlowColor( m_pPlayerState, iCol, fYOffset, m_fYReverseOffsetPixels );
  229. glow = RageColor( c.r, c.g, c.b, c.a*fAlphaOrGlow );
  230.  
  231. }else{
  232. if( fRg == 0 && fGg == 0 && fBg == 0 ){
  233. glow = RageColor( 1,1,1,fAlphaOrGlow );
  234. }else{
  235. glow = RageColor(
  236. fColorScale*fRg,
  237. fColorScale*fGg,
  238. fColorScale*fBg,
  239. fAlphaOrGlow);
  240. }
  241. }
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251. const RageColor color = bGlow ? glow : diffuse ;
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263. if( fAlphaOrGlow > 0 )
  264. bAllAreTransparent = false;
  265.  
  266.  
  267.  
  268.  
  269.  
  270. queue.v[0].p = RageVector3(fXLeft, fYLeft, fZLeft); queue.v[0].c = color; queue.v[0].t = RageVector2(fTexCoordLeft, fTexCoordTop);
  271. queue.v[1].p = RageVector3(fXRight, fYRight, fZRight); queue.v[1].c = color; queue.v[1].t = RageVector2(fTexCoordRight, fTexCoordTop);
  272.  
  273. // FMS_Cat Start
  274. const float fYp = ArrowEffects::GetYPos( m_pPlayerState, iCol, fYOffset+fBStep, m_fYReverseOffsetPixels );
  275. const float fXp = ArrowEffects::GetXPos( m_pPlayerState, iCol, fYOffset+fBStep );
  276. const float fZp = ArrowEffects::GetZPos( m_pPlayerState, iCol, fYOffset+fBStep );
  277.  
  278. const RageVector3 na = RageVector3( fXRight - fXLeft, 0.0, fZRight - fZLeft );
  279. const RageVector3 nb = RageVector3( fXp - fXLeft, fYp - fY, fZp - fZLeft );
  280. const RageVector3 n = RageVector3(
  281. na.y * nb.z - na.z * nb.y,
  282. na.z * nb.x - na.x * nb.z,
  283. na.x * nb.y - na.y * nb.x
  284. );
  285. const float nl = sqrtf( n.x * n.x + n.y * n.y + n.z * n.z );
  286.  
  287. queue.v[0].n = n / nl; queue.v[0].n.y = -queue.v[0].n.y;
  288. queue.v[1].n = n / nl; queue.v[1].n.y = -queue.v[1].n.y;
  289. // FMS_Cat End
  290.  
  291. queue.v+=2;
  292. if( queue.Free() < 2 )
  293. {
  294. // The queue is full. Render it, clear the buffer, and move back a step to
  295. // start off the quad strip again.
  296. if( !bAllAreTransparent ){
  297.  
  298. if( m_pPlayerState->m_pHoldShader != NULL && m_pPlayerState->m_pHoldShader->IsValid() )
  299. {
  300. m_pPlayerState->m_pHoldShader->SetUniform2f( "imageSize", pTexture->GetImageWidth(), pTexture->GetImageHeight() );
  301. m_pPlayerState->m_pHoldShader->SetUniform2f( "textureSize", pTexture->GetTextureWidth(), pTexture->GetTextureHeight() );
  302. m_pPlayerState->m_pHoldShader->SetUniform1i( "iCol", iCol ); m_pPlayerState->m_pHoldShader->SetUniform1i( "iPlayfield", m_pPlayerState->m_Playfield );
  303. m_pPlayerState->m_pHoldShader->SetUniform1i( "isReceptor", 0 ); m_pPlayerState->m_pHoldShader->SetUniform1i( "isHold", 1 );
  304. m_pPlayerState->m_pHoldShader->SetUniform1f( "fNoteBeat", NoteRowToBeat(iRow) );
  305.  
  306. DISPLAY->ApplyShaderProgram( m_pPlayerState->m_pHoldShader );
  307. }
  308.  
  309. queue.Draw();
  310.  
  311. DISPLAY->UnapplyShaderProgram();
  312.  
  313. }
  314. queue.Init();
  315. bAllAreTransparent = true;
  316. fBc -= fBStep;
  317. }
  318. }
  319. if( !bAllAreTransparent ){
  320.  
  321. if( m_pPlayerState->m_pHoldShader != NULL && m_pPlayerState->m_pHoldShader->IsValid() )
  322. {
  323. m_pPlayerState->m_pHoldShader->SetUniform2f( "imageSize", pTexture->GetImageWidth(), pTexture->GetImageHeight() );
  324. m_pPlayerState->m_pHoldShader->SetUniform2f( "textureSize", pTexture->GetTextureWidth(), pTexture->GetTextureHeight() );
  325. m_pPlayerState->m_pHoldShader->SetUniform1i( "iCol", iCol ); m_pPlayerState->m_pHoldShader->SetUniform1i( "iPlayfield", m_pPlayerState->m_Playfield );
  326. m_pPlayerState->m_pHoldShader->SetUniform1i( "isReceptor", 0 ); m_pPlayerState->m_pHoldShader->SetUniform1i( "isHold", 1 );
  327. m_pPlayerState->m_pHoldShader->SetUniform1f( "fNoteBeat", NoteRowToBeat(iRow) );
  328.  
  329. DISPLAY->ApplyShaderProgram( m_pPlayerState->m_pHoldShader );
  330. }
  331.  
  332. queue.Draw();
  333.  
  334. DISPLAY->UnapplyShaderProgram();
  335.  
  336. }
  337. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement