SGL Polygon s

slinga

Established Member
Hey all,

I had some free time and I was fooling around with polygons on the Saturn. I'm using the standard slPutPolygon API and it seems to work so far. I hate the syntax for defining the polygons, is there a cleaner way to do it? For example, if I declare PDATA polygon1 how do I change's color later on during runtime? I can't find any place where the PDATA struct is actually defined.

I also could use some advice on doing collision detection between polygons. For example, if I have two triangles and I know there pos[x], pos[y], pos[z], and ang[z] (I rotate the polygons) how do I know if two triangles are colliding?

Thanks in advance.
 
Hey slinga!

slinga said:
I'm using the standard slPutPolygon API and it seems to work so far. I hate the syntax for defining the polygons, is there a cleaner way to do it? For example, if I declare PDATA polygon1 how do I change's color later on during runtime? I can't find any place where the PDATA struct is actually defined.

PDATA is defined in SL_DEF.H:

Code:
typedef struct {

    Uint8     flag ;

    Uint8     sort ;

    Uint16     texno ;

    Uint16     atrb ;

    Uint16     colno ;

    Uint16     gstb ;

    Uint16     dir ;

} ATTR ;

....

typedef struct {

    POINT    *pntbl ;

    Uint32     nbPoint ;

    POLYGON    *pltbl ;

    Uint32     nbPolygon ;

    ATTR    *attbl ;

} PDATA ;
The color is defined with macro

Code:
#define    C_RGB(r,g,b)        (((b)&0x1f)<<10|((g)&0x1f)<<5|((r)&0x1f)|0x8000)
and given as 4th parameter to the macro

Code:
ATTRIBUTE(f,s,t,c,g,a,d,o)    {f,(s)|(((d)>>16)&0x1c)|(o),t,(a)|(((d)>>24)&0xc0),c,g,(d)&0x3f}
when declaring the polygon attributes.

At runtime, you can change the color of a polygon by assigning myattrptr-> colno = C_RGB(new_r, new_g, new_b).

In case of a gouraud shaded polygon, you could set new colors to the 4-entry gouraud color table of that polygon, which is stored in VDP1 VRAM.

Collision detection is a wide field, I'd suggest you search the web about triangle intersection. Special care has to be taken when using fixed point arithmetic for the computations. Not all methods can be implemented with fixed points. I've implemented a point inside quad/triangle test once for the racing game project. It turned out to give wrong results, because of limited precision. So I found the circle distance approach from the SGL examples DRIVING and others does quite well for my purpose (ground following with collision detection).

Anyways, the SGL itself provides slBallCollision() and slCheckOnScreen() for that.
 
Hey Rockin,

Did you ever release your SGL Replacement lib? I see it under the downloads section on your site, but I can't find a link to a package to download...

As for collision detection I'm going to try using a well known algorithm for determining if two lines intersect. I'll check if any of the 3 lines from the first triangle intersect with any of the three lines from the second triangle.
 
slinga said:
Hey Rockin,

Did you ever release your SGL Replacement lib? I see it under the downloads section on your site, but I can't find a link to a package to download...

No sorry, still on my todo list...

slinga said:
As for collision detection I'm going to try using a well known algorithm for determining if two lines intersect. I'll check if any of the 3 lines from the first triangle intersect with any of the three lines from the second triangle.

I guess you will try to work with bounding volumes where ever possible, as well.
 
Back
Top