goat3d

diff src/material.cc @ 9:04bb114fcf05

implementing Scene::save, lots to do still
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 23 Aug 2013 06:36:47 +0300
parents
children f1b4c27382ce
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/material.cc	Fri Aug 23 06:36:47 2013 +0300
     1.3 @@ -0,0 +1,54 @@
     1.4 +#include "material.h"
     1.5 +
     1.6 +int Material::get_attrib_count() const
     1.7 +{
     1.8 +	return (int)attrib.size();
     1.9 +}
    1.10 +
    1.11 +const char *Material::get_attrib_name(int idx) const
    1.12 +{
    1.13 +	if(idx < 0 || idx >= get_attrib_count()) {
    1.14 +		return 0;
    1.15 +	}
    1.16 +
    1.17 +	std::map<std::string, MaterialAttrib>::const_iterator it = attrib.begin();
    1.18 +	for(int i=0; i<idx; i++) it++;
    1.19 +	return it->first.c_str();
    1.20 +}
    1.21 +
    1.22 +MaterialAttrib &Material::operator [](int idx)
    1.23 +{
    1.24 +	if(idx < 0 || idx >= get_attrib_count()) {
    1.25 +		return def_attr;
    1.26 +	}
    1.27 +
    1.28 +	std::map<std::string, MaterialAttrib>::iterator it = attrib.begin();
    1.29 +	for(int i=0; i<idx; i++) it++;
    1.30 +	return it->second;
    1.31 +}
    1.32 +
    1.33 +const MaterialAttrib &Material::operator [](int idx) const
    1.34 +{
    1.35 +	if(idx < 0 || idx >= get_attrib_count()) {
    1.36 +		return def_attr;
    1.37 +	}
    1.38 +
    1.39 +	std::map<std::string, MaterialAttrib>::const_iterator it = attrib.begin();
    1.40 +	for(int i=0; i<idx; i++) it++;
    1.41 +	return it->second;
    1.42 +}
    1.43 +
    1.44 +MaterialAttrib &Material::operator [](const std::string &name)
    1.45 +{
    1.46 +	return attrib[name];
    1.47 +}
    1.48 +
    1.49 +const MaterialAttrib &Material::operator [](const std::string &name) const
    1.50 +{
    1.51 +	std::map<std::string, MaterialAttrib>::const_iterator it;
    1.52 +	if((it = attrib.find(name)) != attrib.end()) {
    1.53 +		return it->second;
    1.54 +	}
    1.55 +	return def_attr;
    1.56 +}
    1.57 +