|
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. |