156 lines
3.3 KiB
C
156 lines
3.3 KiB
C
/*
|
|
* PVVMUD a 3D MUD
|
|
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
*
|
|
*/
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <iostream.h>
|
|
|
|
#include "pvvmud.H"
|
|
#include "material.H"
|
|
#include "matfile.H"
|
|
|
|
|
|
int CMaterial::load(char * fileName) {
|
|
char * sufix;
|
|
|
|
sufix = strrchr(fileName,'.');
|
|
if (sufix == NULL) {
|
|
cdebug << "Failed!\n";
|
|
return FALSE;
|
|
}
|
|
|
|
if ( (strcmp(sufix,".bmat")==0) || (strcmp(sufix,".BMAT")==0) ){
|
|
loadBMAT(fileName);
|
|
} else {
|
|
cdebug << "Failed!\n";
|
|
return FALSE;
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
int CMaterial::loadBMAT(char * fileName) {
|
|
FILE * matFile;
|
|
|
|
matFile = fopen(fileName,"r");
|
|
if (matFile == NULL) {
|
|
return FALSE;
|
|
}
|
|
float red,green,blue,alpha,shininess;
|
|
int matfileid,id;
|
|
|
|
while (fscanf(matFile,"%i",&matfileid)==1){
|
|
switch (matfileid){
|
|
case MAT_TEXTURE:
|
|
fscanf(matFile,"%i\n",&id);
|
|
setTextureId(id);
|
|
break;
|
|
case MAT_AMBIENT:
|
|
fscanf(matFile,"%f %f %f %f\n",&red,&green,&blue,&alpha);
|
|
setAmbient(red,green,blue,alpha);
|
|
break;
|
|
case MAT_DIFFUSE:
|
|
fscanf(matFile,"%f %f %f %f\n",&red,&green,&blue,&alpha);
|
|
setDiffuse(red,green,blue,alpha);
|
|
break;
|
|
case MAT_SPECULAR:
|
|
fscanf(matFile,"%f %f %f %f\n",&red,&green,&blue,&alpha);
|
|
setSpecular(red,green,blue,alpha);
|
|
break;
|
|
case MAT_EMISSION:
|
|
fscanf(matFile,"%f %f %f %f\n",&red,&green,&blue,&alpha);
|
|
setEmission(red,green,blue,alpha);
|
|
break;
|
|
case MAT_SHININESS:
|
|
fscanf(matFile,"%f",&shininess);
|
|
setShininess(shininess);
|
|
break;
|
|
}
|
|
}
|
|
fclose(matFile);
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
|
|
|
|
int CMaterial::save(char * name) {
|
|
FILE * matFile;
|
|
int ii;
|
|
|
|
matFile = fopen(name,"w");
|
|
if (matFile == NULL) {
|
|
return FALSE;
|
|
}
|
|
|
|
if (getTextureId() != MAT_NOTEXTURE)
|
|
fprintf(matFile,"%i %i\n",MAT_TEXTURE,getTextureId());
|
|
|
|
// Ambient
|
|
fprintf(matFile,"%i",MAT_AMBIENT);
|
|
for (ii = 0; ii < 4; ii++)
|
|
fprintf(matFile," %f",getAmbientFloat(ii));
|
|
fprintf(matFile,"\n");
|
|
|
|
// Diffuse
|
|
fprintf(matFile,"%i",MAT_DIFFUSE);
|
|
for (ii = 0; ii < 4; ii++)
|
|
fprintf(matFile," %f",getDiffuseFloat(ii));
|
|
fprintf(matFile,"\n");
|
|
|
|
// Specular
|
|
fprintf(matFile,"%i",MAT_SPECULAR);
|
|
for (ii = 0; ii < 4; ii++)
|
|
fprintf(matFile," %f",getSpecularFloat(ii));
|
|
fprintf(matFile,"\n");
|
|
|
|
// Emission
|
|
fprintf(matFile,"%i",MAT_EMISSION);
|
|
for (ii = 0; ii < 4; ii++)
|
|
fprintf(matFile," %f",getEmissionFloat(ii));
|
|
fprintf(matFile,"\n");
|
|
|
|
// Shininess
|
|
fprintf(matFile,"%i %f\n",MAT_SHININESS,getShininessFloat());
|
|
|
|
fclose(matFile);
|
|
return FALSE;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|