goat3d

view src/material.cc @ 87:f0277d348c2c

fixed goat3d_get_node_<position|rotation|scaling> to return only the node's transformations
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 14 May 2014 18:28:38 +0300
parents 498ca7ac7047
children
line source
1 /*
2 goat3d - 3D scene, character, and animation file format library.
3 Copyright (C) 2013-2014 John Tsiombikas <nuclear@member.fsf.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include "material.h"
20 using namespace g3dimpl;
22 MaterialAttrib Material::def_attr;
24 int Material::get_attrib_count() const
25 {
26 return (int)attrib.size();
27 }
29 const char *Material::get_attrib_name(int idx) const
30 {
31 if(idx < 0 || idx >= get_attrib_count()) {
32 return 0;
33 }
35 std::map<std::string, MaterialAttrib>::const_iterator it = attrib.begin();
36 for(int i=0; i<idx; i++) it++;
37 return it->first.c_str();
38 }
40 MaterialAttrib &Material::operator [](int idx)
41 {
42 if(idx < 0 || idx >= get_attrib_count()) {
43 return def_attr;
44 }
46 std::map<std::string, MaterialAttrib>::iterator it = attrib.begin();
47 for(int i=0; i<idx; i++) it++;
48 return it->second;
49 }
51 const MaterialAttrib &Material::operator [](int idx) const
52 {
53 if(idx < 0 || idx >= get_attrib_count()) {
54 return def_attr;
55 }
57 std::map<std::string, MaterialAttrib>::const_iterator it = attrib.begin();
58 for(int i=0; i<idx; i++) it++;
59 return it->second;
60 }
62 MaterialAttrib &Material::operator [](const std::string &name)
63 {
64 return attrib[name];
65 }
67 const MaterialAttrib &Material::operator [](const std::string &name) const
68 {
69 std::map<std::string, MaterialAttrib>::const_iterator it;
70 if((it = attrib.find(name)) != attrib.end()) {
71 return it->second;
72 }
73 return def_attr;
74 }