Reputation: 5404
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;
}
Upvotes: 2
Views: 115
Reputation: 185
Use
if (type && NdotL > 0.0){
Blah....
} else {
Buegh...
}
Just so that it combines the two conditions.
Really sorry about indentations and such, but the mobile version of this site doesn't let you enter code, I just wanted to help you so much XD!
Upvotes: 1
Reputation: 46415
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
}
Upvotes: 6
Reputation: 1336
Try that :
color+=(type && NdotL >= 0.0)? Idiff + Ispec:Idiff + Ispec;
Upvotes: 0