//------------------------------------------------------------
// $Id: material.cc,v 1.1.1.1 1999/11/25 06:26:12 yamauchi Exp $
//------------------------------------------------------------
//	material.cc
//	material data 
//	1996/6/11
//	Copyright (C) 1996--1998 YAMAUCHI Hitoshi
//------------------------------------------------------------
#include <string.h>
// #include "constants.h"
#include "material.h"
#include "mpi2exit.h"

// public functions
materialClass::
materialClass(void)
{
    Vector3 zero(0.0, 0.0, 0.0);
    strncpy(this->mName, NULLMaterialName, MAX_MATERIAL_NAME_LEN - 1);
    this->mDiffRef		= zero;
    this->mDiffTrans		= zero;
    this->mDiffEmit		= zero;
    this->mSpecRefCosN		= 0.0;
    this->mSpecRef		= zero;
    this->mSpecTransCosN	= 0.0;	
    this->mSpecTrans		= zero;
    this->mIdxRefraction	= 1.0;
    this->mFrustumHalfTopRad   	= 0.0;
};

materialClass::
materialClass(const materialClass& aMaterial)
{
    strncpy(this->mName, aMaterial.mName, MAX_MATERIAL_NAME_LEN - 1);
    this->mDiffRef		= aMaterial.mDiffRef;
    this->mDiffTrans		= aMaterial.mDiffTrans;
    this->mDiffEmit		= aMaterial.mDiffEmit;
    this->mSpecRefCosN		= aMaterial.mSpecRefCosN;
    this->mSpecRef		= aMaterial.mSpecRef;
    this->mSpecTransCosN	= aMaterial.mSpecTransCosN;
    this->mSpecTrans		= aMaterial.mSpecTrans;
    this->mIdxRefraction	= aMaterial.mIdxRefraction;
    this->mFrustumHalfTopRad	= aMaterial.mFrustumHalfTopRad;
}

const materialClass &materialClass::
operator=(const materialClass& aMaterial)
{
    if(this == &aMaterial)
    {
	return(*this);
    }
    this->setName(aMaterial.mName);
    this->mDiffRef		= aMaterial.mDiffRef;
    this->mDiffTrans		= aMaterial.mDiffTrans;
    this->mDiffEmit		= aMaterial.mDiffEmit;
    this->mSpecRefCosN		= aMaterial.mSpecRefCosN;
    this->mSpecRef		= aMaterial.mSpecRef;
    this->mSpecTransCosN	= aMaterial.mSpecTransCosN;
    this->mSpecTrans		= aMaterial.mSpecTrans;
    this->mIdxRefraction	= aMaterial.mIdxRefraction;
    this->mFrustumHalfTopRad	= aMaterial.mFrustumHalfTopRad;
    return(*this);    
}

ostream& operator<<(ostream& s, const materialClass& m)
{
    s << "# [material name] "    << m.mName 	 << endl;
    s << "rd " << m.mName << " " << m.mDiffRef	 << endl;
    s << "td " << m.mName << " " << m.mDiffTrans << endl;
    s << "ed " << m.mName << " " << m.mDiffEmit	 << endl;
    s << "rs " << m.mName << " " << m.mSpecRefCosN   << " " 
	<< m.mSpecRef   << endl;
    s << "ts " << m.mName << " " << m.mSpecTransCosN << " " 
	<< m.mSpecTrans << endl;
    s << "ir " << m.mName << " " << m.mIdxRefraction << endl;
    s << "fhtrad " << m.mName << " " << m.mFrustumHalfTopRad << endl;
    return(s);
}

void materialClass::
setName(const char *pName)
{
    if(strncmp(pName, NULLMaterialName, MAX_MATERIAL_NAME_LEN - 1) == 0)
    {
	cerr << "materialClass::setName can't set null material name. setting "
	    << pName << " is illegal. Please change material name." << endl;
	commMpi2_exit(1);
    }
    strncpy(this->mName, pName, MAX_MATERIAL_NAME_LEN - 1);
    
    if(strlen(pName) >= (MAX_MATERIAL_NAME_LEN - 1))
    {
	cerr << "Warning! : material name is too long, " << 
	    pName << "is changed to " << this->mName << endl;
    }
}

