24 February 2020, 19:33 | #1 |
Newbie Amiga programmer
Join Date: Jun 2012
Location: Front of my A500+
Age: 38
Posts: 372
|
Drawing polygons: use only triangles or use bigger ones, splitting them if needed?
Out of theoretical curiosity, which would be the smarter thing?
If we only use triangles, they always will be convex polygons, so we can just simply get the horizontal coordinates of the two edges on each line and fill between them. However, if we need to draw a polygon with a higher number of vertices, then we need to draw several triangles to draw it, which means we need to draw all the edges "inside" the big polygon and also fill it triangle by triangle, instead of filling it once. On the other hand, if we try to draw a polygon which is not convex, then we cannot just use the horizontal coordinates of the edges to fill between them, as it is not known, how much edges - and thus horizontal points - we will have. So, to avoid these gaps, we need to split the non convex polygon into convex ones. But for that we first have to determine if it needs splitting at all. So, in short, which approach would be the faster? On Amiga of course. If the answer depends on which model we're talking about, then A500 and A1200. |
29 February 2020, 03:16 | #2 |
Registered User
Join Date: Dec 2019
Location: North Dakota
Posts: 741
|
What is the use case scenario?
I presume we aren't talking about a classic game scenario as you would already have specific triangles. Edge traversal, scanline by scanline is expensive. If you can merge multiple consecutive runs within same scanline into one, then that's the way to go. But the merge must be faster than the brute Force. |
29 February 2020, 16:33 | #3 |
It's coming back!
Join Date: Jul 2018
Location: comp.sys.amiga
Posts: 762
|
I think the smarter thing would be to arrange it such that your polygons are always convex, which is easy if you're in control. I think you'd get the most benefit from reducing the number of polygons by making them bigger where possible. I have polygons with up to 6 vertices, for instance.
I don't think there's much more complexity in the code to scanline fill polygons with any number of vertices compared to just triangles. The calculations are little more than just a pair of Bresenhams. Otherwise you don't always have to decompose polygons all the way to triangles to get them convex, just clipping an ear or two is often enough. You may find that restricting to triangles gives you other benefits though, particularly in with 3D code. |
01 March 2020, 11:02 | #4 | |||||
Newbie Amiga programmer
Join Date: Jun 2012
Location: Front of my A500+
Age: 38
Posts: 372
|
Experimenting with filled vectorgraphics.
Quote:
Quote:
Quote:
Quote:
Quote:
BTW, i implemented the algorithm for transforming a 3D point to 2D from Wikipedia, but it did not give any hint about the display surface's coordinates. I suspect that ex, ey, and ezare ought to be constants, but what? Have you guys any ideas about what they should be? |
|||||
01 March 2020, 15:57 | #5 |
Registered User
Join Date: Dec 2019
Location: North Dakota
Posts: 741
|
If you don't have a specific 2D game scenario in mind and this is just experimenting, there's plenty googlable approaches how to break down a generic polygon into renderable parts.
Most of them, as far as I can recall have a condition or two per scanline. If the target machine is A500, it's going to add up real fast. I hope you experiment in some C/C++ and not an assembler? Edit: I just realized that a very common scenario could be a demo production where animated convex polygons are, indeed, desirable. In which case you have the option to adjust speed of movement to match the performance of the rasterizer, so the performance might not be critical as it's up to you to decide what you want on screen. |
01 March 2020, 17:19 | #6 | ||
It's coming back!
Join Date: Jul 2018
Location: comp.sys.amiga
Posts: 762
|
Quote:
Quote:
exand eyto 0, and ezto the viewing distance will give you what you want. This part of the process is typically the only one that involves division, so it's often done separately to all the matrix based transformations. |
||
01 March 2020, 19:50 | #7 | ||||
Newbie Amiga programmer
Join Date: Jun 2012
Location: Front of my A500+
Age: 38
Posts: 372
|
Quote:
Quote:
Quote:
Quote:
Code:
x = p3D->x - c->x; y = p3D->y - c->y; z = p3D->z - c->z; cx = cos(c->thx); cy = cos(c->thy); cz = cos(c->thz); sx = sin(c->thx); sy = sin(c->thy); sz = sin(c->thz); dx = cy * (sz * y + cz * x) - sy * z; dy = sx * (cy * z + sy * (sz * y + cz * x)) + cx * (cz * y - sz * x); dz = cx * (cy * z + sy * (sz * y + cz * x)) - sx * (cz * y - sz * x); p2D->x = (ez / dz) * dx + ex; p2D->y = (ez / dz) * dy + ey; What do you mean by "viewing distance"? Isn't viewing distance is the distance between the camera and the point? |
||||
01 March 2020, 20:20 | #8 | |
It's coming back!
Join Date: Jul 2018
Location: comp.sys.amiga
Posts: 762
|
Quote:
The way I do it (and other people are welcome to tell me why I'm wrong), is to use pixels as the unit size for everything, and to approximate one pixel = one millimetre. Your screen is a clear glass grid ranging from -160 to 159 in x and 127 to -128 in y. Your scene, the things you're rendering, sit behind the screen. You sit at viewing distance in front of it. Chose a vertex in your scene, imagine a line from your eye (the camera) to that vertex, and imagine the point where that line intersects the screen. Note it's x and y coordinates. Job done, and calculated through similar triangles. All the matrix stuff leads up to this point. Without looking closely, I think your code is just another representation of the matrices. EDIT: So, viewing distance is probably ez. |
|
01 March 2020, 21:43 | #9 | |||
Newbie Amiga programmer
Join Date: Jun 2012
Location: Front of my A500+
Age: 38
Posts: 372
|
Quote:
ezto 500.0? Quote:
Quote:
|
|||
02 March 2020, 07:07 | #10 | |
It's coming back!
Join Date: Jul 2018
Location: comp.sys.amiga
Posts: 762
|
Quote:
You, your eye, your camera, does move, but the final step of the matrix stuff is the "camera transform", which moves and spins everything in the world, including yourself, around backwards so that you end up at the origin looking straight down the z axis. Then the screen is a plane parallel to xy and around 500mm away from your eye. I recommend you implement the "matrix stuff". It's not hard, and most other sites / tutorials / blogs you find will expect you to have it. |
|
02 March 2020, 10:28 | #11 |
Newbie Amiga programmer
Join Date: Jun 2012
Location: Front of my A500+
Age: 38
Posts: 372
|
Even if i implement the matrix version, i still have no idea what to write into
ezwhen i calculate the projected point's coordinates. You say, it's 500.0? |
02 March 2020, 11:07 | #12 | |
It's coming back!
Join Date: Jul 2018
Location: comp.sys.amiga
Posts: 762
|
Quote:
EDIT: In this image the "near plane" or "plane of projection" is your computer monitor. Imagine an object placed behind that plane. You should be able to see that moving the eye point closer to the screen will give a more exaggerated 3D effect, just as in real life photography. 500 is a good starting point, as you're probably sitting around 500mm from your screen. If you find that things need to be more 3D, or your field of view isn't big enough, then you can decrease that value. Alternatively, if you have a specific field of view in mind, then you can calculate your ezfrom that. Last edited by deimos; 02 March 2020 at 11:28. |
|
02 March 2020, 11:36 | #13 |
Newbie Amiga programmer
Join Date: Jun 2012
Location: Front of my A500+
Age: 38
Posts: 372
|
Thanks. I'll start with 500 and then i'll see.
|
25 March 2020, 19:38 | #14 |
Registered User
Join Date: Mar 2017
Location: London
Posts: 125
|
Not sure if this is of any help but there are a number of Vids following this one
[ Show youtube player ] |
02 April 2020, 17:13 | #15 |
Newbie Amiga programmer
Join Date: Jun 2012
Location: Front of my A500+
Age: 38
Posts: 372
|
Thanks, i'll check them.
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Scans bigger than A3 | haynor666 | HOL suggestions and feedback | 5 | 13 September 2018 15:30 |
Using blitter for filling 3D polygons | kovacm | Amiga scene | 34 | 25 January 2018 15:30 |
Subpixel-corrected lines and polygons on Amiga | Scali | Coders. Asm / Hardware | 9 | 11 January 2012 12:37 |
Would you like some polygons? | Dalai | Retrogaming General Discussion | 7 | 05 October 2004 00:20 |
Bigger collection than EmuChina | Ian | Amiga scene | 16 | 09 December 2001 17:52 |
|
|