Advertisement

Ten Billion Parentheses, + 4 Bit shifts + 1Subtraction + 1 divide = confusion

Started by March 14, 2003 02:19 PM
1 comment, last by MattS423 21 years, 8 months ago
ok, These few lines are messed up...i''m pretty sure it''s the parentheses. The idea behind this is to find the diffrence between the respective channels of 2 colors (using a bitshift to find the mask, then an AND, then another shift te shift the color value into the least significant byte.) then subtract the 2 color values, and finally divide the diffrence of the colors by the legnth of the line. here''s the code:
  
dLeftAlpha =  ( ((LocalVerts[AimToLeft].Color & (255 << 24)) >> 24 )  - ((LocalVerts[CurrentVertLeft].Color & (255 << 24)) >> 24))/LeftLegnth; 

dLeftRed =  ( ( ((LocalVerts[AimToLeft].Color & (255 << 16)) >> 16 )  - (LocalVerts[CurrentVertLeft].Color & (255 << 16) >> 16)) )/LeftLegnth;

dLeftGreen = ( ( ((LocalVerts[AimToLeft].Color & (255 << 8)) >> 8 )  - (LocalVerts[CurrentVertLeft].Color & (255 << 8) >> 8)) )/LeftLegnth;

dLeftBlue =  ( ((LocalVerts[AimToLeft].Color & (255))  - (LocalVerts[CurrentVertLeft].Color & (255)))/LeftLegnth );

  
The values here are always comming out weird (like, 1 million and change) so I figured I had an error on these lines. Any ideas? thanks.
Programmers of the world, UNTIE!
A couple of ideas spring to mind, you can replace intermediary steps with a temp variable to debug, and I would remove some of those bit shifts and replace with hard constants -- it's a more familiar idiom to many programmers... Also, I think I would approach the matter differently, more like this...



  dLeftAlpha = (((LocalVerts[AimToLeft].Color - LocalVerts[CurrentVertLeft].Color) >> 24) & 0xFF) / LeftLength;dLeftRed = (((LocalVerts[AimToLeft].Color - LocalVerts[CurrentVertLeft].Color) >> 16) & 0xFF) / LeftLength;dLeftGreen = (((LocalVerts[AimToLeft].Color - LocalVerts[CurrentVertLeft].Color) >> 8) & 0xFF) / LeftLength;dLeftBlue = ((LocalVerts[AimToLeft].Color - LocalVerts[CurrentVertLeft].Color) & 0xFF) / LeftLength;   


Note, this code has not been tested, and is right off the top of my head, and it may not work, much less compile But hopefully it helps you some.

[edited by - krelwyn on March 14, 2003 5:31:38 PM]
Advertisement
humm...ok, that helps alot. thanks...
Programmers of the world, UNTIE!

This topic is closed to new replies.

Advertisement