Advertisement
Guest User

C# normal map rotation angle encoding to color

a guest
Dec 13th, 2014
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.70 KB | None | 0 0
  1.  public void drawNormalMapSprite(Texture2D sourceTex, Vector2 screenPoint, Rectangle sRect, float rot, Vector2 origin, Vector2 scale) {
  2.  
  3.             // Convert rotation to 0..1 range
  4.             float rotVal = (rot % MathHelper.TwoPi) / MathHelper.TwoPi;
  5.  
  6.             // Encode rotation to color
  7.             normalRotateColor.R = (byte)(rotVal * 255); // First approximation with 8 bits
  8.             normalRotateColor.G = (byte)(((rotVal * 255f) % 1) * 255); // Take the remaining fractional part and scale that again to 8 bit range
  9.  
  10.             batches[(int)SpriteBatchType.spriteMainBatch].Draw(sourceTex, screenPoint, sRect, normalRotateColor, rot, origin, scale, SpriteEffects.None, 0f);
  11.  
  12.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement