English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General

 
 
Thread Tools
Old 24 September 2018, 12:52   #121
deimos
Registered User

 
Join Date: Jul 2018
Location: Londonish / UK
Posts: 126
There have been so many changes that it's hard to remember them all, but I think the biggest change was to allow the algorithm that walks down the edges calculating the x1 and x2 values to draw lines between to alternate the order in which is calculates each side, like the difference between a single and a bidirectional dot matrix printer. This means that it has to swap out the contents of the registers holding all the edge information half as often as before.

I'm currently trying to build a system where the results of scanline converting an edge can be reused, taking advantage of the fact that every edge is shared between two faces. If I can get it to work it could result in a saving, at least for bigger polygons.

But at the moment it doesn't work. It's been nothing but Gurus for days now...

Quote:
Originally Posted by roondar View Post
Getting closer now. It's been fun watching this number go up over the days.
Might I ask what you changed to get the extra performance after the switch to 4 bitplanes?
deimos is offline  
Old 02 December 2018, 21:16   #122
alexh
Thalion Webshrine
alexh's Avatar
 
Join Date: Jan 2004
Location: Oxford
Posts: 12,184
Any news. I was enjoying this thread
alexh is offline  
Old 02 December 2018, 23:47   #123
deimos
Registered User

 
Join Date: Jul 2018
Location: Londonish / UK
Posts: 126
I've spent the last few weeks experimenting with hidden surface removal algorithms, with a few detours around importing / converting .obj files. I've attached a couple of images of what it currently looks like - it's still a long way from anything that could be called a game.

I'm quite pleased with the hidden surface removal method I've settled on, as it can be almost entirely pre-calculated, just relying on face visibility calculations that need to be done in any case.

I want to create at least one more model to display before moving on to my next step, which will be to calculate the horizon so that I can draw the sky and ground correctly as the camera moves. I'm not yet 100% sure how to do that efficiently.

Quote:
Originally Posted by alexh View Post
Any news. I was enjoying this thread
Attached Thumbnails
Click image for larger version

Name:	013.png
Views:	153
Size:	37.1 KB
ID:	61051   Click image for larger version

Name:	016.png
Views:	163
Size:	48.0 KB
ID:	61052  
deimos is offline  
Old 03 December 2018, 18:25   #124
roondar
Registered User

 
Join Date: Jul 2015
Location: The Netherlands
Posts: 745
I do like the model for the plane, looks quite good
roondar is offline  
Old 03 December 2018, 19:43   #125
Steril707
OCS rocks!

 
Join Date: Sep 2016
Location: Amiga Island
Posts: 619
Nice plane, indeed..

Also looking forward to updates in this thread...
Steril707 is offline  
Old 03 December 2018, 22:36   #126
deimos
Registered User

 
Join Date: Jul 2018
Location: Londonish / UK
Posts: 126
Quote:
Originally Posted by roondar View Post
I do like the model for the plane, looks quite good
Thank you, it wasn’t easy to create as I need to know which polygon is which so that I can draw them in order, I couldn’t get good results with the data imported directly from Blender and had to do a lot of work by hand.
deimos is offline  
Old 26 December 2018, 15:58   #127
deimos
Registered User

 
Join Date: Jul 2018
Location: Londonish / UK
Posts: 126
I've been working on this a bit more (see attached image), and I'm having a hard time trying to correctly draw the horizon / sky and ground, and can't find any help online.

At the moment I'm trying to find the intersections of the rectangle of the screen with the ground plane which has the equation ax + by + cz = 0 (i.e. a plane going through the origin with a normal of (a, b, c), where a, b, c is the middle row of my camera rotation matrix. I can get the intersection points for the top, right, bottom and left edges of the screen, which gives me a horizon line, but I need to handle the special cases of no intersection (all sky or all ground) and I need to work out which side of the line is ground and which is sky, which doesn't seem to be as simple as looking at the Y part of the normal.

Does anyone know of any off the shelf solution to this?

Otherwise, my next best idea is to define the screen as a polygon and find some code to clip a polygon to a plane, but I'm not sure what that will look like and whether it will solve my sky vs ground issue.
Attached Thumbnails
Click image for larger version

Name:	020.png
Views:	122
Size:	69.8 KB
ID:	61319  
deimos is offline  
Old 26 December 2018, 18:59   #128
deimos
Registered User

 
Join Date: Jul 2018
Location: Londonish / UK
Posts: 126
This is what I'm currently thinking and will try and code up tomorrow unless there's a better answer out there:

The screen is a polygon, a rectangle from xmin, ymin to xmax, ymax and is located at the viewing distance (256) from the origin:

Code:
    (-160,  127, 256),
    (-160, -128, 256),
    ( 159, -128, 256),
    ( 159,  127, 256)

The ground plane is defined by ax + by + cz = 0, where a, b, c is determined by the orientation of the camera.

Each point in the screen polygon is above or below the ground plane, which can be determined by plugging in the x, y, z values into the plane equation. Positive numbers mean above the plane, negative means below and zero means exactly on the plane which I'll treat as below.

Assuming the screen in sky colour (not wasted if there's only a single bit to change between sky and ground):

Code:
if all the points are above the plane then
    it's all sky, exit.

if all the points are below the plane then
    it's all ground, draw that and exit.

otherwise we have a mix of above and below, so
there must be intersection points.
 
set c (number of points in result) to zero.

for each input point p
    let q be next point in input, wrapping around at the end
    if p is behind the plane
        copy it to result array
        increment c
    if p is behind and q is in front or visa versa
        calculate intersection between line pq and ground plane
        copy it to result array
        increment c

draw ground as polygon in result array
deimos is offline  
Old 27 December 2018, 14:22   #129
deimos
Registered User

 
Join Date: Jul 2018
Location: Londonish / UK
Posts: 126
Something like this:

Code:
static void drawGround(struct RastPort * rastPort, const Camera * camera) {
    WORD poly[5][2];

    LONG a = ((Entity *) camera)->transformation.rotation.value[1][0];
    LONG b = ((Entity *) camera)->transformation.rotation.value[1][1];

    LONG cz = ((Entity *) camera)->transformation.rotation.value[1][2] << 8; // 2^8 = 256 = viewing distance

    WORD s[4];
    s[0] = a * (DISPLAY_MIN_X - DISPLAY_MID_X) + b * (DISPLAY_MAX_Y - DISPLAY_MID_Y) + cz >= 0;
    s[1] = a * (DISPLAY_MIN_X - DISPLAY_MID_X) + b * (DISPLAY_MIN_Y - DISPLAY_MID_Y) + cz >= 0;
    s[2] = a * (DISPLAY_MAX_X - DISPLAY_MID_X) + b * (DISPLAY_MIN_Y - DISPLAY_MID_Y) + cz >= 0;
    s[3] = a * (DISPLAY_MAX_X - DISPLAY_MID_X) + b * (DISPLAY_MAX_Y - DISPLAY_MID_Y) + cz >= 0;

    WORD c = 0;

    if (s[0]) {
        poly[c][X] = DISPLAY_MIN_X;
        poly[c][Y] = DISPLAY_MAX_Y;
        c++;
    }

    if (s[0] != s[1]) {
        poly[c][X] = DISPLAY_MIN_X;
        poly[c][Y] = DISPLAY_MID_Y - (a * (DISPLAY_MIN_X - DISPLAY_MID_X) + cz) / b;
        c++;
    }

    if (s[1]) {
        poly[c][X] = DISPLAY_MIN_X;
        poly[c][Y] = DISPLAY_MIN_Y;
        c++;
    }

    if (s[1] != s[2]) {
        poly[c][X] = DISPLAY_MID_X - (b * (DISPLAY_MIN_Y - DISPLAY_MID_Y) + cz) / a;
        poly[c][Y] = DISPLAY_MIN_Y;
        c++;
    }

    if (s[2]) {
        poly[c][X] = DISPLAY_MAX_X;
        poly[c][Y] = DISPLAY_MIN_Y;
        c++;
    }

    if (s[2] != s[3]) {
        poly[c][X] = DISPLAY_MAX_X;
        poly[c][Y] = DISPLAY_MID_Y - (a * (DISPLAY_MAX_X - DISPLAY_MID_X) + cz) / b;
        c++;
    }

    if (s[3]) {
        poly[c][X] = DISPLAY_MAX_X;
        poly[c][Y] = DISPLAY_MAX_Y;
        c++;
    }

    if (s[3] != s[0]) {
        poly[c][X] = DISPLAY_MID_X - (b * (DISPLAY_MAX_Y - DISPLAY_MID_Y) + cz) / a;
        poly[c][Y] = DISPLAY_MAX_Y;
        c++;
    }

    if (c) {
        SetAPen(rastPort, FOREST_GREEN);
        AreaMove(rastPort, poly[0][X], poly[0][Y]);
        for (WORD i = 1; i < c; i++) {
            AreaDraw(rastPort, poly[i][X], poly[i][Y]);
        }
        AreaDraw(rastPort, poly[0][X], poly[0][Y]);
        AreaEnd(rastPort);
    }
}
I think I may have to add some tests for the intersections being exactly on the corners, otherwise I may end up with duplicated points, which may annoy the poly fill routine and may result in me having more points than I've allocated space for.

But, it seems to work.

Could it be better?
deimos is offline  
Old 23 January 2019, 15:38   #130
Steril707
OCS rocks!

 
Join Date: Sep 2016
Location: Amiga Island
Posts: 619
@Deimos: Thanks for keeping on. This is really one of the most interesting topics here for me at EAB currently...
I loved Starglider and Elite, and though I am not keen on coding stuff like this myself, it#s interesting to see your progress...
Steril707 is offline  
Old 23 January 2019, 22:15   #131
deimos
Registered User

 
Join Date: Jul 2018
Location: Londonish / UK
Posts: 126
Quote:
Originally Posted by Steril707 View Post
@Deimos: Thanks for keeping on. This is really one of the most interesting topics here for me at EAB currently...
I loved Starglider and Elite, and though I am not keen on coding stuff like this myself, it#s interesting to see your progress...
Thanks for the encouragement. I’ve been working on how to draw the ground detail, focusing on how to define coastlines, urban areas, etc., at different detail levels but without having to calculate and type in thousands of coordinates by hand. I’ve talked about that in another thread and had some helpful pointers there. Hopefully I can build something semi automated that will give the landscape to which I can add details like important buildings, then slice it into 880K chunks to make mission packs.

But, life, huh, gets in the way. It will be a few weeks at least before I get more time to work on it.
deimos is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Games that are Full Frame Rate or Slower - Limitations or Choice? Foebane Retrogaming General Discussion 35 08 April 2018 14:22
F1 grand prix frame rate universale support.Games 18 13 July 2015 22:45
The First Person Shooter frame rate tolerance poll... DDNI Retrogaming General Discussion 41 30 June 2011 04:32
Vsync Fullscreen and Double Buffer, incorrect frame rate? rsn8887 support.WinUAE 1 07 April 2011 21:43
Propper speed request when recording with "Disable frame rate" turned on. Ironclaw request.UAE Wishlist 9 02 August 2006 08:21

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 18:27.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.
Page generated in 0.08911 seconds with 14 queries