开发者

What is a good way to get 0 or a value dependant on a boolean?

开发者 https://www.devze.com 2023-03-07 21:20 出处:网络
I\'m currently working on a piece of code that quite simply uses a boolean to see whether the screen is flipped vertically.

I'm currently working on a piece of code that quite simply uses a boolean to see whether the screen is flipped vertically. This is done with :

glOrtho(0.0f, _width, flip ? 0.0f : _height, flip ? _height : 0.0f, -1.0f, 1.0f);

I was wondering if there would be a more optimized way to do this, for example :

glOrtho(0.0f, _开发者_开发技巧width, !flip * _height, flip * _height, -1.0f, 1.0f);

Or would a bitwise operation work?

Thanks for any feedback!


Are you sure that this is a bottleneck in your program?? Don't early optimize and obfuscate your code just for a small gain.


In general, boolValue ? floatValue : 0.0f is equal to boolValue * floatValue

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号