Is it possible to simplify this if statement?
and if so what's the answer?
if (type)
{
if(NdotL >= 0.0)
{
color += Idiff + Ispec;
}
}
else
{
color += Idiff + Ispec;
}
Think about this in terms of Boolean algebra. You have two conditions
A = (type)
B = (NdotL >= 0.0 )
And you execute your statement when
A * B
/A
( I use /A to indicate "NOT A", and * to indicate "AND" )
So the only time you don't execute is
A * /B
This means your statement should be
if (!((type) && NdotL < 0.0 )) {
// do your thing
}
Or, using Boolean identity
(A * B) = /(/A + /B)
you can rewrite your condition as
( /A + B )
if ( !(type) || ( NdotL >= 0 ) ) {
// do your thing
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With