185 lines
4.2 KiB
C
185 lines
4.2 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 "pvvmud.H"
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
|
|
#include "material.H"
|
|
|
|
|
|
CMaterial::CMaterial(){
|
|
m_id = -1;
|
|
m_textureId = MAT_NOTEXTURE;
|
|
setAmbient(0.2,0.2,0.2,1.0);
|
|
setDiffuse(0.8,0.8,0.8,1.0);
|
|
setSpecular(0.0,0.0,0.0,1.0);
|
|
setShininess(0.0F);
|
|
setEmission(0.0,0.0,0.0,1.0);
|
|
}
|
|
|
|
CMaterial::CMaterial(int materialId){
|
|
m_id = materialId;
|
|
m_textureId = MAT_NOTEXTURE;
|
|
setAmbient(0.2,0.2,0.2,1.0);
|
|
setDiffuse(0.8,0.8,0.8,1.0);
|
|
setSpecular(0.0,0.0,0.0,1.0);
|
|
setShininess(0.0F);
|
|
setEmission(0.0,0.0,0.0,1.0);
|
|
}
|
|
|
|
CMaterial::CMaterial(int materialId, char * name){
|
|
m_id = materialId;
|
|
CMaterial(m_id);
|
|
load(name);
|
|
}
|
|
|
|
void CMaterial::setId(int materialId){
|
|
m_id = materialId;
|
|
}
|
|
|
|
|
|
void CMaterial::RGBA_SetColor(RGBA_t rgba,float red, float green, float blue, float alpha){
|
|
rgba[0] = red;
|
|
rgba[1] = green;
|
|
rgba[2] = blue;
|
|
rgba[3] = alpha;
|
|
}
|
|
|
|
void CMaterial::RGBA_Print(RGBA_t rgba){
|
|
printf("%f %f %f %fi\n",rgba[0],rgba[1],rgba[2],rgba[3]);
|
|
}
|
|
|
|
void CMaterial::setTextureId(int textureId){
|
|
m_textureId = textureId;
|
|
}
|
|
|
|
int CMaterial::getTextureId() {
|
|
return m_textureId;
|
|
}
|
|
|
|
|
|
void CMaterial::setAmbient(float red, float green, float blue, float alpha){
|
|
RGBA_SetColor(m_ambient,red,green,blue,alpha);
|
|
}
|
|
|
|
void CMaterial::setDiffuse(float red, float green, float blue, float alpha){
|
|
RGBA_SetColor(m_diffuse,red,green,blue,alpha);
|
|
}
|
|
|
|
void CMaterial::setSpecular(float red, float green, float blue, float alpha){
|
|
RGBA_SetColor(m_specular,red,green,blue,alpha);
|
|
}
|
|
|
|
void CMaterial::setShininess(float shininess){
|
|
m_shininess[0] = shininess;
|
|
}
|
|
|
|
void CMaterial::setEmission(float red, float green, float blue, float alpha){
|
|
RGBA_SetColor(m_emission,red,green,blue,alpha);
|
|
}
|
|
|
|
BYTE CMaterial::getAmbientByte(int num){
|
|
return (BYTE)(m_ambient[num]*255.0F);
|
|
}
|
|
|
|
BYTE CMaterial::getDiffuseByte(int num){
|
|
return (BYTE)(m_diffuse[num]*255.0F);
|
|
}
|
|
|
|
BYTE CMaterial::getSpecularByte(int num){
|
|
return (BYTE)(m_specular[num]*255.0F);
|
|
}
|
|
|
|
BYTE CMaterial::getEmissionByte(int num){
|
|
return (BYTE)(m_emission[num]*255.0F);
|
|
}
|
|
|
|
BYTE CMaterial::getShininessByte(){
|
|
return (BYTE)(m_shininess[0]*255.0F);
|
|
}
|
|
|
|
float CMaterial::getAmbientFloat(int num){
|
|
return m_ambient[num];
|
|
}
|
|
|
|
float CMaterial::getDiffuseFloat(int num){
|
|
return m_diffuse[num];
|
|
}
|
|
|
|
float CMaterial::getSpecularFloat(int num){
|
|
return m_specular[num];
|
|
}
|
|
|
|
float CMaterial::getEmissionFloat(int num){
|
|
return m_emission[num];
|
|
}
|
|
|
|
float CMaterial::getShininessFloat(){
|
|
return m_shininess[0];
|
|
}
|
|
|
|
void CMaterial::setAmbient(int num,BYTE value){
|
|
m_ambient[num] = (float)(value) * (1.0F / 255.0F);
|
|
}
|
|
|
|
void CMaterial::setDiffuse(int num,BYTE value){
|
|
m_diffuse[num] = (float)(value) * (1.0F / 255.0F);
|
|
}
|
|
|
|
void CMaterial::setSpecular(int num,BYTE value){
|
|
m_specular[num] = (float)(value) * (1.0F / 255.0F);
|
|
}
|
|
|
|
void CMaterial::setEmission(int num,BYTE value){
|
|
m_emission[num] = (float)(value) * (1.0F / 255.0F);
|
|
}
|
|
|
|
void CMaterial::setShininess(BYTE value){
|
|
m_shininess[0] = (float)(value) * (1.0F / 255.0F);
|
|
}
|
|
|
|
int CMaterial::exec(CTextureCache * texCache){
|
|
return FALSE;
|
|
}
|
|
|
|
|
|
/******************************************************************************
|
|
*
|
|
*
|
|
* Add material to MaterialCache
|
|
*
|
|
******************************************************************************/
|
|
|
|
CMaterialCache::CMaterialCache():CCache(){
|
|
}
|
|
|
|
CMaterial* CMaterialCache::add(CMaterial * mat) {
|
|
return (CMaterial*)CCache::add(mat->getId(),mat);
|
|
}
|
|
|
|
CMaterial * CMaterialCache::get(int id){
|
|
return (CMaterial*)CCache::get(id);
|
|
}
|
|
|
|
|
|
|
|
|
|
|