Fix Bug #1309 Disabling Actor leaves Ghost, Dynamic and Rigid Body etc enabled.
[blender.git] / source / gameengine / Rasterizer / RAS_IPolygonMaterial.cpp
1 /**
2  * $Id$
3  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version. The Blender
9  * Foundation also sells licenses for use in proprietary software under
10  * the Blender License.  See http://www.blender.org/BL/ for information
11  * about this.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software Foundation,
20  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21  *
22  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
23  * All rights reserved.
24  *
25  * The Original Code is: all of this file.
26  *
27  * Contributor(s): none yet.
28  *
29  * ***** END GPL/BL DUAL LICENSE BLOCK *****
30  */
31
32 #include "RAS_IPolygonMaterial.h"
33
34 #ifdef HAVE_CONFIG_H
35 #include <config.h>
36 #endif
37
38 RAS_IPolyMaterial::RAS_IPolyMaterial(const STR_String& texname,
39                                                                          bool ba,
40                                                                          const STR_String& matname,
41                                                                          int tile,
42                                                                          int tilexrep,
43                                                                          int tileyrep,
44                                                                          int mode,
45                                                                          bool transparant,
46                                                                          bool zsort,
47                                                                          int lightlayer,
48                                                                          bool bIsTriangle,
49                                                                          void* clientobject=NULL) :
50
51                 m_texturename(texname),
52                 m_materialname(matname),
53                 m_tile(tile),
54                 m_tilexrep(tilexrep),
55                 m_tileyrep(tileyrep),
56                 m_drawingmode (mode),
57                 m_transparant(transparant),
58                 m_zsort(zsort),
59                 m_lightlayer(lightlayer),
60                 m_bIsTriangle(bIsTriangle)
61 {
62         m_shininess = 35.0;
63         m_specular = MT_Vector3(0.5,0.5,0.5);
64         m_specularity = 1.0;
65         m_diffuse = MT_Vector3(0.5,0.5,0.5);
66 }
67
68
69 bool RAS_IPolyMaterial::Equals(const RAS_IPolyMaterial& lhs) const
70 {
71         return (
72                         this->m_tile            ==              lhs.m_tile &&
73                         this->m_tilexrep        ==              lhs.m_tilexrep &&
74                         this->m_tileyrep        ==              lhs.m_tileyrep &&
75                         this->m_transparant     ==              lhs.m_transparant &&
76                         this->m_zsort           ==              lhs.m_zsort &&
77                         this->m_drawingmode     ==              lhs.m_drawingmode &&
78                         this->m_bIsTriangle     ==              lhs.m_bIsTriangle &&
79                         this->m_lightlayer  ==          lhs.m_lightlayer &&
80                         this->m_texturename.hash()      ==              lhs.m_texturename.hash() &&
81                         this->m_materialname.hash() ==          lhs.m_materialname.hash()
82         );
83 }
84
85 bool RAS_IPolyMaterial::Less(const RAS_IPolyMaterial& rhs) const
86 {
87         /**
88          * @warning STL requires lhs.Less(rhs) == rhs.Less(lhs) implies lhs.Equals(rhs).
89          * This function *must* return different values for lhs.Less(rhs) and rhs.Less(lhs) if
90          * !lhs.Equals(rhs) !!
91          */
92         if (m_materialname.hash() < rhs.m_materialname.hash())
93                 return true;
94            
95         if (m_materialname.hash() > rhs.m_materialname.hash() ||
96             m_texturename.hash()  >  rhs.m_texturename.hash())
97                 return false;
98            
99         if (m_texturename.hash() < rhs.m_texturename.hash() ||
100             m_lightlayer          < rhs.m_lightlayer)
101                 return true;
102         
103         if (m_lightlayer > rhs.m_lightlayer ||
104             m_bIsTriangle > rhs.m_bIsTriangle)
105                 return false;
106         
107         if (m_bIsTriangle < rhs.m_bIsTriangle ||
108             m_drawingmode <  rhs.m_drawingmode)
109                 return true;
110         
111         if (m_drawingmode > rhs.m_drawingmode ||
112             m_transparant > !rhs.m_transparant)
113                 return false;
114         
115         if (m_transparant < rhs.m_transparant ||
116             m_tileyrep < rhs.m_tileyrep)
117                 return true;
118         
119         if (m_tileyrep > rhs.m_tileyrep ||
120             m_tilexrep > rhs.m_tilexrep)
121                 return false;
122         
123         if (m_tilexrep < rhs.m_tilexrep ||
124             m_tile < rhs.m_tile)
125                 return true;
126         
127         return !(m_tile > rhs.m_tile ||
128                 m_zsort > rhs.m_zsort);
129 }
130
131 int RAS_IPolyMaterial::GetLightLayer() const
132 {
133         return m_lightlayer;
134 }
135
136 bool RAS_IPolyMaterial::IsTransparant() const
137 {
138         return m_transparant;
139 }
140
141 bool RAS_IPolyMaterial::IsZSort() const
142 {
143         return m_zsort;
144 }
145
146 bool RAS_IPolyMaterial::UsesTriangles() const
147 {
148         return m_bIsTriangle;
149 }
150
151 unsigned int RAS_IPolyMaterial::hash() const
152 {
153         return m_texturename.hash();
154 }
155
156 int RAS_IPolyMaterial::GetDrawingMode() const
157 {
158         return m_drawingmode;
159 }
160
161 const STR_String& RAS_IPolyMaterial::GetMaterialName() const
162
163         return m_materialname;
164 }
165
166 const STR_String& RAS_IPolyMaterial::GetTextureName() const
167 {
168         return m_texturename;
169 }