posted February 06, 2006 01:19 PM
/*
* This demo shows sectioned cutting planes using
* the base stream toolkit.
*/
#include < BStream.h>
#include < stdio.h>
#define countof(array) sizeof(array)/sizeof(array[0])
static void WriteObject(BBaseOpcodeHandler*, BStreamFileToolkit*, FILE*, char*r, int);
static char mybuffer[4096];
static float pc_pts[][3] = { {-1,0,0}, {1,0,0},};
static float pc_rdi[] = {0.75f, 0.75f};
static float cutting_planes[][4] = {
{1,0,0,0},
{0,1,0,0},
{0,0,1,0},
};
int main(){
FILE *flptr = fopen( "temp.hsf", "wb");
BStreamFileToolkit mytoolkit;
mytoolkit.PrepareBuffer(mybuffer, sizeof(mybuffer));
TK_Header header;
WriteObject(&header, &mytoolkit, flptr, mybuffer, sizeof(mybuffer));
/* Set Visibility for faces on. */
TK_Visibility vis;
vis.SetGeometry(TKO_Geo_Face);
vis.SetValue(TKO_Geo_Face);
WriteObject(&vis, &mytoolkit, flptr, mybuffer, sizeof(mybuffer));
/* Create some geometry to section. */
TK_PolyCylinder pc;
pc.SetPoints(countof(pc_pts), (float*)pc_pts);
pc.SetRadii(countof(pc_rdi), pc_rdi);
pc.SetCaps(3);
WriteObject(&pc, &mytoolkit, flptr, mybuffer, sizeof(mybuffer));
/* Insert a few cutting planes to take out a section of the object. */
TK_Cutting_Plane cp;
cp.SetPlanes(countof(cutting_planes), (float*)cutting_planes);
WriteObject(&cp, &mytoolkit, flptr, mybuffer, sizeof(mybuffer));
/* TK_Terminator indicates the end of the HSF file. */
TK_Terminator term( TKE_Termination );
WriteObject(&term, &mytoolkit, flptr, mybuffer, sizeof(mybuffer));
fwrite(mybuffer, sizeof(char), mytoolkit.CurrentBufferLength(), flptr);
fclose(flptr);
return 0;
}
static
void WriteObject(BBaseOpcodeHandler * handler,
BStreamFileToolkit * tk,
FILE * fp,
char * buffer,
int size)
{
TK_Status status;
status = handler->Write(*tk);
while (status == TK_Pending){
while (status == TK_Pending){
int count = tk->CurrentBufferLength();
fwrite(buffer, sizeof (char), count, fp);
status = tk->PrepareBuffer(buffer, size);
}
status = handler->Write(*tk);
}
}
[This message has been edited by Reuben (edited February 06, 2006).]
[This message has been edited by Reuben (edited February 06, 2006).]