Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

MaterialList.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *cr
00003  *cr            (C) Copyright 1995-2008 The Board of Trustees of the
00004  *cr                        University of Illinois
00005  *cr                         All Rights Reserved
00006  *cr
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  * RCS INFORMATION:
00011  *
00012  *      $RCSfile: MaterialList.h,v $
00013  *      $Author: johns $        $Locker:  $             $State: Exp $
00014  *      $Revision: 1.21 $      $Date: 2008/03/27 19:36:40 $
00015  *
00016  ***************************************************************************
00017  * DESCRIPTION:
00018  *   Material properties list structure, master list of all materials
00019  ***************************************************************************/
00020 
00021 #ifndef MATERIAL_LIST_H__
00022 #define MATERIAL_LIST_H__
00023 
00024 #include "NameList.h"
00025 #include "ResizeArray.h"
00026 
00027 class Displayable;
00028 
00030 struct Material {
00031   float ambient, specular, diffuse, shininess, opacity;
00032   int ind;
00033 };
00034 
00035 
00037 enum MaterialProperty { 
00038   MAT_AMBIENT, MAT_SPECULAR, MAT_DIFFUSE, MAT_SHININESS, MAT_OPACITY
00039 };
00040                         
00041 
00043 class MaterialList {
00044 protected:
00045   // list of materials 
00046   NameList<Material *> *mlist;
00047  
00048   // root displayable, used to propogate changes in material settings down
00049   // to all the displayables.
00050   Displayable *root;
00051 
00052   // tell users that settings have changed 
00053   void notify(int);
00054 
00055   // counter used to create unique material names
00056   int matcounter;
00057 
00058 public:
00059   // constructor: root of displayable tree
00060   MaterialList(Displayable *);
00061   ~MaterialList();
00062 
00063   // query raw material properties
00064   // The renderers would access the material properties from the
00065   // index in the DispCmd.
00066   int num() const { return mlist->num(); }
00067   const char *material_name(int i) const { return mlist->name(i); }
00068   const Material *material(int i) const  { return mlist->data(i); }
00069 
00070   // Displayables get the index for a material here.  If the name is no longer
00071   // valid, index 0 (opaque) is returned. 
00072   int material_index(const char *nm) const { return mlist->typecode(nm); }
00073 
00074   // modify material properties - the raw values may be scaled internally
00075   void set_name(int, const char *);
00076   void set_ambient(int, float); 
00077   void set_specular(int, float); 
00078   void set_diffuse(int, float); 
00079   void set_shininess(int, float); 
00080   void set_opacity(int, float); 
00081 
00082   // query material properties, with values scaled from 0 to 1
00083   float get_ambient(int); 
00084   float get_specular(int); 
00085   float get_diffuse(int); 
00086   float get_shininess(int); 
00087   float get_opacity(int); 
00088   
00089   // Add material with given name, or use new unique name if NULL.  
00090   // Copy settings from material with given name, or use material 0 
00091   // if copyfrom is NULL.  Return name of new material, or NULL on
00092   // error.
00093   const char *add_material(const char *name, const char *copyfrom); 
00094 
00095   // delete material; return success.
00096   int delete_material(int);
00097 
00098   // restore the default value of the given material.  Return success.
00099   int restore_default(int);
00100 };
00101 
00102 #endif
00103 

Generated on Mon Sep 8 01:26:05 2008 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002