Files
TeslaRel410/sda4/DPL3RLS/EXAMPLES/TEST.C
T
CydandClaude Fable 5 db7745fcd0 sda4: commit the Glaze developer hard-drive dump
Un-ignored: the dev drive is the ground truth the restoration and
emulator work constantly reference (DPL3/LIBDPL + VRENDER i860 renderer
source, BT/RP live+dev game trees, VGL_LABS pod boot, scene/audio
content). Kept in-repo for the pod-owner community.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-04 19:41:15 -05:00

407 lines
9.2 KiB
C++

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <dpl.h>
#include "matrix.h"
#include <math.h>
char *dpl_arg;
/*{{{ static dpl_node * find ( char *s, int expect )*/
static dpl_node * find ( char *s, int expect )
{
dpl_node *node;
if (node=dpl_FindNamedNode ( s )) {
if (expect == 0) {
printf ("Unexpectedly found %s, 0x%x type 0x%x\n", s, node, node->type_check );
}
return node;
}
else {
if (expect)
printf ("Unexpectedly couldnt find %s\n", s );
return NULL;
}
}
/*}}} */
/*{{{ void dpl_test_1 ( void )*/
void dpl_test_1 ( void )
{
dpl_ZONE *z;
dpl_DCS *root;
dpl_DCS *dcs1;
dpl_DCS *chile;
dpl_DCS *bro;
int i;
dpl_LMODEL *lm;
dpl_LIGHT *amb;
dpl_LIGHT *direct;
dpl_VIEW *eye;
dpl_VERTEX_LIST *vl;
dpl_INSTANCE *ins;
dpl_OBJECT *obj;
dpl_LOD *lod;
dpl_MATRIX m;
dpl_MATERIAL *frig, *firstpatch;
float32 cx, cy, cz;
z=dpl_NewZone();
root = dpl_NewDcs();
dcs1 = dpl_NewDcs();
chile = dpl_NewDcs();
bro = dpl_NewDcs();
dpl_NestDcs ( root, dcs1 );
dpl_NestDcs ( dcs1, chile );
dpl_LinkDcs ( chile, bro );
eye = dpl_NewView();
dpl_SetViewClipPlanes ( eye, 30.0f, 10000.0f );
dpl_SetViewBackGround ( eye, 0.4f, 0.6f, 0.9f );
dpl_SetViewFog ( eye, 1, 0.5f, 0.5f, 0.6f, 5000.0f, 10000.0f );
dpl_SetViewProjection ( eye, 832.0f, 512.0f,
-1.0f, -1.0f, 1.0f, 1.0f,
2.0f );
dpl_IdMatrix ( m );
dpl_Rotate ( m, 180.0f, dpl_Y );
dpl_Translate ( m, 0.0f, 0.0f, -140.0f );
dpl_SetViewMatrix ( eye, m );
lm = dpl_NewLmodel();
amb = dpl_NewLight();
direct= dpl_NewLight();
dpl_SetLightType ( amb, dpl_light_type_ambient );
dpl_SetLightColor ( amb, 0.2f, 0.3f, 0.5f );
dpl_SetLightType ( direct, dpl_light_type_directional );
dpl_SetLightColor ( direct, 0.8f, 0.8f, 0.6f );
dpl_SetDcsLight ( root, direct );
dpl_SetZoneLmodel ( z, lm );
dpl_SetZoneRootDcs ( z, root );
dpl_AddLightToLmodel ( lm, amb );
dpl_AddLightToLmodel ( lm, direct );
dpl_AddViewToScene ( eye );
dpl_AddZoneToScene ( z );
dpl_SetZoneEnable ( z, 1 );
ins=dpl_NewInstance ();
/*
obj=b2zread("globo.b2z" );
obj=b2zread("grouper.b2z");
obj=b2zread("terr46.b2z" );
*/
dpl_LoadObject ( obj=dpl_NewObject(), "little" );
lod=dpl_GetObjectFirstLod ( obj );
cx=(lod->bounds[0][0]+lod->bounds[1][0]) * 0.5f;
cy=(lod->bounds[0][1]+lod->bounds[1][1]) * 0.5f;
cz=(lod->bounds[0][2]+lod->bounds[1][2]) * 0.5f;
dpl_SetDcsInstance ( chile, ins);
dpl_SetInstanceObject ( ins, obj );
/* first apply a scale to parent node */
dpl_Scale ( dcs1->matrix, 5.0f, 5.0f, 5.0f );
dpl_Flush ( dcs1 );
frig =dpl_NewMaterial();
firstpatch=((dpl_GEOGROUP *) (lod->geogroup_list.head->item))->f_material;
frig->texture=firstpatch->texture;
memcpy ( frig->emissive, firstpatch->emissive, 16*sizeof(float));
frig->ramp=firstpatch->ramp;
frig->texture->u0=0;
frig->texture->v0=0;
frig->texture->dv=0;
frig->texture->du=0.43;
dpl_Flush(frig);
dpl_Flush(frig->texture);
dpl_SetInstanceFrontMaterial ( ins, frig );
dpl_SetInstanceBackMaterial ( ins, frig );
/*
*/
{
float alpha=0.0f;
float alphacycle=0;
int angle=0, clampcycle=0;
while (1) {
float f;
dpl_MATRIX m;
angle++;
f=sin(alphacycle/22.0f);
if (f > 0.99f) {
f=1.0f;
clampcycle++;
if (clampcycle==20) {
alphacycle+=1.0f;
clampcycle=0;
}
}
else
alphacycle+=1.0f;
alpha=0.5f + 0.505f * f;
if (alpha < 0.0f)
alpha=0.0f;
else if (alpha > 1.0f)
alpha=1.0f;
dpl_SetMaterialOpacity ( frig, alpha, alpha, alpha );
dpl_IdMatrix ( m );
dpl_Translate ( m, -cx, -cy, -cz );
dpl_Rotate ( m, angle*0.30f, dpl_Y );
dpl_Rotate ( m, angle*0.437f, dpl_X );
dpl_Rotate ( m, angle*0.1739f, dpl_Z );
dpl_SetDcsMatrix ( chile, m );
dpl_DrawScene ( 1 );
/* printf ("draw scene frame %d\n", angle ); */
}
}
dpl_RemoveViewFromScene ( eye );
dpl_RemoveZoneFromScene ( z );
dpl_RemoveLightFromLmodel ( lm, amb );
dpl_RemoveLightFromLmodel ( lm, direct );
dpl_DeleteLight ( amb );
dpl_DeleteLight ( direct );
dpl_SetZoneLmodel ( z, NULL );
dpl_DeleteLmodel ( lm );
dpl_PruneDcs ( bro );
dpl_PruneDcs ( chile );
dpl_PruneDcs ( dcs1 );
dpl_SetZoneRootDcs ( z, NULL );
dpl_DeleteDcs ( bro );
dpl_DeleteDcs ( chile );
dpl_DeleteDcs ( dcs1 );
dpl_DeleteView ( eye );
dpl_DeleteZone ( z );
printf ( dpl_Status() );
}
/*}}} */
/*{{{ void dpl_test_2 ( void )*/
void dpl_test_2 ( void )
{
int i;
return;
for (i=0; i<2; i++ ) {
dpl_ZONE *z;
dpl_DCS *root;
dpl_DCS *dcs1;
dpl_DCS *chile;
dpl_DCS *bro;
dpl_LMODEL *lm;
dpl_LIGHT *amb;
dpl_LIGHT *direct;
z=dpl_NewZone();
root = dpl_NewDcs();
dcs1 = dpl_NewDcs();
chile = dpl_NewDcs();
bro = dpl_NewDcs();
dpl_NestDcs ( root, dcs1 );
dpl_NestDcs ( dcs1, chile );
dpl_LinkDcs ( chile, bro );
lm = dpl_NewLmodel();
amb = dpl_NewLight();
direct= dpl_NewLight();
dpl_SetLightType ( amb, dpl_light_type_ambient );
dpl_SetLightColor ( amb, 0.2f, 0.3f, 0.5f );
dpl_SetLightType ( direct, dpl_light_type_directional );
dpl_SetLightColor ( direct, 0.8f, 0.8f, 0.6f );
dpl_SetZoneLmodel ( z, lm );
dpl_SetZoneRootDcs ( z, root );
dpl_AddLightToLmodel ( lm, amb );
dpl_AddLightToLmodel ( lm, direct );
dpl_NameNode ( &z->dplnode, "zone" );
dpl_NameNode ( &lm->dplnode, "lighting model" );
dpl_NameNode ( &amb->dplnode, "ambient" );
dpl_NameNode ( &direct->dplnode, "direct light" );
dpl_NameNode ( &root->dplnode, "root" );
dpl_NameNode ( &dcs1->dplnode, "dcs1" );
dpl_NameNode ( &chile->dplnode, "chile" );
dpl_NameNode ( &bro->dplnode, "bro" );
find ( "lighting model", 1 );
find ( "direct light", 1 );
find ( "zone", 1 );
find ( "root", 1 );
find ( "dcs1", 1 );
find ( "chile", 1 );
find ( "bro", 1 );
find ( "lighting module", 0 );
find ( "roots", 0 );
find ( "chile voodoo", 0 );
find ( "bros", 0 );
dpl_ClearNameTable();
find ( "zone", 0 );
find ( "lighting model", 0 );
find ( "lighting module", 0 );
find ( "direct light", 0 );
find ( "root", 0 );
find ( "roots", 0 );
find ( "dcs1", 0 );
find ( "chile", 0 );
find ( "chile voodoo", 0 );
find ( "bro", 0 );
find ( "bros", 0 );
dpl_SetZoneRootDcs ( z, NULL );
dpl_SetZoneLmodel ( z, NULL );
dpl_RemoveLightFromLmodel ( lm, amb );
dpl_RemoveLightFromLmodel ( lm, direct );
dpl_DeleteLmodel ( lm );
dpl_DeleteLight ( amb );
dpl_DeleteLight ( direct );
dpl_PruneDcs ( bro );
dpl_PruneDcs ( chile );
dpl_PruneDcs ( dcs1 );
dpl_DeleteDcs ( bro );
dpl_DeleteDcs ( chile );
dpl_DeleteDcs ( dcs1 );
dpl_DeleteDcs ( root );
dpl_DeleteZone ( z );
printf ( dpl_Status() );
}
}
/*}}} */
/*{{{ void dpl_test_3 ( void )*/
void dpl_test_3 ( void )
{
dpl_OBJECT *o;
dpl_ZONE *z;
clock_t then, now;
return;
z=dpl_NewZone();
then=clock();
/*
o=b2zread("ball.b2z");
o=b2zread("ballo.b2z");
o=b2zread("glob.b2z");
o=b2zread("glob.b2z");
o=b2zread("glob.b2z");
*/
now=clock();
printf ("Done, read 3 globs (1.23 MBytes) in %f secs\n",
(float) (now-then) / 100.0f) ;
}
/*}}} */
/*{{{ void dpl_test_4 ( void )*/
void dpl_test_4 ( void )
{
}
/*}}} */
/*{{{ int main ( int argc, char **argv )*/
int main ( int argc, char **argv )
{
dpl_PATHITEM *gpathitem, *tpathitem;
dpl_EXTNITEM *gextnitem, *textnitem;
dpl_FILEPATH *gpath, *tpath;
dpl_arg=getenv("dplarg");
printf ("test is go\n" );
dpl_SetWarningLevel(0);
dpl_Init ( dpl_arg );
gpath =dpl_NewFilePath();
gpathitem=dpl_NewPathItem();
gextnitem=dpl_NewExtnItem();
tpath =dpl_NewFilePath();
tpathitem=dpl_NewPathItem();
textnitem=dpl_NewExtnItem();
dpl_SetPathItemPath ( gpathitem, "..\\geometry" );
dpl_SetExtnItemExtn ( gextnitem, "b2z" );
dpl_SetPathItemPath ( tpathitem, "..\\texture" );
dpl_SetExtnItemExtn ( textnitem, "svt" );
dpl_AddPathToFilepath ( gpath, gpathitem );
dpl_AddExtToFilepath ( gpath, gextnitem );
dpl_AddPathToFilepath ( tpath, tpathitem );
dpl_AddExtToFilepath ( tpath, textnitem );
dpl_SetGeometryFilePath ( gpath );
dpl_SetTextureFilePath ( tpath );
printf ("dpl_test_1\n" );
dpl_test_1();
return 0;
printf ("dpl_test_2\n" );
dpl_test_2();
printf ("dpl_test_3\n" );
dpl_test_3();
printf ("dpl_test_4\n" );
dpl_test_4();
return 0;
}
/*}}} */