Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
rtv
committed
Jun 25, 2009
1 parent
5936b28
commit e2e8d03
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* File: rasterize.cc | ||
* Description: example of how to use the Stg::Model::Rasterize() method | ||
* Date: 12 June 2009 | ||
* Author: Richard Vaughan | ||
*/ | ||
|
||
// uncomment the line 'ctrl "rasterize"' in <stage source>/worlds/simple.world to try this example | ||
|
||
#include "stage.hh" | ||
using namespace Stg; | ||
|
||
|
||
// Stage calls this when the model starts up | ||
extern "C" int Init( Model* mod ) | ||
{ | ||
const unsigned int dw = 40, dh = 20; | ||
|
||
uint8_t* data = new uint8_t[dw*dh*2]; | ||
memset( data, 0, sizeof(uint8_t) * dw * dh ); | ||
|
||
printf( "\n[Rasterize] Raster of model \"%s\":\n", | ||
mod->Token() ); | ||
|
||
Size modsz( mod->GetGeom().size ); | ||
|
||
mod->Rasterize( data, dw, dh, | ||
modsz.x / (float)dw, | ||
modsz.y / (float)dh ); | ||
|
||
for( unsigned int y=0; y<dh; y++ ) | ||
{ | ||
printf( "[Rasterize] " ); | ||
for( unsigned int x=0; x<dw; x++ ) | ||
putchar( data[x + ((dh-y-1)*dw)] ? 'O' : '.' ); | ||
putchar( '\n' ); | ||
} | ||
delete data; | ||
puts( "[Rasterize] Done" ); | ||
|
||
return 0; //ok | ||
} | ||
|
||
|
||
|