00001 /******************************************************************************* 00002 Copyright (c) 2005-2009 David Williams 00003 00004 This software is provided 'as-is', without any express or implied 00005 warranty. In no event will the authors be held liable for any damages 00006 arising from the use of this software. 00007 00008 Permission is granted to anyone to use this software for any purpose, 00009 including commercial applications, and to alter it and redistribute it 00010 freely, subject to the following restrictions: 00011 00012 1. The origin of this software must not be misrepresented; you must not 00013 claim that you wrote the original software. If you use this software 00014 in a product, an acknowledgment in the product documentation would be 00015 appreciated but is not required. 00016 00017 2. Altered source versions must be plainly marked as such, and must not be 00018 misrepresented as being the original software. 00019 00020 3. This notice may not be removed or altered from any source 00021 distribution. 00022 *******************************************************************************/ 00023 00024 #ifndef __PolyVox_Material_H__ 00025 #define __PolyVox_Material_H__ 00026 00027 #include "PolyVoxImpl/TypeDef.h" 00028 00029 #include <cassert> 00030 00031 namespace PolyVox 00032 { 00046 template <typename MaterialType> 00047 class Material 00048 { 00049 public: 00050 Material() : m_uMaterial(0) {} 00051 Material(MaterialType uMaterial) : m_uMaterial(uMaterial) {} 00052 00053 bool operator==(const Material& rhs) const throw() 00054 { 00055 return (m_uMaterial == rhs.m_uMaterial); 00056 }; 00057 00058 bool operator!=(const Material& rhs) const throw() 00059 { 00060 return !(*this == rhs); 00061 } 00062 00063 uint32_t getDensity() const throw() 00064 { 00065 //We don't actually have a density, so make one up based on the material. 00066 if(m_uMaterial == 0) 00067 { 00068 return getMinDensity(); 00069 } 00070 else 00071 { 00072 return getMaxDensity(); 00073 } 00074 } 00075 00076 MaterialType getMaterial() const throw() { return m_uMaterial; } 00077 00078 void setDensity(uint32_t /*uDensity*/) { assert(false); } //Cannot set density on voxel of type Material 00079 void setMaterial(MaterialType uMaterial) { m_uMaterial = uMaterial; } 00080 00081 static uint32_t getMaxDensity() throw() { return 2; } 00082 static uint32_t getMinDensity() throw() { return 0; } 00083 static uint32_t getThreshold() throw() { return 1; } 00084 00085 private: 00086 MaterialType m_uMaterial; 00087 }; 00088 00089 typedef Material<uint8_t> Material8; 00090 typedef Material<uint16_t> Material16; 00091 typedef Material<uint32_t> Material32; 00092 } 00093 00094 #endif //__PolyVox_Material_H__