Logo
  • Main Page
  • Related Pages
  • Modules
  • Classes
  • Files

mms3dmaterial.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005-2007 Stefan Schwarzer, Jens Schneider,             *
00003  *                           Matthias Hardt, Guido Madaus                  *
00004  *                                                                         *
00005  *   Copyright (C) 2007-2008 BerLinux Solutions GbR                        *
00006  *                           Stefan Schwarzer & Guido Madaus               *
00007  *                                                                         *
00008  *   Copyright (C) 2009-2013 BerLinux Solutions GmbH                       *
00009  *                                                                         *
00010  *   Authors:                                                              *
00011  *      Stefan Schwarzer   <stefan.schwarzer@diskohq.org>,                 *
00012  *      Matthias Hardt     <matthias.hardt@diskohq.org>,                   *
00013  *      Jens Schneider     <jens.schneider@diskohq.org>,                   *
00014  *      Guido Madaus       <guido.madaus@diskohq.org>,                     *
00015  *      Patrick Helterhoff <patrick.helterhoff@diskohq.org>,               *
00016  *      René Bählkow       <rene.baehlkow@diskohq.org>                     *
00017  *                                                                         *
00018  *   This library is free software; you can redistribute it and/or         *
00019  *   modify it under the terms of the GNU Lesser General Public            *
00020  *   License version 2.1 as published by the Free Software Foundation.     *
00021  *                                                                         *
00022  *   This library is distributed in the hope that it will be useful,       *
00023  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00024  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00025  *   Lesser General Public License for more details.                       *
00026  *                                                                         *
00027  *   You should have received a copy of the GNU Lesser General Public      *
00028  *   License along with this library; if not, write to the                 *
00029  *   Free Software Foundation, Inc.,                                       *
00030  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
00031  **************************************************************************/
00032 
00033 #include "mmsgui/3d/mms3dmaterial.h"
00034 
00035 //! number of user defined materials
00036 int MMS3DMaterial::material_cnt = 0;
00037 
00038 //! materials
00039 MMS3D_MATERIAL MMS3DMaterial::mat_buffer[MMS3DMaterial::MAT_SIZE] = {
00040     // init space for user defined materials
00041         {0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},
00042         {0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},
00043         {0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},
00044         {0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},
00045         {0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},
00046         {0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},
00047         {0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},
00048         {0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},
00049         {0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},
00050         {0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},
00051         {0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},
00052         {0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},
00053         {0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},
00054         {0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},
00055         {0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},
00056         {0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},
00057 
00058     // basic colors ---- Emission ----------  Ambient -----------  Diffuse -----------  Specular ----------  Shininess -
00059     // ----------------- Re   Ge   Be   Ae    Ra   Ga   Ba   Aa    Rd   Gd   Bd   Ad    Rs   Gs   Bs   As
00060                         {0.00,0.00,0.00,1.00, 0.00,0.00,0.00,1.00, 0.00,0.00,0.00,1.00, 0.00,0.00,0.00,1.00, 0.000},
00061                         {0.00,0.00,0.00,1.00, 0.50,0.00,0.00,1.00, 1.00,0.00,0.00,1.00, 0.00,0.00,0.00,1.00, 0.000},
00062                         {0.00,0.00,0.00,1.00, 0.00,0.50,0.00,1.00, 0.00,1.00,0.00,1.00, 0.00,0.00,0.00,1.00, 0.000},
00063                         {0.00,0.00,0.00,1.00, 0.00,0.00,0.50,1.00, 0.00,0.00,1.00,1.00, 0.00,0.00,0.00,1.00, 0.000},
00064                         {0.00,0.00,0.00,1.00, 0.50,0.50,0.00,1.00, 1.00,1.00,0.00,1.00, 0.00,0.00,0.00,1.00, 0.000},
00065                         {0.00,0.00,0.00,1.00, 0.00,0.50,0.50,1.00, 0.00,1.00,1.00,1.00, 0.00,0.00,0.00,1.00, 0.000},
00066                         {0.00,0.00,0.00,1.00, 0.50,0.00,0.50,1.00, 1.00,0.00,1.00,1.00, 0.00,0.00,0.00,1.00, 0.000},
00067                         {0.00,0.00,0.00,1.00, 0.50,0.50,0.50,1.00, 1.00,1.00,1.00,1.00, 0.00,0.00,0.00,1.00, 0.000},
00068 
00069     // gemstone / ------ Emission ----------  Ambient -----------  Diffuse -----------  Specular ----------  Shininess -
00070     // glass ----------- Re   Ge   Be   Ae    Ra   Ga   Ba   Aa    Rd   Gd   Bd   Ad    Rs   Gs   Bs   As
00071                         {0.00,0.00,0.00,1.00, 0.14,0.22,0.16,1.00, 0.54,0.89,0.63,1.00, 0.32,0.32,0.32,1.00, 0.100},
00072                         {0.00,0.00,0.00,1.00, 0.14,0.22,0.16,0.90, 0.54,0.89,0.63,0.90, 0.32,0.32,0.32,0.90, 0.100},
00073                         {0.00,0.00,0.00,1.00, 0.05,0.05,0.07,1.00, 0.18,0.17,0.23,1.00, 0.33,0.33,0.35,1.00, 0.300},
00074                         {0.00,0.00,0.00,1.00, 0.05,0.05,0.07,0.80, 0.18,0.17,0.23,0.80, 0.33,0.33,0.35,0.80, 0.300},
00075                         {0.00,0.00,0.00,1.00, 0.25,0.21,0.21,1.00, 0.99,0.83,0.83,1.00, 0.30,0.30,0.30,1.00, 0.088},
00076                         {0.00,0.00,0.00,1.00, 0.25,0.21,0.21,0.90, 0.99,0.83,0.83,0.90, 0.30,0.30,0.30,0.90, 0.088},
00077                         {0.00,0.00,0.00,1.00, 0.17,0.01,0.01,1.00, 0.61,0.04,0.04,1.00, 0.73,0.63,0.63,1.00, 0.600},
00078                         {0.00,0.00,0.00,1.00, 0.17,0.01,0.01,0.50, 0.61,0.04,0.04,0.50, 0.73,0.63,0.63,0.50, 0.600},
00079                         {0.00,0.00,0.00,1.00, 0.02,0.17,0.02,1.00, 0.08,0.61,0.08,1.00, 0.63,0.73,0.63,1.00, 0.600},
00080                         {0.00,0.00,0.00,1.00, 0.02,0.17,0.02,0.50, 0.08,0.61,0.08,0.50, 0.63,0.73,0.63,0.50, 0.600},
00081                         {0.00,0.00,0.00,1.00, 0.10,0.19,0.17,1.00, 0.40,0.74,0.69,1.00, 0.30,0.31,0.31,1.00, 0.100},
00082                         {0.00,0.00,0.00,1.00, 0.10,0.19,0.17,0.80, 0.40,0.74,0.69,0.80, 0.30,0.31,0.31,0.80, 0.100},
00083 
00084     // synthetic ------- Emission ----------  Ambient -----------  Diffuse -----------  Specular ----------  Shininess -
00085     // ----------------- Re   Ge   Be   Ae    Ra   Ga   Ba   Aa    Rd   Gd   Bd   Ad    Rs   Gs   Bs   As
00086                         {0.00,0.00,0.00,1.00, 0.00,0.00,0.00,1.00, 0.01,0.01,0.01,1.00, 0.50,0.50,0.50,1.00, 0.250},
00087                         {0.00,0.00,0.00,1.00, 0.00,0.00,0.00,1.00, 0.50,0.00,0.00,1.00, 0.70,0.60,0.60,1.00, 0.250},
00088                         {0.00,0.00,0.00,1.00, 0.00,0.00,0.00,1.00, 0.10,0.35,0.10,1.00, 0.45,0.55,0.45,1.00, 0.250},
00089                         {0.00,0.00,0.00,1.00, 0.00,0.00,0.00,1.00, 0.00,0.00,0.50,1.00, 0.60,0.60,0.70,1.00, 0.250},
00090                         {0.00,0.00,0.00,1.00, 0.00,0.00,0.00,1.00, 0.50,0.50,0.00,1.00, 0.60,0.60,0.50,1.00, 0.250},
00091                         {0.00,0.00,0.00,1.00, 0.00,0.10,0.06,1.00, 0.00,0.51,0.51,1.00, 0.50,0.50,0.50,1.00, 0.250},
00092                         {0.00,0.00,0.00,1.00, 0.06,0.00,0.06,1.00, 0.51,0.00,0.51,1.00, 0.50,0.50,0.50,1.00, 0.250},
00093                         {0.00,0.00,0.00,1.00, 0.00,0.00,0.00,1.00, 0.55,0.55,0.55,1.00, 0.70,0.70,0.70,1.00, 0.250},
00094                         {0.00,0.00,0.00,1.00, 0.02,0.02,0.02,1.00, 0.01,0.01,0.01,1.00, 0.40,0.40,0.40,1.00, 0.078},
00095                         {0.00,0.00,0.00,1.00, 0.05,0.00,0.00,1.00, 0.50,0.40,0.40,1.00, 0.70,0.04,0.04,1.00, 0.078},
00096                         {0.00,0.00,0.00,1.00, 0.00,0.05,0.00,1.00, 0.40,0.50,0.40,1.00, 0.04,0.70,0.04,1.00, 0.078},
00097                         {0.00,0.00,0.00,1.00, 0.00,0.00,0.05,1.00, 0.40,0.40,0.50,1.00, 0.04,0.04,0.70,1.00, 0.078},
00098                         {0.00,0.00,0.00,1.00, 0.05,0.05,0.00,1.00, 0.50,0.50,0.40,1.00, 0.70,0.70,0.04,1.00, 0.078},
00099                         {0.00,0.00,0.00,1.00, 0.00,0.05,0.05,1.00, 0.40,0.50,0.50,1.00, 0.04,0.70,0.70,1.00, 0.078},
00100                         {0.00,0.00,0.00,1.00, 0.05,0.00,0.05,1.00, 0.50,0.40,0.50,1.00, 0.70,0.04,0.70,1.00, 0.078},
00101                         {0.00,0.00,0.00,1.00, 0.05,0.05,0.05,1.00, 0.50,0.50,0.50,1.00, 0.70,0.70,0.70,1.00, 0.078},
00102 
00103     // metal ----------- Emission ----------  Ambient -----------  Diffuse -----------  Specular ----------  Shininess -
00104     // ----------------- Re   Ge   Be   Ae    Ra   Ga   Ba   Aa    Rd   Gd   Bd   Ad    Rs   Gs   Bs   As
00105                         {0.00,0.00,0.00,1.00, 0.21,0.13,0.05,1.00, 0.71,0.43,0.18,1.00, 0.39,0.27,0.17,1.00, 0.200},
00106                         {0.00,0.00,0.00,1.00, 0.25,0.15,0.06,1.00, 0.40,0.24,0.10,1.00, 0.77,0.46,0.20,1.00, 0.600},
00107                         {0.00,0.00,0.00,1.00, 0.25,0.25,0.25,1.00, 0.40,0.40,0.40,1.00, 0.77,0.77,0.77,1.00, 0.600},
00108                         {0.00,0.00,0.00,1.00, 0.25,0.20,0.07,1.00, 0.75,0.61,0.23,1.00, 0.63,0.65,0.37,1.00, 0.400},
00109                         {0.00,0.00,0.00,1.00, 0.25,0.22,0.06,1.00, 0.35,0.31,0.09,1.00, 0.80,0.72,0.21,1.00, 0.650},
00110                         {0.00,0.00,0.00,1.00, 0.19,0.07,0.02,1.00, 0.70,0.27,0.08,1.00, 0.26,0.14,0.09,1.00, 0.100},
00111                         {0.00,0.00,0.00,1.00, 0.23,0.09,0.03,1.00, 0.55,0.21,0.07,1.00, 0.58,0.22,0.07,1.00, 0.400},
00112                         {0.00,0.00,0.00,1.00, 0.33,0.22,0.03,1.00, 0.78,0.57,0.11,1.00, 0.99,0.94,0.81,1.00, 0.218},
00113                         {0.00,0.00,0.00,1.00, 0.19,0.19,0.19,1.00, 0.51,0.51,0.51,1.00, 0.51,0.51,0.51,1.00, 0.400},
00114                         {0.00,0.00,0.00,1.00, 0.23,0.23,0.23,1.00, 0.28,0.28,0.28,1.00, 0.77,0.77,0.77,1.00, 0.700},
00115                         {0.00,0.00,0.00,1.00, 0.11,0.06,0.11,1.00, 0.43,0.47,0.54,1.00, 0.33,0.33,0.52,1.00, 0.077}
00116 };
00117 
00118 
00119 MMS3DMaterial::MMS3DMaterial() {
00120 }
00121 
00122 void MMS3DMaterial::getBuffer(MMS3D_MATERIAL **mat_buffer) {
00123     *mat_buffer = this->mat_buffer;
00124 }
00125 
00126 int MMS3DMaterial::genMaterial(MMSFBColor emission, MMSFBColor ambient, MMSFBColor diffuse, MMSFBColor specular, unsigned char shininess) {
00127     if (this->material_cnt > MAT_MAX_USER_DEFINED) {
00128         // buffer is full
00129         return MAT_NOTSET;
00130     }
00131 
00132     // convert to float, range 0..1
00133     mat_buffer[this->material_cnt].s.emission.r = (float)emission.r / 255;
00134     mat_buffer[this->material_cnt].s.emission.g = (float)emission.g / 255;
00135     mat_buffer[this->material_cnt].s.emission.b = (float)emission.b / 255;
00136     mat_buffer[this->material_cnt].s.emission.a = (float)emission.a / 255;
00137     mat_buffer[this->material_cnt].s.ambient.r  = (float)ambient.r / 255;
00138     mat_buffer[this->material_cnt].s.ambient.g  = (float)ambient.g / 255;
00139     mat_buffer[this->material_cnt].s.ambient.b  = (float)ambient.b / 255;
00140     mat_buffer[this->material_cnt].s.ambient.a  = (float)ambient.a / 255;
00141     mat_buffer[this->material_cnt].s.diffuse.r  = (float)diffuse.r / 255;
00142     mat_buffer[this->material_cnt].s.diffuse.g  = (float)diffuse.g / 255;
00143     mat_buffer[this->material_cnt].s.diffuse.b  = (float)diffuse.b / 255;
00144     mat_buffer[this->material_cnt].s.diffuse.a  = (float)diffuse.a / 255;
00145     mat_buffer[this->material_cnt].s.specular.r = (float)specular.r / 255;
00146     mat_buffer[this->material_cnt].s.specular.g = (float)specular.g / 255;
00147     mat_buffer[this->material_cnt].s.specular.b = (float)specular.b / 255;
00148     mat_buffer[this->material_cnt].s.specular.a = (float)specular.a / 255;
00149     mat_buffer[this->material_cnt].s.shininess  = (float)shininess / 255;
00150     this->material_cnt++;
00151     return this->material_cnt - 1;
00152 }
00153 
00154 
00155 

Generated by doxygen