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

VenusImage.cpp

Go to the documentation of this file.
00001 /*
00002  * VenusImage.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 
00035 #include "../Include/Sky.h"
00036 #include "../Include/Utility.h"
00037 
00038 
00039 //
00040 // Pre-draw callback
00041 //
00042 static int venus_predraw (ssgEntity *e)
00043 {
00044   ssgLeaf *f = (ssgLeaf*)e;
00045   if (f->hasState()) f->getState()->apply();
00046 
00047   glPushAttrib (GL_DEPTH_BUFFER_BIT | GL_FOG_BIT | GL_POINT_BIT);
00048   glDisable (GL_DEPTH_TEST);
00049   glDisable (GL_FOG);
00050   glEnable (GL_POINT_SMOOTH);
00051   glPointSize (2.0);
00052 
00053   return true;
00054 }
00055 
00056 
00057 //
00058 // Post-draw callback
00059 //
00060 static int venus_postdraw (ssgEntity *e)
00061 {
00062   glPopAttrib ();
00063 
00064   return true;
00065 }
00066 
00067 
00068 CVenusImage::CVenusImage (void)
00069 {
00070   // Instantiate SSG entities
00071   top = new ssgTransform;
00072   top->setName ("Venus");
00073 
00074   // Create simple SSG state
00075   ssgSimpleState *state = new ssgSimpleState ();
00076   state->setShadeModel (GL_SMOOTH);
00077   state->disable (GL_LIGHTING);
00078   state->disable (GL_CULL_FACE);
00079   state->disable (GL_TEXTURE_2D);
00080   state->enable (GL_COLOR_MATERIAL);
00081   state->enable (GL_BLEND);
00082   state->enable (GL_ALPHA_TEST);
00083   state->setColourMaterial (GL_AMBIENT_AND_DIFFUSE);
00084   state->setMaterial (GL_EMISSION, 0, 0, 0, 1);
00085   state->setMaterial (GL_SPECULAR, 0, 0, 0, 1);
00086 
00087   // Default colour is white
00088   rgba = new ssgColourArray (1);
00089   sgVec4 default_colour;
00090   sgSetVec4 (default_colour, 1.0, 1.0, 1.0, 1.0);
00091 
00092   // TEMP : Set colour to yellow for testing
00093 //  sgSetVec4 (default_colour, 1.0, 1.0, 0.5, 1.0);
00094 
00095   rgba->add (default_colour);
00096 
00097   // Create as single point at the origin
00098   va = new ssgVertexArray (1);
00099   sgVec3 v;
00100   sgSetVec3 (v, 0, 0, 0);
00101   va->add (v);
00102 
00103   // Construct the leaf object
00104   ssgLeaf *leaf = new ssgVtxTable (GL_POINTS, va, NULL, NULL, rgba);
00105   leaf->setState (state);
00106   leaf->setCallback (SSG_CALLBACK_PREDRAW, venus_predraw);
00107   leaf->setCallback (SSG_CALLBACK_POSTDRAW, venus_postdraw);
00108   top->addKid (leaf);
00109 }
00110 
00111 
00112 ssgEntity* CVenusImage::GetSSGEntity (void)
00113 {
00114   return top;
00115 }
00116 
00117 
00118 //
00119 // Repaint the appearance of the image
00120 //
00121 void CVenusImage::Repaint (float mv, float limit, float factor)
00122 {
00123   float nmag, alpha;
00124   if (mv < limit) {
00125     // This star is brighter than the limiting magnitude
00126     nmag = (limit - mv) / limit;    // Scale brightness to 0.0..1.0
00127     alpha = (nmag * 0.85);        // Scale alpha to 0.0..0.85
00128     alpha += 0.25;            // Bias +25%
00129     alpha *= factor;          // Adjust alpha for ambient light
00130   } else {
00131     // Star is dimmer than the limiting magnitude
00132     alpha = 0.0;
00133   }
00134 
00135   // Clamp alpha to 0.0..1.0
00136   if (alpha > 1.0) { alpha = 1.0; }
00137   if (alpha < 0.0) { alpha = 0.0; }
00138 
00139   float* colour = rgba->get (0);
00140   colour[3] = alpha;
00141 }
00142 
00143 
00144 //
00145 // Reposition the image of the planet in the sky
00146 //
00147 // Arguments:
00148 //  pos     3D position of the eye (cartesian coordinates??)
00149 //  lst     Local Sidereal Time, in degrees
00150 //  ra      Right Ascension, in radians
00151 //  dec     Declination, in radians
00152 //  distance  Distance from the eye in world units
00153 //
00154 void CVenusImage::Reposition (sgVec3 pos, double lst, double lat,
00155                 double ra, double dec, double distance)
00156 {
00157   sgMat4 LST, LAT, RA, DEC, D;
00158   sgVec3 axis;
00159   sgVec3 v;
00160 
00161   // Rotation matrix for latitude
00162   sgSetVec3 (axis, -1, 0, 0);
00163   sgMakeRotMat4 (LAT, 90-lat, axis);
00164 
00165   // Rotation matrix for local sidereal time, converted from h to deg
00166   sgSetVec3 (axis, 0, 0, -1);
00167   sgMakeRotMat4 (LST, (lst * 15), axis);
00168 
00169   // Rotation matrix for right ascension
00170   sgSetVec3 (axis, 0, 0, 1);
00171   sgMakeRotMat4 (RA, RadToDeg (ra), axis);
00172 
00173   // Rotation matrix for declination
00174   sgSetVec3 (axis, 1, 0, 0);
00175   sgMakeRotMat4 (DEC, 90 - RadToDeg (dec), axis);
00176 
00177   // Translate sun distance
00178   sgSetVec3 (v, 0, 0, distance);
00179   sgMakeTransMat4 (D, v);
00180 
00181   // Combine all transforms
00182   sgMat4 T;
00183   sgMakeIdentMat4 (T);
00184   sgPreMultMat4 (T, LAT);
00185   sgPreMultMat4 (T, LST);
00186   sgPreMultMat4 (T, RA);
00187   sgPreMultMat4 (T, DEC);
00188   sgPreMultMat4 (T, D);
00189   
00190   top->setTransform (T);
00191 }
00192 
00193 
SourceForge.net Logo Documentation generated by doxygen