• Skip to content
  • Skip to link menu
KDE 4.0 API Reference
  • KDE API Reference
  • kdeedu
  • Sitemap
  • Contact Us
 

kalzium

color.cpp

Go to the documentation of this file.
00001 /**********************************************************************
00002   Color - Class for handling color changes in OpenGL
00003 
00004   Copyright (C) 2006 Benoit Jacob <jacob@math.jussieu.fr>
00005   Copyright (C) 2007 Geoffrey R. Hutchison <geoff@geoffhutchison.net>
00006 
00007   This file is part of the Avogadro molecular editor project.
00008   For more information, see <http://avogadro.sourceforge.net/>
00009 
00010   Avogadro is free software; you can redistribute it and/or modify 
00011   it under the terms of the GNU General Public License as published by 
00012   the Free Software Foundation; either version 2 of the License, or 
00013   (at your option) any later version.
00014 
00015   Avogadro is distributed in the hope that it will be useful,
00016   but WITHOUT ANY WARRANTY; without even the implied warranty of
00017   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018   GNU General Public License for more details.
00019 
00020   You should have received a copy of the GNU General Public License
00021   along with this program; if not, write to the Free Software
00022   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00023   02110-1301, USA.
00024  **********************************************************************/
00025 
00026 #include <config.h>
00027 
00028 #include <avogadro/color.h>
00029 
00030 using namespace OpenBabel;
00031 
00032 namespace Avogadro {
00033 
00034 Color::Color( GLfloat red, GLfloat green, GLfloat blue,
00035                   GLfloat alpha )
00036 {
00037   set(red, green, blue, alpha);
00038 }
00039 
00040 Color::Color( const OBAtom* atom )
00041 {
00042   set(atom);
00043 }
00044 
00045 Color& Color::operator=( const Color& other )
00046 {
00047     m_red = other.m_red;
00048     m_green = other.m_green;
00049     m_blue = other.m_blue;
00050     m_alpha = other.m_alpha;
00051 
00052     return *this;
00053 }
00054   
00055 void Color::set(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
00056 {
00057   m_red = red;
00058   m_green = green;
00059   m_blue = blue;
00060   m_alpha = alpha;
00061 }
00062 
00063 void Color::set(const OpenBabel::OBAtom *atom)
00064 {
00065   if (!atom)
00066     return;
00067 
00068     std::vector<double> rgb = etab.GetRGB( atom->GetAtomicNum() );
00069     m_red = rgb[0];
00070     m_green = rgb[1];
00071     m_blue = rgb[2];
00072     m_alpha = 1.0;
00073 }
00074 
00075 void Color::set(double value, double low, double high)
00076 {
00077   Q_UNUSED(value);
00078   Q_UNUSED(low);
00079   Q_UNUSED(high);
00080   m_red = m_green = m_blue = m_alpha = 1.0;
00081 }
00082 
00083 void Color::applyAsMaterials()
00084 {
00085     GLfloat ambientColor [] = { m_red / 3, m_green / 3, m_blue / 3,
00086                                 m_alpha };
00087     GLfloat diffuseColor [] = { m_red, m_green, m_blue, m_alpha };
00088 
00089     float s = ( 0.5 + fabsf( m_red - m_green )
00090         + fabsf( m_blue - m_green ) + fabsf( m_blue - m_red ) ) / 4.0;
00091 
00092     float t = 1.0 - s;
00093 
00094     GLfloat specularColor [] = { s + t * m_red,
00095         s + t * m_green,
00096         s + t * m_blue,
00097         m_alpha };
00098 
00099     glMaterialfv( GL_FRONT, GL_AMBIENT, ambientColor );
00100     glMaterialfv( GL_FRONT, GL_DIFFUSE, diffuseColor );
00101     glMaterialfv( GL_FRONT, GL_SPECULAR, specularColor );
00102     glMaterialf( GL_FRONT, GL_SHININESS, 50.0 );
00103 }
00104 
00105 }

kalzium

Skip menu "kalzium"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdeedu

Skip menu "kdeedu"
  • kalzium
  • kanagram
  • kig
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  •   docs
  •   src
  • parley
Generated for kdeedu by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal