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

JupiterImage.cpp

Go to the documentation of this file.
00001 /*
00002  * JupiterImage.cpp
00003  *
00004  * Part of Fly! Legacy project
00005  *
00006  * Copyright 2003 Chris Wallace
00007  *
00008  * Fly! Legacy is free software; you can redistribute it and/or modify
00009  *   it under the terms of the GNU General Public License as published by
00010  *   the Free Software Foundation; either version 2 of the License, or
00011  *   (at your option) any later version.
00012  *
00013  * Fly! Legacy is distributed in the hope that it will be useful,
00014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  *   GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  *   along with Fly! Legacy; if not, write to the Free Software
00020  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  *
00022  */
00023 
00041 #include "../Include/Sky.h"
00042 #include "../Include/Utility.h"
00043 
00044 
00045 //
00046 // Pre-draw callback
00047 //
00048 static int jupiter_predraw (ssgEntity *e)
00049 {
00050   ssgLeaf *f = (ssgLeaf*)e;
00051   if (f->hasState()) f->getState()->apply();
00052 
00053   glPushAttrib (GL_DEPTH_BUFFER_BIT | GL_FOG_BIT | GL_POINT_BIT);
00054   glDisable (GL_DEPTH_TEST);
00055   glDisable (GL_FOG);
00056   glEnable (GL_POINT_SMOOTH);
00057   glPointSize (2.0);
00058 
00059   return true;
00060 }
00061 
00062 
00063 //
00064 // Post-draw callback
00065 //
00066 static int jupiter_postdraw (ssgEntity *e)
00067 {
00068   glPopAttrib ();
00069 
00070   return true;
00071 }
00072 
00073 
00074 CJupiterImage::CJupiterImage (void)
00075 {
00076   // Instantiate SSG entities
00077   top = new ssgTransform;
00078   top->setName ("Jupiter");
00079 
00080   // Create simple SSG state
00081   ssgSimpleState *state = new ssgSimpleState ();
00082   state->setShadeModel (GL_SMOOTH);
00083   state->disable (GL_LIGHTING);
00084   state->disable (GL_CULL_FACE);
00085   state->disable (GL_TEXTURE_2D);
00086   state->enable (GL_COLOR_MATERIAL);
00087   state->enable (GL_BLEND);
00088   state->enable (GL_ALPHA_TEST);
00089   state->setColourMaterial (GL_AMBIENT_AND_DIFFUSE);
00090   state->setMaterial (GL_EMISSION, 0, 0, 0, 1);
00091   state->setMaterial (GL_SPECULAR, 0, 0, 0, 1);
00092 
00093   // Default colour is pale yellow
00094   rgba = new ssgColourArray (1);
00095   sgVec4 default_colour;
00096   sgSetVec4 (default_colour, 1.0, 0.99, 0.90, 1.0);
00097   rgba->add (default_colour);
00098 
00099   // Create as single point at the origin
00100   va = new ssgVertexArray (1);
00101   sgVec3 v;
00102   sgSetVec3 (v, 0, 0, 0);
00103   va->add (v);
00104 
00105   // Construct the leaf object
00106   ssgLeaf *leaf = new ssgVtxTable (GL_POINTS, va, NULL, NULL, rgba);
00107   leaf->setState (state);
00108   leaf->setCallback (SSG_CALLBACK_PREDRAW, jupiter_predraw);
00109   leaf->setCallback (SSG_CALLBACK_POSTDRAW, jupiter_postdraw);
00110   top->addKid (leaf);
00111 }
00112 
00113 
00114 ssgEntity* CJupiterImage::GetSSGEntity (void)
00115 {
00116   return top;
00117 }
00118 
00119 
00120 
00121 //
00122 // Repaint the appearance of the image
00123 //
00124 void CJupiterImage::Repaint (float mv, float limit, float factor)
00125 {
00126   float nmag, alpha;
00127   if (mv < limit) {
00128     // This star is brighter than the limiting magnitude
00129     nmag = (limit - mv) / limit;    // Scale brightness to 0.0..1.0
00130     alpha = (nmag * 0.85);        // Scale alpha to 0.0..0.85
00131     alpha += 0.25;            // Bias +25%
00132     alpha *= factor;          // Adjust alpha for ambient light
00133   } else {
00134     // Star is dimmer than the limiting magnitude
00135     alpha = 0.0;
00136   }
00137 
00138   // Clamp alpha to 0.0..1.0
00139   if (alpha > 1.0) { alpha = 1.0; }
00140   if (alpha < 0.0) { alpha = 0.0; }
00141 
00142   float* colour = rgba->get(0);
00143   colour[3] = alpha;
00144 }
00145 
00146 
00147 //
00148 // Reposition the image in the sky
00149 //
00150 // Arguments:
00151 //  pos     3D position of the eye (cartesian coordinates??)
00152 //  lst     Local Sidereal Time, in degrees
00153 //  ra      Right Ascension, in radians
00154 //  dec     Declination, in radians
00155 //  distance  Distance from the eye in world units
00156 //
00157 void CJupiterImage::Reposition (sgVec3 pos, double lst, double lat,
00158                 double ra, double dec, double distance)
00159 {
00160   sgMat4 LST, LAT, RA, DEC, D;
00161   sgVec3 axis;
00162   sgVec3 v;
00163 
00164   // Rotation matrix for latitude
00165   sgSetVec3 (axis, -1, 0, 0);
00166   sgMakeRotMat4 (LAT, 90-lat, axis);
00167 
00168   // Rotation matrix for local sidereal time, converted from h to deg
00169   sgSetVec3 (axis, 0, 0, -1);
00170   sgMakeRotMat4 (LST, (lst * 15), axis);
00171 
00172   // Rotation matrix for right ascension
00173   sgSetVec3 (axis, 0, 0, 1);
00174   sgMakeRotMat4 (RA, RadToDeg (ra), axis);
00175 
00176   // Rotation matrix for declination
00177   sgSetVec3 (axis, 1, 0, 0);
00178   sgMakeRotMat4 (DEC, 90 - RadToDeg (dec), axis);
00179 
00180   // Translate sun distance
00181   sgSetVec3 (v, 0, 0, distance);
00182   sgMakeTransMat4 (D, v);
00183 
00184   // Combine all transforms
00185   sgMat4 T;
00186   sgMakeIdentMat4 (T);
00187   sgPreMultMat4 (T, LAT);
00188   sgPreMultMat4 (T, LST);
00189   sgPreMultMat4 (T, RA);
00190   sgPreMultMat4 (T, DEC);
00191   sgPreMultMat4 (T, D);
00192   
00193   top->setTransform (T);
00194 }
00195 
00196 
SourceForge.net Logo Documentation generated by doxygen