Back to index

supertuxkart  0.5+dfsg1
Public Member Functions | Private Member Functions | Private Attributes
Material Class Reference

#include <material.hpp>

Collaboration diagram for Material:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Material (int index)
 Material (const std::string &fname, char *description, int index, bool is_full_path=false)
 ~Material ()
int matches (char *tx)
ssgSimpleState * getState () const
bool isIgnore () const
bool isZipper () const
bool isSphereMap () const
bool isCrashable () const
bool isReset () const
float getFriction () const
const std::string & getTexFname () const
int getIndex () const
void apply ()
void force ()
void applyToLeaf (ssgLeaf *l)

Private Member Functions

bool parseBool (char **p)
int parseInt (char **p)
float parseFloat (char **p)
void init (int index)
void install (bool is_full_path=false)

Private Attributes

ssgSimpleState * m_state
ssgCallback m_predraw
ssgCallback m_postdraw
int m_index
std::string m_texname
bool m_collideable
bool m_zipper
bool m_resetter
bool m_ignore
int m_clamp_tex
bool m_lighting
bool m_sphere_map
bool m_transparency
float m_alpha_ref
float m_friction

Detailed Description

Definition at line 26 of file material.hpp.


Constructor & Destructor Documentation

Material::Material ( int  index)

Definition at line 79 of file material.cpp.

{
    m_texname = "";
    m_predraw  = m_postdraw = NULL ;

    init   (index);
    install();
}   // Material

Here is the call graph for this function:

Material::Material ( const std::string &  fname,
char *  description,
int  index,
bool  is_full_path = false 
)

Definition at line 89 of file material.cpp.

{
    m_texname = fname;
    m_predraw  = m_postdraw = NULL ;

    init (index);

    if(strlen(description)>0)
    {
        m_clamp_tex    = parseBool (&description) ? UCLAMP : 0 ;
        m_clamp_tex   += parseBool (&description) ? VCLAMP : 0 ;
        
        m_transparency = parseBool (&description);
        m_alpha_ref    = parseFloat(&description);
        m_lighting     = parseBool (&description);
        m_sphere_map   = parseBool (&description);
        m_friction     = parseFloat(&description);
        m_ignore       = parseBool (&description);
        m_zipper       = parseBool (&description);
        m_resetter     = parseBool (&description);
        m_collideable  = parseBool (&description);
    }
    install(is_full_path);
}   // Material

Here is the call graph for this function:

Definition at line 116 of file material.cpp.

{
    ssgDeRefDelete(m_state);
}   // ~Material

Member Function Documentation

void Material::apply ( ) [inline]

Definition at line 73 of file material.hpp.

{ m_state ->apply();    }

Here is the caller graph for this function:

void Material::applyToLeaf ( ssgLeaf *  l)

Definition at line 138 of file material.cpp.

{
    if ( m_predraw  ) l -> setCallback ( SSG_CALLBACK_PREDRAW , m_predraw  ) ;
    if ( m_postdraw ) l -> setCallback ( SSG_CALLBACK_POSTDRAW, m_postdraw ) ;
}   // applyToLeaf
void Material::force ( ) [inline]

Definition at line 74 of file material.hpp.

{ m_state ->force();    }
float Material::getFriction ( ) const [inline]

Definition at line 69 of file material.hpp.

{ return m_friction;    }

Here is the caller graph for this function:

int Material::getIndex ( ) const [inline]

Definition at line 72 of file material.hpp.

{ return m_index;       }
ssgSimpleState* Material::getState ( ) const [inline]

Definition at line 63 of file material.hpp.

{ return m_state ;      }

Here is the caller graph for this function:

const std::string& Material::getTexFname ( ) const [inline]

Definition at line 71 of file material.hpp.

{ return m_texname;     }
void Material::init ( int  index) [private]

Definition at line 122 of file material.cpp.

{
    m_index        = index ;
    m_clamp_tex    = 0     ;
    m_transparency = false ;
    m_alpha_ref    = 0.1f  ;
    m_lighting     = true  ;
    m_sphere_map   = false ;
    m_friction     = 1.0f  ;
    m_ignore       = false ;
    m_zipper       = false ;
    m_resetter     = false ;
    m_collideable  = true  ;
}

Here is the caller graph for this function:

void Material::install ( bool  is_full_path = false) [private]

Definition at line 145 of file material.cpp.

