From: Markus R. <rol...@us...> - 2005-12-05 21:38:32
|
Update of /cvsroot/simspark/simspark/spark/kerosin/materialserver In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19774/materialserver Added Files: .cvsignore material.cpp material.h material2dtexture.cpp material2dtexture.h material2dtexture_c.cpp material_c.cpp materialserver.cpp materialserver.h materialserver_c.cpp materialsolid.cpp materialsolid.h materialsolid_c.cpp Log Message: --- NEW FILE: .cvsignore --- *.lo .deps .dirstamp .libs --- NEW FILE: materialsolid.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: materialsolid.h,v 1.1 2005/12/05 21:38:22 rollmark Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef KEROSIN_MATERIALSOLID_H #define KEROSIN_MATERIALSOLID_H #include "material.h" #include <kerosin/openglserver/glbase.h> #include <salt/vector.h> namespace kerosin { class MaterialSolid : public Material { // // Functions // public: MaterialSolid(); virtual ~MaterialSolid(); virtual void Bind(); /** sets the ambient material reflectance */ void SetAmbient(const RGBA& ambient); /** returns the ambient material reflectance */ const RGBA& GetAmbient(); /** sets the diffuse material reflectance */ void SetDiffuse(const RGBA& diffuse); /** returns the diffuse material reflectancee */ const RGBA& GetDiffuse(); /** sets the specular material reflectance */ void SetSpecular(const RGBA& specular); /** returns the specular material reflectance */ const RGBA& GetSpecular(); /** sets the light emission */ void SetEmission(const RGBA& emission); /** returns the light emission */ const RGBA& GetEmission(); protected: /** sets up all lighting material properties */ void SetupMaterial(); // // Members // protected: /** the ambient material refeflectance */ RGBA mAmbient; /** the diffuse material reflectance */ RGBA mDiffuse; /** the specular material reflectance */ RGBA mSpecular; /** the emitted light intensity of the material */ RGBA mEmission; }; DECLARE_CLASS(MaterialSolid); }; #endif // KEROSIN_MATERIALSOLID_H --- NEW FILE: materialserver.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: materialserver.h,v 1.1 2005/12/05 21:38:22 rollmark Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef KEROSIN_MATERIALSERVER_H #define KEROSIN_MATERIALSERVER_H #include <zeitgeist/class.h> #include <zeitgeist/node.h> namespace kerosin { class Material; class MaterialServer : public zeitgeist::Node { // // types // private: // // functions // public: MaterialServer(); virtual ~MaterialServer(); //! returns a cached material boost::shared_ptr<Material> GetMaterial(const std::string &name); protected: virtual void OnLink(); }; DECLARE_CLASS(MaterialServer); } //kerosin #endif //KEROSIN_MATERIALSERVER_H --- NEW FILE: material_c.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: material_c.cpp,v 1.1 2005/12/05 21:38:22 rollmark Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "material.h" using namespace zeitgeist; using namespace kerosin; void CLASS(Material)::DefineClass() { DEFINE_BASECLASS(zeitgeist/Leaf); } --- NEW FILE: materialsolid_c.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: materialsolid_c.cpp,v 1.1 2005/12/05 21:38:22 rollmark Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "materialsolid.h" using namespace zeitgeist; using namespace kerosin; using namespace salt; using namespace boost; static bool readRGBA(const zeitgeist::ParameterList& in, RGBA& m) { if ( (in.GetSize() != 4) || (! in.GetValue(in[0], m.r())) || (! in.GetValue(in[1], m.g())) || (! in.GetValue(in[2], m.b())) || (! in.GetValue(in[3], m.a())) ) { return false; } return true; } FUNCTION(MaterialSolid,setAmbient) { RGBA m; if (! readRGBA(in,m)) { return false; } obj->SetAmbient(m); return true; } FUNCTION(MaterialSolid,setDiffuse) { RGBA m; if (! readRGBA(in,m)) { return false; } obj->SetDiffuse(m); return true; } FUNCTION(MaterialSolid,setSpecular) { RGBA m; if (! readRGBA(in,m)) { return false; } obj->SetSpecular(m); return true; } FUNCTION(MaterialSolid,setEmission) { RGBA m; if (! readRGBA(in,m)) { return false; } obj->SetEmission(m); return true; } void CLASS(MaterialSolid)::DefineClass() { DEFINE_BASECLASS(kerosin/Material); DEFINE_FUNCTION(setAmbient); DEFINE_FUNCTION(setDiffuse); DEFINE_FUNCTION(setSpecular); DEFINE_FUNCTION(setEmission); } --- NEW FILE: material2dtexture.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: material2dtexture.cpp,v 1.1 2005/12/05 21:38:22 rollmark Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "material2dtexture.h" #include <kerosin/textureserver/textureserver.h> #include <kerosin/textureserver/texture.h> #include <kerosin/openglserver/openglserver.h> #include <zeitgeist/logserver/logserver.h> #include <zeitgeist/scriptserver/scriptserver.h> using namespace zeitgeist; using namespace kerosin; using namespace boost; using namespace std; Material2DTexture::Material2DTexture() : MaterialSolid() { } Material2DTexture::~Material2DTexture() { } bool Material2DTexture::LoadTexture(const std::string& texName, shared_ptr<Texture>& store) { shared_ptr<ScriptServer> scriptServer = GetCore()->GetScriptServer(); shared_ptr<TextureServer> textureServer = shared_dynamic_cast<TextureServer> (GetCore()->Get("/sys/server/texture")); store.reset(); if (textureServer.get() == 0) { GetLog()->Error() << "(Material2DTexture) ERROR: cannot find TextureServer\n"; return false; } store = textureServer->GetTexture(texName); return (store.get() != 0); } bool Material2DTexture::SetDiffuseTexture(const std::string& texName) { return LoadTexture(texName,mTexDiffuse); } bool Material2DTexture::SetNormalTexture(const std::string& texName) { return LoadTexture(texName,mTexNormal); } bool Material2DTexture::SetSpecularTexture(const std::string& texName) { return LoadTexture(texName,mTexSpecular); } void Material2DTexture::Bind() { SetupMaterial(); if (mTexDiffuse.get() != 0) { glActiveTextureARB(GL_TEXTURE0_ARB); glEnable(GL_TEXTURE_2D); mTexDiffuse->Bind(); } if (mTexNormal.get() != 0) { glActiveTextureARB(GL_TEXTURE1_ARB); glEnable(GL_TEXTURE_2D); mTexNormal->Bind(); } if (mTexSpecular.get() != 0) { glActiveTextureARB(GL_TEXTURE2_ARB); glEnable(GL_TEXTURE_2D); mTexSpecular->Bind(); } } --- NEW FILE: material2dtexture_c.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: material2dtexture_c.cpp,v 1.1 2005/12/05 21:38:22 rollmark Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "material2dtexture.h" using namespace zeitgeist; using namespace kerosin; using namespace std; FUNCTION(Material2DTexture,setDiffuseTexture) { string inName; if ( (in.GetSize() != 1) || (! in.GetValue(in[0], inName)) ) { return false; } return obj->SetDiffuseTexture(inName); } FUNCTION(Material2DTexture,setNormalTexture) { string inName; if ( (in.GetSize() != 1) || (! in.GetValue(in[0], inName)) ) { return false; } return obj->SetNormalTexture(inName); } FUNCTION(Material2DTexture,setSpecularTexture) { string inName; if ( (in.GetSize() != 1) || (! in.GetValue(in[0], inName)) ) { return false; } return obj->SetSpecularTexture(inName); } void CLASS(Material2DTexture)::DefineClass() { DEFINE_BASECLASS(kerosin/MaterialSolid); DEFINE_FUNCTION(setDiffuseTexture); DEFINE_FUNCTION(setNormalTexture); DEFINE_FUNCTION(setSpecularTexture); } --- NEW FILE: material.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: material.h,v 1.1 2005/12/05 21:38:22 rollmark Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef KEROSIN_MATERIAL_H #define KEROSIN_MATERIAL_H #include <zeitgeist/class.h> #include <zeitgeist/leaf.h> #include <string> namespace kerosin { class Material : public zeitgeist::Leaf { // // Functions // public: Material(); virtual ~Material(); /** binds the managed material, i.e. sets all necessary OpenGL states */ virtual void Bind() = 0; }; DECLARE_ABSTRACTCLASS(Material); } //namespace kerosin #endif //KEROSIN_MATERIAL_H --- NEW FILE: materialsolid.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: materialsolid.cpp,v 1.1 2005/12/05 21:38:22 rollmark Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "materialsolid.h" #include <kerosin/openglserver/openglserver.h> using namespace kerosin; using namespace zeitgeist; using namespace salt; using namespace boost; using namespace std; MaterialSolid::MaterialSolid() : Material(), mAmbient(0.2f,0.2f,0.2f,1.0f), mDiffuse(1.0f,1.0f,1.0f,1.0f), mSpecular(0.0f,0.0f,0.0f,1.0f), mEmission(0.0f,0.0f,0.0f,1.0f) { } MaterialSolid::~MaterialSolid() { } void MaterialSolid::SetupMaterial() { // set ambient material reflectance glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mAmbient); // set diffuse material reflectance glColor3fv(mDiffuse); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mDiffuse); // set specular material reflectance glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,mSpecular); // set light emission glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,mEmission); } void MaterialSolid::Bind() { SetupMaterial(); glDisable(GL_TEXTURE_2D); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); } void MaterialSolid::SetAmbient(const RGBA& ambient) { mAmbient = ambient; } const RGBA& MaterialSolid::GetAmbient() { return mAmbient; } void MaterialSolid::SetDiffuse(const RGBA& diffuse) { mDiffuse = diffuse; } const RGBA& MaterialSolid::GetDiffuse() { return mDiffuse; } void MaterialSolid::SetSpecular(const RGBA& specular) { mSpecular = specular; } const RGBA& MaterialSolid::GetSpecular() { return mSpecular; } void MaterialSolid::SetEmission(const RGBA& emission) { mEmission = emission; } const RGBA& MaterialSolid::GetEmission() { return mEmission; } --- NEW FILE: materialserver.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: materialserver.cpp,v 1.1 2005/12/05 21:38:22 rollmark Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "materialserver.h" #include <zeitgeist/logserver/logserver.h> #include <zeitgeist/scriptserver/scriptserver.h> #include "material.h" #include "materialsolid.h" using namespace boost; using namespace kerosin; using namespace zeitgeist; MaterialServer::MaterialServer() : Node() { } MaterialServer::~MaterialServer() { } shared_ptr<Material> MaterialServer::GetMaterial(const std::string& name) { shared_ptr<Material> material = shared_dynamic_cast<Material>(GetChild(name)); if (material.get() == 0) { GetLog()->Error() << "(MaterialServer) ERROR: Unknown material '" << name << "'\n"; } return material; } void MaterialServer::OnLink() { // create the default material shared_ptr<MaterialSolid> defMat = shared_dynamic_cast<MaterialSolid> (GetCore()->New("kerosin/MaterialSolid")); defMat->SetName("default"); AddChildReference(defMat); } --- NEW FILE: material2dtexture.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: material2dtexture.h,v 1.1 2005/12/05 21:38:22 rollmark Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef KEROSIN_MATERIAL2DTEXTURE_H #define KEROSIN_MATERIAL2DTEXTURE_H #include "materialsolid.h" namespace kerosin { class Texture; class Material2DTexture : public MaterialSolid { // // Functions // public: Material2DTexture(); virtual ~Material2DTexture(); /** loads the diffuse texture */ bool SetDiffuseTexture(const std::string& texName); /** loads the normal texture */ bool SetNormalTexture(const std::string& texName); /** loads the specular texture */ bool SetSpecularTexture(const std::string& texName); /** binds the managed material, i.e. sets all necessary OpenGL states */ virtual void Bind(); protected: /** tries to load the texturee texName and stores a reference */ bool LoadTexture(const std::string& texName, boost::shared_ptr<Texture>& store); // // Members // protected: /** the diffuse texture */ boost::shared_ptr<Texture> mTexDiffuse; /** the normal texture */ boost::shared_ptr<Texture> mTexNormal; /** the specular texture */ boost::shared_ptr<Texture> mTexSpecular; }; DECLARE_CLASS(Material2DTexture); }; #endif // KEROSIN_MATERIAL2DTEXTURE_H --- NEW FILE: material.cpp --- #include "material.h" using namespace boost; using namespace kerosin; using namespace std; using namespace zeitgeist; Material::Material() : Leaf() { } Material::~Material() { } --- NEW FILE: materialserver_c.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: materialserver_c.cpp,v 1.1 2005/12/05 21:38:22 rollmark Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "materialserver.h" using namespace boost; using namespace kerosin; using namespace zeitgeist; void CLASS(MaterialServer)::DefineClass() { DEFINE_BASECLASS(zeitgeist/Node); } |