class RModel | .h |
constructor | RModel(RCar *_car) |
destructor | ~RModel() |
Load | bool Load(QInfo *info,cstring path) Read settings from 'info' 'path' indicates the original component path, i.e. 'body' Expects DOF models |
IsLoaded | bool IsLoaded() Returns TRUE if model has been loaded If so, you may call Paint() to paint it |
Paint | void Paint() Paint the 3D model |
/*
* RModel - model used for car components
* 10-12-2000: Created!
* NOTES:
* (C) Dolphinity/RvG
*/
#include <racer/racer.h>
#include <qlib/debug.h>
#pragma hdrstop
#include <math.h>
#include <d3/geode.h>
#include <qlib/app.h>
DEBUG_ENABLE
// Default ambient lighting (otherwise its very dark)
#define DEF_AMBIENT_LIGHT 0.9f
RModel::RModel(RCar *_car)
{
car=_car;
geode=0;
}
RModel::~RModel()
{
if(geode)delete geode;
}
bool RModel::Load(QInfo *info,cstring path)
// Read settings from 'info'
// 'path' indicates the original component path, i.e. 'body'
// Expects DOF models
{
char buf[128],fname[256];
int i;
// Mind the textures
QCV->Select();
// Model
sprintf(buf,"%s.model.file",path);
info->GetString(buf,fname);
//qdbg("RModel:Load; file '%s'\n",fname);
if(fname[0])
{
rfloat scaleX,scaleY,scaleZ;
QFile *f;
geode=new DGeode(0);
f=new QFile(RFindFile(fname,car->GetCarDir()));
// Set path to find map files
//qdbg(" car dir=%s\n",car->GetCarDir());
geode->SetMapPath(car->GetCarDir());
if(!geode->ImportDOF(f))
{
qwarn("Can't import '%s'",fname);
delete geode;
geode=0;
goto skip_geode;
}
// Use this geode as a part of a rendering tree
geode->EnableCSG();
// Light object
for(i=0;i<geode->materials;i++)
{ geode->material[i]->ambient[0]=DEF_AMBIENT_LIGHT;
geode->material[i]->ambient[1]=DEF_AMBIENT_LIGHT;
geode->material[i]->ambient[2]=DEF_AMBIENT_LIGHT;
}
// Optional scaling
sprintf(buf,"%s.model.scale.x",path);
scaleX=info->GetFloat(buf,1.0);
sprintf(buf,"%s.model.scale.y",path);
scaleY=info->GetFloat(buf,1.0);
sprintf(buf,"%s.model.scale.z",path);
scaleZ=info->GetFloat(buf,1.0);
if(scaleX!=1.0||scaleY!=1.0||scaleZ!=1.0)
{ geode->ScaleVertices(scaleX,scaleY,scaleZ);
}
skip_geode:
if(f)delete f;
}
return TRUE;
}
/**********
* Attribs *
**********/
bool RModel::IsLoaded()
// Returns TRUE if model has been loaded
// If so, you may call Paint() to paint it
{
if(geode)return TRUE;
return FALSE;
}
/********
* Paint *
********/
void RModel::Paint()
// Paint the 3D model
{
if(geode)
{
glPushMatrix();
geode->Paint();
glPopMatrix();
}
}