c++ - OpenGL draw circle with Mouse Move -


i trying use function mousemove(int x, int y) draw circle centered @ mouse click , drag across screen. circles drawn on moving mouse spray paint. far, have

void mousemove(int x, int y) {     glbegin(gl_polygon);         (int = 0; <= 360; i++)         {             float theta = (2 * 3.14 * i) / 360;             glvertex2f((size/2 + x) * cos(theta), (size/2 + y) * sin(theta));         }     glend();     glutpostredisplay(); } 

but when using this, draws large circles aren't centered around mouse. how alter make program draw circles centered @ mouse?

to describe project, creating painting program changes shapes, colors, sizes, , rotations of drawing done in mousemove. now, size int set 32. when user selects shape using 'b' key in keyboard function, he/she can switch shapes drawn around mouse user clicks , drags mouse around. spray paint. other shapes work shaped around mouse except circle shape spray.

this answer assumes things viewport , projection matrices set correctly, , input function taking account fact "screen coordinates" (what mouse uses) not same thing "opengl coordinate space" (this implies reversing direction of y-axis 1 or other).

the math you're using setting vertex coordinates wrong. mouse's x , y coordinates should not multiplied sine/cosine functions.

the correct way write is

glvertex2f((size/2) * cos(theta) + x, (size/2) * sin(theta) + y); 

i add appear still using opengl's immediate mode rendering, deprecated , offer extremely poor training professional setting. highly advise learn modern opengl (3.x+) , reapply concepts whatever projects you're working on. this tutorial.


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

mapreduce - Resource manager does not transit to active state from standby -

serialization - Convert Any type in scala to Array[Byte] and back -