Page 1 of 1

Calculating a percentage based on a 0.01 variable?

PostPosted: Tue Dec 15, 2009 9:42 pm
by Hblade
Okay the title is confusing I know but I'm trying to find out how I can convert something. I have a double variable that holds a maximum of 1, when it's above 1, it deletes an actor.

What I'm trying to do is, how would I..

Aha, I know a better way of showing you what I mean
Okay, say I wanted to make the "Opacity" code instead of using transp all the time, how would I make the 255 numbers of the opacity match up to the transp's maximum of 1?

For example if you do transp = 255; the darn thing will be SUPER transparent :P... so if you were to make transp = opacity, then it would fail. So how would I get the percentage of "transp" using opacity?

Re: Calculating a percentage based on a 0.01 variable?

PostPosted: Tue Dec 15, 2009 9:53 pm
by pyrometal
Code: Select all
transp = 1 - (double)opacity / 255;


Note that "opacity" is a measure of how much material blocks light, while trnasparency is a measure of how much a materiale allows light to pass through. Therefore they describe the same property but in reverse perspective, therefore you should invert the behavior (1 - opacity).

Re: Calculating a percentage based on a 0.01 variable?

PostPosted: Tue Dec 15, 2009 9:54 pm
by Hblade
Thanks :D It worked

Re: Calculating a percentage based on a 0.01 variable?

PostPosted: Tue Dec 15, 2009 9:58 pm
by pyrometal
Don't forget the points! :P I did help you out a lot today. Haha, anyway, have a good one!

Re: Calculating a percentage based on a 0.01 variable?

PostPosted: Tue Dec 15, 2009 10:00 pm
by Hblade
did ^.^