2007-05-27 12:01:53 -04:00
|
|
|
// $Id$
|
|
|
|
//
|
|
|
|
// SuperTuxKart - a fun racing game with go-kart
|
|
|
|
// Copyright (C) 2004 Steve Baker <sjbaker1@airmail.net>
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License
|
2008-06-20 05:34:35 -04:00
|
|
|
// as published by the Free Software Foundation; either version 3
|
2007-05-27 12:01:53 -04:00
|
|
|
// of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
2009-06-02 08:37:29 -04:00
|
|
|
#include "graphics/material.hpp"
|
2009-02-28 19:46:47 -05:00
|
|
|
|
|
|
|
#include <stdexcept>
|
2009-01-22 17:27:13 -05:00
|
|
|
|
2009-06-11 06:00:43 -04:00
|
|
|
#include "config/stk_config.hpp"
|
2009-03-11 01:10:56 -04:00
|
|
|
#include "graphics/irr_driver.hpp"
|
2009-03-11 23:49:31 -04:00
|
|
|
#include "io/file_manager.hpp"
|
2009-03-30 22:52:01 -04:00
|
|
|
#include "io/xml_node.hpp"
|
2009-01-22 17:27:13 -05:00
|
|
|
#include "utils/string_utils.hpp"
|
2007-05-27 12:01:53 -04:00
|
|
|
|
2009-03-29 18:12:44 -04:00
|
|
|
|
2007-05-27 12:01:53 -04:00
|
|
|
#define UCLAMP 1
|
|
|
|
#define VCLAMP 2
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2009-02-26 19:15:09 -05:00
|
|
|
/** Create a new material using the parameters specified in the xml file.
|
|
|
|
* \param node Node containing the parameters for this material.
|
|
|
|
* \param index Index in material_manager.
|
|
|
|
*/
|
|
|
|
Material::Material(const XMLNode *node, int index)
|
|
|
|
{
|
|
|
|
node->get("name", &m_texname);
|
|
|
|
if(m_texname=="")
|
|
|
|
{
|
|
|
|
throw std::runtime_error("No texture name specified in %s file\n");
|
|
|
|
}
|
|
|
|
init(index);
|
|
|
|
bool b=false;
|
|
|
|
node->get("clampU", &b); if(b) m_clamp_tex +=UCLAMP;
|
|
|
|
b=false;
|
|
|
|
node->get("clampV", &b); if(b) m_clamp_tex +=VCLAMP;
|
2009-06-11 01:57:46 -04:00
|
|
|
node->get("transparency", &m_transparency );
|
|
|
|
node->get("alpha", &m_alpha_blending );
|
|
|
|
node->get("light", &m_lighting );
|
|
|
|
node->get("sphere", &m_sphere_map );
|
|
|
|
node->get("friction", &m_friction );
|
|
|
|
node->get("ignore", &m_ignore );
|
|
|
|
node->get("zipper", &m_zipper );
|
|
|
|
node->get("reset", &m_resetter );
|
|
|
|
node->get("collide", &m_collideable );
|
|
|
|
node->get("maxSpeed", &m_max_speed_fraction);
|
|
|
|
node->get("slowdownTime", &m_slowdown );
|
|
|
|
std::string s("");
|
|
|
|
node->get("graphical-effect", &s );
|
|
|
|
if(s=="water")
|
|
|
|
m_graphical_effect = GE_WATER;
|
|
|
|
else if(s=="smoke")
|
|
|
|
m_graphical_effect = GE_SMOKE;
|
|
|
|
else if (s!="")
|
|
|
|
fprintf(stderr,
|
|
|
|
"Invalid graphical effect specification: '%s' - ignored.\n",
|
|
|
|
s.c_str());
|
|
|
|
else
|
|
|
|
m_graphical_effect = GE_NONE;
|
2009-02-26 19:15:09 -05:00
|
|
|
install(/*is_full_path*/false);
|
|
|
|
} // Material
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
/** Create a standard material using the default settings for materials.
|
|
|
|
* \param fname Name of the texture file.
|
|
|
|
* \param index Unique index in material_manager.
|
|
|
|
* \param is_full_path If the fname contains the full path.
|
|
|
|
*/
|
|
|
|
Material::Material(const std::string& fname, int index, bool is_full_path)
|
|
|
|
{
|
|
|
|
m_texname = fname;
|
|
|
|
init(index);
|
|
|
|
install(is_full_path);
|
|
|
|
} // Material
|
|
|
|
|
2007-05-27 12:01:53 -04:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
Material::~Material()
|
|
|
|
{
|
2008-02-23 03:21:30 -05:00
|
|
|
} // ~Material
|
2007-05-27 12:01:53 -04:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2009-02-26 19:15:09 -05:00
|
|
|
void Material::init(unsigned int index)
|
2007-05-27 12:01:53 -04:00
|
|
|
{
|
2009-06-11 01:57:46 -04:00
|
|
|
m_index = index;
|
|
|
|
m_clamp_tex = 0;
|
|
|
|
m_transparency = false;
|
|
|
|
m_alpha_blending = false;
|
|
|
|
m_lighting = true;
|
|
|
|
m_sphere_map = false;
|
|
|
|
m_friction = 1.0f;
|
|
|
|
m_ignore = false;
|
|
|
|
m_zipper = false;
|
|
|
|
m_resetter = false;
|
|
|
|
m_collideable = true;
|
2009-01-05 19:36:56 -05:00
|
|
|
m_max_speed_fraction = 1.0f;
|
2009-01-05 21:39:30 -05:00
|
|
|
m_slowdown = stk_config->m_slowdown_factor;
|
2009-06-11 01:57:46 -04:00
|
|
|
m_graphical_effect = GE_NONE;
|
2007-05-27 12:01:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2008-02-28 22:26:07 -05:00
|
|
|
void Material::install(bool is_full_path)
|
2007-05-27 12:01:53 -04:00
|
|
|
{
|
2009-03-26 19:31:00 -04:00
|
|
|
// Avoid irrlicht warning about not being able to load texture.
|
|
|
|
m_texture = irr_driver->getTexture(file_manager->getTextureFile(m_texname));
|
2008-03-17 00:43:01 -04:00
|
|
|
|
|
|
|
// now set the name to the basename, so that all tests work as expected
|
2009-08-24 01:56:53 -04:00
|
|
|
m_texname = StringUtils::getBasename(m_texname);
|
2009-09-28 08:25:21 -04:00
|
|
|
} // install
|
2007-05-27 12:01:53 -04:00
|
|
|
|
2009-03-26 19:31:00 -04:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
/** Sets the appropriate flags in an irrlicht SMaterial.
|
|
|
|
* \param material The irrlicht SMaterial which gets the flags set.
|
|
|
|
*/
|
2009-06-02 08:06:35 -04:00
|
|
|
void Material::setMaterialProperties(video::SMaterial *m) const
|
2009-03-26 19:31:00 -04:00
|
|
|
{
|
2009-10-29 17:00:11 -04:00
|
|
|
if (m_transparency)
|
2009-03-29 09:24:54 -04:00
|
|
|
// Note: if EMT_TRANSPARENT_ALPHA_CHANNEL is used, you have to use
|
|
|
|
// scene_manager->getParameters()->setAttribute(
|
|
|
|
// scene::ALLOW_ZWRITE_ON_TRANSPARENT, true); and enable
|
|
|
|
// updates of the Z buffer of the material. Since the _REF
|
|
|
|
// approach is faster (and looks better imho), this is used for now.
|
2009-06-02 08:06:35 -04:00
|
|
|
m->MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
|
2009-10-29 17:00:11 -04:00
|
|
|
else if (m_alpha_blending)
|
2009-06-02 08:06:35 -04:00
|
|
|
m->MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
|
2009-09-28 08:25:21 -04:00
|
|
|
|
2009-10-29 17:00:11 -04:00
|
|
|
if (m_sphere_map)
|
|
|
|
m->MaterialType = video::EMT_SPHERE_MAP;
|
|
|
|
|
|
|
|
if (!m_lighting)
|
|
|
|
{
|
|
|
|
//m->setFlag( video::EMF_LIGHTING, false );
|
|
|
|
m->AmbientColor = video::SColor(255, 255, 255, 255);
|
|
|
|
m->DiffuseColor = video::SColor(255, 255, 255, 255);
|
|
|
|
m->EmissiveColor = video::SColor(255, 255, 255, 255);
|
|
|
|
m->SpecularColor = video::SColor(255, 255, 255, 255);
|
|
|
|
}
|
2009-03-26 19:31:00 -04:00
|
|
|
// FIXME: more parameters need to be set!
|
|
|
|
} // setMaterialProperties
|