Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

nebula.cpp

Go to the documentation of this file.
00001 // nebula.cpp
00002 //
00003 // Copyright (C) 2003, Chris Laurel <claurel@shatters.net>
00004 //
00005 // This program is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU General Public License
00007 // as published by the Free Software Foundation; either version 2
00008 // of the License, or (at your option) any later version.
00009 
00010 #include <algorithm>
00011 #include <stdio.h>
00012 #include "celestia.h"
00013 #include <celmath/mathlib.h>
00014 #include <celutil/util.h>
00015 #include <celutil/debug.h>
00016 #include "astro.h"
00017 #include "nebula.h"
00018 #include "meshmanager.h"
00019 #include "rendcontext.h"
00020 #include "gl.h"
00021 #include "vecgl.h"
00022 #include "render.h"
00023 
00024 using namespace std;
00025 
00026 
00027 Nebula::Nebula() :
00028     model(InvalidResource)
00029 {
00030 }
00031 
00032 
00033 const char* Nebula::getType() const
00034 {
00035     return "Nebula";
00036 }
00037 
00038 
00039 void Nebula::setType(const string& typeStr)
00040 {
00041 }
00042 
00043 
00044 size_t Nebula::getDescription(char* buf, size_t bufLength) const
00045 {
00046     // Should use snprintf, but it's not available on Windows
00047     return sprintf(buf, _("%s"), getType());
00048 }
00049 
00050 
00051 ResourceHandle Nebula::getModel() const
00052 {
00053     return model;
00054 }
00055 
00056 void Nebula::setModel(ResourceHandle _model)
00057 {
00058     model = _model;
00059 }
00060 
00061 
00062 bool Nebula::load(AssociativeArray* params, const string& resPath)
00063 {
00064     string model;
00065     if (params->getString("Mesh", model))
00066     {
00067         ResourceHandle modelHandle =
00068             GetModelManager()->getHandle(ModelInfo(model, resPath));
00069         setModel(modelHandle);
00070     }
00071     
00072     return DeepSkyObject::load(params, resPath);
00073 }
00074 
00075 
00076 void Nebula::render(const GLContext&,
00077                     const Vec3f& offset,
00078                     const Quatf& viewerOrientation,
00079                     float brightness,
00080                     float pixelSize)
00081 {
00082     Model* m = NULL;
00083     if (model != InvalidResource)
00084         m = GetModelManager()->find(model);
00085     if (m == NULL)
00086         return;
00087 
00088     glDisable(GL_LIGHTING);
00089     glEnable(GL_TEXTURE_2D);
00090     glScalef(getRadius(), getRadius(), getRadius());
00091     glRotate(getOrientation());
00092 
00093     FixedFunctionRenderContext rc;
00094     m->render(rc);
00095 
00096     // Reset the material
00097     float black[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
00098     float zero = 0.0f;
00099     glColor4fv(black);
00100     glMaterialfv(GL_FRONT, GL_EMISSION, black);
00101     glMaterialfv(GL_FRONT, GL_SPECULAR, black);
00102     glMaterialfv(GL_FRONT, GL_SHININESS, &zero);
00103 
00104     glEnable(GL_BLEND);
00105 }
00106 
00107 
00108 unsigned int Nebula::getRenderMask() const
00109 {
00110     return Renderer::ShowNebulae;
00111 }
00112 
00113 
00114 unsigned int Nebula::getLabelMask() const
00115 {
00116     return Renderer::NebulaLabels;
00117 }

Generated on Sat Jan 14 22:30:28 2006 for Celestia by  doxygen 1.4.1