Jump to content
  • Advertisement
Sign in to follow this  
MadsGustaf

Primitive drawings

This topic is 4076 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

When the player clicks the left mouse button, and draws it over screen, pixels is drawn, however, if the mouse is being moved quickly, only a few pixels is drawn, instead of the line from a to b being filed with pixels. How would i solve this? my code is currently:
[source langg = "cpp"]
struct point
{
int x,y;
};
...........

const int maxpoints = 100;
point* mousepoints = new point[maxpoints];
int curpoint =0;
.............
 //if mouse button is pressed reamember the current position
  if(mouse_b&1)
  {
	 if(++curpoint >= maxpoints)
	 {
	  curpoint = 0;
	 }
	
	  
     mousepoints[curpoint].x = mouse_x;
     mousepoints[curpoint].y = mouse_y;
	
  }
 //draw all the pixels
 for(n =0; n<= maxpoints; n++)
  drawpoints(buffer,mousepoints[n]);  
.............

void drawpoints(BITMAP* buffer,point pt)
{
 if(inside(pt.x,pt.y,0,0,0+SCREEN_W,0+SCREEN_H))
 {
  //brug do_line();!
  putpixel(buffer,pt.x,pt.y,BLUE);
  putpixel(buffer,pt.x+1,pt.y,BLUE);
  putpixel(buffer,pt.x,pt.y+1,BLUE);
  putpixel(buffer,pt.x-1,pt.y-1,BLUE);
  putpixel(buffer,pt.x-1,pt.y,BLUE);
  putpixel(buffer,pt.x-2,pt.y,BLUE);
  putpixel(buffer,pt.x+1,pt.y+1,BLUE);
  putpixel(buffer,pt.x,pt.y+1,BLUE);
  putpixel(buffer,pt.x-1,pt.y+1,BLUE);
  putpixel(buffer,pt.x-2,pt.y+1,BLUE);
  putpixel(buffer,pt.x,pt.y+2,BLUE);
  putpixel(buffer,pt.x-1,pt.y+2,BLUE);
  
 }
}

im using allegro and c++

Share this post


Link to post
Share on other sites
Advertisement
Whats happening is the cursor is moving over multiple pixels between the last time its position was read and the current time. To solve this you need to calculate the line between the current cursor position and the previous cursor position and then colour the pixels that lie on that line.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!