void draw_sprites(int rotation) { spSetZTest( sprites_z ); spSetZSet( sprites_z ); SDL_Surface* screen = spGetWindowSurface(); spRotozoomSurface( screen->w / 4, screen->h / 4, 0, sprites_garfield, spSin( rotation * 4 ) + ( spFloatToFixed( 1.5f ) ) >> 2, spCos( rotation * 8 ) + ( spFloatToFixed( 1.5f ) ) >> 2, rotation ); spRotozoomSurfacePart( 3 * screen->w / 4, screen->h / 4, 0, sprites_garfield, sprites_garfield->w / 4, sprites_garfield->h / 4, sprites_garfield->w / 2, sprites_garfield->w / 2, spSin( rotation * 4 ) + ( spFloatToFixed( 1.5f ) ) >> 1, spCos( rotation * 8 ) + ( spFloatToFixed( 1.5f ) ) >> 1, rotation ); sprite->rotation = 0; spDrawSprite( screen->w / 5, 5 * screen->h / 8, 0, sprite ); sprite->zoomX = spSin( rotation * 8 ) + ( spFloatToFixed( 1.5f ) ); sprite->zoomY = spCos( rotation * 6 ) + ( spFloatToFixed( 1.5f ) ); spDrawSprite( 2 * screen->w / 5, 5 * screen->h / 8, 0, sprite ); sprite->zoomX *= -1; sprite->rotation = rotation * 4; spDrawSprite( 3 * screen->w / 5, 5 * screen->h / 8, 0, sprite ); sprite->zoomX = SP_ONE; sprite->zoomY = SP_ONE; spDrawSprite( 4 * screen->w / 5, 5 * screen->h / 8, 0, sprite ); spSetZTest( 0 ); spSetZSet( 0 ); }
void draw_function( void ) { //Cleaning the target (in this case the screen surface) with 0 (black). //In this case I don't clean the zBuffer, because I don't use it. ;-) //But you ARE able to use it, if you want! spResetZBuffer(); spClearTarget( 34567 ); //Set the origin: switch ( ( rotation >> 17 ) % 9 ) { case 0: spSetHorizontalOrigin( SP_CENTER ); spSetVerticalOrigin( SP_CENTER ); break; case 1: spSetHorizontalOrigin( SP_LEFT ); spSetVerticalOrigin( SP_CENTER ); break; case 2: spSetHorizontalOrigin( SP_LEFT ); spSetVerticalOrigin( SP_TOP ); break; case 3: spSetHorizontalOrigin( SP_CENTER ); spSetVerticalOrigin( SP_TOP ); break; case 4: spSetHorizontalOrigin( SP_RIGHT ); spSetVerticalOrigin( SP_TOP ); break; case 5: spSetHorizontalOrigin( SP_RIGHT ); spSetVerticalOrigin( SP_CENTER ); break; case 6: spSetHorizontalOrigin( SP_RIGHT ); spSetVerticalOrigin( SP_BOTTOM ); break; case 7: spSetHorizontalOrigin( SP_CENTER ); spSetVerticalOrigin( SP_BOTTOM ); break; case 8: spSetHorizontalOrigin( SP_LEFT ); spSetVerticalOrigin( SP_BOTTOM ); break; } //Drawing the sprite in the middle of the screen spDrawSprite( screen->w / 2, screen->h / 2, -1, sprite ); spDrawSprite( screen->w - 1, screen->h - 1, -1, sprite ); spDrawSprite( screen->w - 1, 0, -1, sprite ); spDrawSprite( 0, screen->h - 1, -1, sprite ); spDrawSprite( 0, 0, -1, sprite ); //mark the center //spEllipseBorder( screen->w / 2, screen->h / 2, -100, 60+spSin(rotation/2)/1000, 60+spCos(rotation/3)/1000, 20+spCos(rotation/7)/10000, 20+spSin(rotation/5)/10000, 0 ); spEllipseBorder( screen->w / 2, screen->h / 2, -100, 6, 6, 2, 2, 0 ); //Show it! spFlip(); }
void draw_target(int rotation) { SDL_Surface* screen = spGetWindowSurface(); //drawing on the target_texture spSelectRenderTarget(target_texture); spClearTarget(65535); spSetZSet(0); spSetZTest(0); target_sprite->rotation = 0; spDrawSprite( target_texture->w / 4, target_texture->h / 4, 0, target_sprite ); target_sprite->zoomX = spSin( rotation * 8 ) + spFloatToFixed( 1.5f ); target_sprite->zoomY = spCos( rotation * 6 ) + spFloatToFixed( 1.5f ); spDrawSprite( 3 * target_texture->w / 4, target_texture->h / 4, 0, target_sprite ); target_sprite->rotation = rotation * 4; spDrawSprite( target_texture->w / 4, 3 * target_texture->h / 4, 0, target_sprite ); target_sprite->zoomX = SP_ONE; target_sprite->zoomY = SP_ONE; spDrawSprite( 3 * target_texture->w / 4, 3 * target_texture->h / 4, 0, target_sprite ); //drawing on the target_graph spSelectRenderTarget(target_graph); spClearTarget(01234); spSetZSet(0); spSetZTest(0); Uint16* pixeldata = spGetTargetPixel(); int x; for (x = 0;x < GRAPH_SIZE; x++) { Sint32 sx = spIntToFixed(x-GRAPH_SIZE/2)/16; Sint32 sy = spSin(sx+rotation*16); int y = spFixedToInt(sy*16)+GRAPH_SIZE/2; if (y>=0 && y<GRAPH_SIZE) pixeldata[y*GRAPH_SIZE+x] = 56789; sy = spCos(sx+rotation*32); y = spFixedToInt(sy*16)+GRAPH_SIZE/2; if (y>=0 && y<GRAPH_SIZE) pixeldata[y*GRAPH_SIZE+x] = 45678; } spUnlockRenderTarget(); for (x = 0;x < GRAPH_SIZE-1; x++) { Sint32 sx1 = spIntToFixed(x-GRAPH_SIZE/2)/16; Sint32 sy1 = spTan(sx1+rotation*8); int y1 = spFixedToInt(sy1*16)+GRAPH_SIZE/2; Sint32 sx2 = spIntToFixed(x+1-GRAPH_SIZE/2)/16; Sint32 sy2 = spTan(sx2+rotation*8); int y2 = spFixedToInt(sy2*16)+GRAPH_SIZE/2; spLine(x,y1,0,x+1,y2,0,34567); sy1 = spAcos(sx1/2+spSin(rotation*24)); y1 = spFixedToInt(sy1*16)+GRAPH_SIZE/2; sy2 = spAcos(sx2/2+spSin(rotation*24)); y2 = spFixedToInt(sy2*16)+GRAPH_SIZE/2; spLine(x,y1,0,x+1,y2,0,23456); sy1 = spAsin(sx1/2+spCos(rotation*24)); y1 = spFixedToInt(sy1*16)+GRAPH_SIZE/2; sy2 = spAsin(sx2/2+spCos(rotation*24)); y2 = spFixedToInt(sy2*16)+GRAPH_SIZE/2; spLine(x,y1,0,x+1,y2,0,12345); } //drawing on the screen spSelectRenderTarget(screen); spClearTarget(0); spSetZSet(1); spSetZTest(1); spResetZBuffer(); spIdentity(); spTranslate( 0,0, spFloatToFixed( -7.0f ) ); spRotateX( rotation ); spRotateY( rotation ); spRotateZ( rotation ); //Front / Back spBindTexture(target_texture); spQuadTex3D( -spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), 0, target_texture->h - 1, -spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), 0, 0, spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), target_texture->w - 1, 0, spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), target_texture->w - 1, target_texture->h - 1, 65535); spQuadTex3D( spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), 0, target_texture->h - 1, spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), 0, 0, -spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), target_texture->w - 1, 0, -spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), target_texture->w - 1, target_texture->h - 1, 65535 ); //Left / Right spBindTexture(target_graph); spQuadTex3D( -spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), 0, target_graph->h - 1, -spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), 0, 0, -spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), target_graph->w - 1, 0, -spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), target_graph->w - 1, target_graph->h - 1, 65535 ); spQuadTex3D( spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), 0, target_graph->h - 1, spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), 0, 0, spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), target_graph->w - 1, 0, spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), target_graph->w - 1, target_graph->h - 1, 65535 ); //Up / Down spBindTexture(target_garfield); spQuadTex3D( spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), 0, target_garfield->h - 1, spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), 0, 0, -spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), target_garfield->w - 1, 0, -spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), target_garfield->w - 1, target_garfield->h - 1, 65535 ); spQuadTex3D( -spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), 0, target_garfield->h - 1, -spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), 0, 0, spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), target_garfield->w - 1, 0, spFloatToFixed( 1.5f ), -spFloatToFixed( 1.5f ), spFloatToFixed( 1.5f ), target_garfield->w - 1, target_garfield->h - 1, 65535 ); }