{
    if ( isSphereMap () )
    {
        m_predraw  =   setSpheremap ;
        m_postdraw = clearSpheremap ;
    }

    m_state = new ssgSimpleState ;

    m_state -> ref () ;
    m_state -> setExternalPropertyIndex ( m_index ) ;
    if ( m_texname.size()>0 )
    {
        std::string fn=is_full_path ? m_texname 
                                    : file_manager->getTextureFile(m_texname);
        if(fn=="")
        {
            fprintf(stderr, "WARNING: texture '%s' not found.\n", 
                    m_texname.c_str());
        }
        m_state -> setTexture ( fn.c_str(), !(m_clamp_tex & UCLAMP),
                              !(m_clamp_tex & VCLAMP) );
        m_state -> enable  ( GL_TEXTURE_2D ) ;
    }
    else
        m_state -> disable ( GL_TEXTURE_2D ) ;

    if ( m_lighting )
        m_state -> enable  ( GL_LIGHTING ) ;
    else
        m_state -> disable ( GL_LIGHTING ) ;

    m_state -> setShadeModel ( GL_SMOOTH ) ;
    m_state -> enable        ( GL_COLOR_MATERIAL ) ;
    m_state -> enable        ( GL_CULL_FACE      ) ;
    m_state -> setColourMaterial ( GL_AMBIENT_AND_DIFFUSE ) ;
    m_state -> setMaterial   ( GL_EMISSION, 0, 0, 0, 1 ) ;
    m_state -> setMaterial   ( GL_SPECULAR, 0, 0, 0, 1 ) ;
    m_state -> setShininess  ( 0 ) ;

    if ( m_transparency )
    {
        m_state -> setTranslucent () ;
        m_state -> enable         ( GL_ALPHA_TEST ) ;
        m_state -> setAlphaClamp  ( m_alpha_ref ) ;
        m_state -> enable         ( GL_BLEND ) ;
    }
    else
    {
        m_state -> setOpaque () ;
        m_state -> disable   ( GL_BLEND ) ;
    }

    // now set the name to the basename, so that all tests work as expected
    m_texname  = StringUtils::basename(m_texname);
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool Material::isCrashable ( ) const [inline]

Definition at line 67 of file material.hpp.

{ return m_collideable; }
bool Material::isIgnore ( ) const [inline]

Definition at line 64 of file material.hpp.

{ return m_ignore;      }

Here is the caller graph for this function:

bool Material::isReset ( ) const [inline]

Definition at line 68 of file material.hpp.

{ return m_resetter;    }

Here is the caller graph for this function:

bool Material::isSphereMap ( ) const [inline]

Definition at line 66 of file material.hpp.

{ return m_sphere_map;  }

Here is the caller graph for this function:

bool Material::isZipper ( ) const [inline]

Definition at line 65 of file material.hpp.

{ return m_zipper;      }

Here is the caller graph for this function:

int Material::matches ( char *  tx)
bool Material::parseBool ( char **  p) [private]

Definition at line 45 of file material.cpp.

{
    /* Skip leading spaces */

    while ( **p <= ' ' && **p != '\0' ) (*p)++ ;

    const bool RES = ( ( **p == 'Y' ) || ( **p == 'y' ) ) ;

    while ( **p > ' ' && **p != '\0' ) (*p)++ ;

    return RES ;
}   // parseBool

Here is the caller graph for this function:

float Material::parseFloat ( char **  p) [private]

Definition at line 69 of file material.cpp.

{
    /* Skip leading spaces */

    while ( **p <= ' ' && **p != '\0' ) (*p)++ ;

    return (float)strtod ( *p, p ) ;
}   // parseFloat 

Here is the caller graph for this function:

int Material::parseInt ( char **  p) [private]

Definition at line 59 of file material.cpp.

{
    /* Skip leading spaces */

    while ( **p <= ' ' && **p != '\0' ) (*p)++ ;

    return strtol ( *p, p, 0 ) ;
}   // parseInt 

Member Data Documentation

float Material::m_alpha_ref [private]

Definition at line 42 of file material.hpp.

int Material::m_clamp_tex [private]

Definition at line 38 of file material.hpp.

bool Material::m_collideable [private]

Definition at line 34 of file material.hpp.

float Material::m_friction [private]

Definition at line 43 of file material.hpp.

bool Material::m_ignore [private]

Definition at line 37 of file material.hpp.

int Material::m_index [private]

Definition at line 32 of file material.hpp.

bool Material::m_lighting [private]

Definition at line 39 of file material.hpp.

ssgCallback Material::m_postdraw [private]

Definition at line 31 of file material.hpp.

ssgCallback Material::m_predraw [private]

Definition at line 30 of file material.hpp.

bool Material::m_resetter [private]

Definition at line 36 of file material.hpp.

bool Material::m_sphere_map [private]

Definition at line 40 of file material.hpp.

ssgSimpleState* Material::m_state [private]

Definition at line 29 of file material.hpp.

std::string Material::m_texname [private]

Definition at line 33 of file material.hpp.

bool Material::m_transparency [private]

Definition at line 41 of file material.hpp.

bool Material::m_zipper [private]

Definition at line 35 of file material.hpp.


The documentation for this class was generated from the following files: