c++ - How to start CImg drawing from bottom-left corner rather than top-left corner? -


in cimg co-ordinate system considered started @ top,left corner . , used see co-ordinate system started bottom,left corner . whenever trying draw triangle co-ordinates (10,100),(50,50),(100,100) got drawing upside down . there flip ?expected want

found found this

to put possible, every time specify y value cimg, need first flip coordinate system want offers. perhaps easiest way write own function converts y value you:

unsigned int flip_y( unsigned int y, unsigned int height ) {     return height - y; } 

this mean every place have specify y, have remember use function:

img.draw_text( x, y, "hello world!", ...); // becomes img.draw_text( x, flip_y( y, img.height() ), "hello world!", ...); 

understandably, tedious fast, , forgetting use flip_y in single situation quite time consuming track down , fix.

as alternative, make own subclass of cimg , wrapping functions take y values , inverts y before passing values original cimg method. have advantage of being able work when passing references subclass library functions expecting cimg parameter.

keep in mind many graphical libraries use style of coordinates, typically because easier buffer addressing kind of coordinate system. if plan on doing lot more work computer graphics in future, recommend learning use coordinate system directly instead of trying force more mathematical one.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -