rjDrawSprite3D - shaddatic/sa2b-render-fix GitHub Wiki
Prototype
void rjDrawSprite3D( const NJS_SPRITE* sp, Int n, Uint32 attr )
API
void (*DrawSprite3D)( const NJS_SPRITE* sp, Int n, Uint32 attr )
Ninja
void njDrawSprite3D( NJS_SPRITE* sp, Int n, Uint32 attr )
Parameters
const NJS_SPRITE* sp
Sprite structure
Int n
Animation frame number
Uint32 attr
Sprite attribute flags
| Flag | Value | Usage |
|---|---|---|
NJD_SPRITE_ANGLE |
BIT_0 |
Rotate sprite around its center by the angle structure member |
NJD_SPRITE_COLOR |
BIT_1 |
Use constant material color, otherwise white is used |
NJD_SPRITE_HFLIP |
BIT_2 |
Flip sprite texture horizontally |
NJD_SPRITE_VFLIP |
BIT_3 |
Flip sprite texture vertically |
NJD_SPRITE_HVFLIP |
BIT_2|3 |
Flip sprite both horizontally and vertically |
NJD_SPRITE_SCALE |
BIT_4 |
Draw sprite always facing the camera, ie 'scale only' |
NJD_SPRITE_ALPHA |
BIT_5 |
Use translucency |
Returns
No return value.
Description
Draw a sprite in 3D space.
Example
This example will draw a 64x64, opaque, sprite in the center of the world at Y +10. It is rotated by 90 degrees and always faces the screen. It uses two frames of animation, and flips between them with every draw pass.
#define NUM_TEXANIM 2
#define NUM_TEX_0 0
#define NUM_TEX_1 2
NJS_TEXANIM tanim[NUM_TEXANIM] =
{
// frame 1
{
64, 64, // sprite size
32, 32, // sprite center
0, 0, // top left texture coordinate
256, 256, // bottom right texture coordinate
NUM_TEX_0, // texture number
0x0 // reserved
},
// frame 2
{
64, 64, // sprite size
32, 32, // sprite center
0, 0, // top left texture coordinate
256, 256, // bottom right texture coordinate
NUM_TEX_1, // texture number
0x0 // reserved
},
};
NJS_SPRITE sp =
{
{ 0.f, 0.f, 0.f }, // position
1.f, 1.f, // scale multiplier
NJM_DEG_ANG( 90.f ), // rotate by 90 degrees
&texlist, // texlist
tanim, // sprite animation list
};
// begin matrix
njPushMatrix( NULL );
// offset sprite 1 meter upwards in world space
njTranslate( NULL, 0.f, 10.f, 0.f );
// draw sprite, use angle and face camera
rjDrawSprite3D( &sp, n_frame, NJD_SPRITE_ANGLE|NJD_SPRITE_SCALE ); // <<<<<<<<
// end matrix
njPopMatrix( 1 );
// next sprite frame
n_frame = (n_frame + 1) % NUM_TEXANIM;
Related Functions
- rjDrawSprite2D() Draw a 2D sprite/quad
History
- 1.5.0.0: Introduced