|
From: St0fF 6. <st...@gm...> - 2001-11-06 14:44:18
|
Thanks to Jason for explaining Bresenham's algorithm. I'm sure Dx Fx needs to get to know about some pretty nice helpers: Books and search engines. Hunting with a goot search engine on '+drawing +lines' would probably have been enough ... St0fF. ----- Original Message ----- From: "Jason Hardman" <jas...@bt...> To: "Dev-C++" <dev...@li...>; "<Dx 8a>" <vin...@ed...> Sent: Sunday, November 04, 2001 3:26 AM Subject: Re: [Dev-C++] Drawing Lines... > Hello! Me again. Probably sick of me replying all the time and not being > helpful enough. > > I'm not sure of your level of maths knowledge, but I'll put it simply and > elaborate later (if you want). There are algorithms for drawing lines that > are optimised for speed and can do things like anti-aliasing, but to do a > simple line with simple maths then all you need to know is how to calculate > the gradient of the line. > > If I had a pen and paper and could explain it that way it would be easier, > but I'll try in writing. > > By calculating the gradient you can then tell how much y increases (or > decreases) for each one of x (or x of y) i.e. > Assuming x1 (start) is smaller than x2 (end), i.e. line going left to right > on a screen. If not the case just swap coords around. > > double gradient, dx, dy, x, y; > > dx = x1 - x2; // change in x > dy = y1 - y2; // change in y > > gradient = dy/dx; > > for(x = x1, y = y1; x <= x2; ++x, y += gradient) > putpixel(static_cast<int>(x), static_cast<int>(y), colour); > /* proper rounding would be better, but simple rounding down of decimals in > double to int conversion should be OK */ > > This is a guide of what you might do. I've not tested it, but AFAICT the > math is OK. With a little more work you should be able to go in any > direction. Other algorithms avoid the use of floating point representation > cos it's slower than integer maths. > > I'll go into putpixel later if you want, but first can I ask what are you > trying to do (apart from draw a line)? If you are working in a window then > there are a broad set of drawing functions available for use, i.e. LineTo(), > Polygon(), Rectangle() etc... and they can be used on a DirectX app if need > be? I hope I'm not confusing the issue? > > Jason. > > ----- Original Message ----- > From: "<Dx 8a>" <vin...@ed...> > To: "Dev-C++ mailing list" <dev...@li...> > Sent: Sunday, November 04, 2001 1:31 AM > Subject: [Dev-C++] Drawing Lines... > > > > Ok guys, I'll put it all together, and hopefully I can get the point... > > > > Using a library might be a good choice... I'tll save me a lot of time and > effort... But I surely don't know where I can get from so I guess I'll have > to do things manually. > > > > And yes, I think, DirectX doesn't supply a PutPixel or something to put > points on the screen... That's why Ill have to make my own functions... > > > > Also, there must be someway of doing this thing mathematically... I found > that on a tutorial... that drawing pixels in the screen can be done > mathematically... although, the tutorial didn't included a formula in > drawing a straight line on the screen... Does anyone know of such a formula? > > > > Drawing the pixel on the screen would require me to access the memory > buffer or something... Ill have to make a function to simplify the task and > do a PutPixel... > > > > am I missing something? I hope I got it right, ive actually started coding > a few days earlier... and caused my system to crash... the reason I don't > really know... but it sure wasn't the programming I did... which also > prevented me to check the mailing list... > > > > Well guys, thanks in many ways... although I'll leave the still unanswered > question... > > > > > > > > > > How do I draw Straight lines on the screen? (using DirectX) > > > > > > Specifically, now Im asking of a formula that would make it sure that what > I'm drawing is a straight line... the previous things in the mailing list > have actually helped me to know what Ill actually have to do In doing the > drawing... Well... i hope someone could enlighten me somehow > > > > Thanks... > > > > Dx Fx > > > > __________________________________ > > www.edsamail.com > > > > _______________________________________________ > > Dev-cpp-users mailing list > > Dev...@li... > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > > > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users |