00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include "space/star.hpp"
00035 #include "math/units.hpp"
00036 #include "scenegraph/camera.hpp"
00037 #include "platform/lowlevel.hpp"
00038
00039 #include <cmath>
00040
00041 using namespace gsgl;
00042 using namespace gsgl::data;
00043 using namespace gsgl::io;
00044 using namespace gsgl::math;
00045 using namespace gsgl::platform;
00046 using namespace gsgl::scenegraph;
00047
00048
00049 namespace periapsis
00050 {
00051
00052 namespace space
00053 {
00054
00055 BROKER_DEFINE_CREATOR(periapsis::space::star);
00056
00057
00058 star::star(const config_record & obj_config)
00059 : gas_body(obj_config), surface(0), corona(0), star_light(0)
00060 {
00061 get_draw_flags() |= NODE_DRAW_UNLIT;
00062
00063
00064 if (!obj_config[L"corona"].is_empty())
00065 {
00066 corona = new texture(obj_config.get_directory().get_full_path() + obj_config[L"corona"], TEXTURE_ENV_REPLACE);
00067 }
00068
00069
00070 star_light = new light(this);
00071 star_light->get_ambient() = color::BLACK;
00072 star_light->get_diffuse() = color::WHITE;
00073 star_light->get_specular() = color::WHITE;
00074 star_light->get_attenuation_constant() = 1;
00075 star_light->get_attenuation_linear() = static_cast<gsgl::real_t>(1.0 / (10.0 * units::METERS_PER_AU));
00076 star_light->get_attenuation_quadratic() = 0;
00077 }
00078
00079
00080 star::~star()
00081 {
00082 delete corona;
00083 delete surface;
00084 }
00085
00086
00087 void star::init(context *c)
00088 {
00089 get_simple_sphere()->init(c);
00090 }
00091
00092
00093 void star::draw(context *c)
00094 {
00095 gsgl::real_t corona_radius = get_equatorial_radius() * 16;
00096
00097 glPushAttrib(GL_ALL_ATTRIB_BITS); CHECK_GL_ERRORS();
00098 glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS); CHECK_GL_ERRORS();
00099
00100 gas_body::draw(c);
00101
00102 glPopClientAttrib(); CHECK_GL_ERRORS();
00103 glPopAttrib(); CHECK_GL_ERRORS();
00104
00105
00106 if (corona)
00107 {
00108 glPushAttrib(GL_ALL_ATTRIB_BITS); CHECK_GL_ERRORS();
00109 glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS); CHECK_GL_ERRORS();
00110
00111 vector ep = utils::pos_in_eye_space(this);
00112 gsgl::real_t dist = ep.mag();
00113
00114 gsgl::real_t zdist = -ep.get_z();
00115 assert(zdist > 0);
00116
00117 float far_plane = zdist + (corona_radius * 1.1f);
00118 float near_plane = zdist - (corona_radius * 1.1f);
00119 if (near_plane < 1.0f)
00120 near_plane = 1.0f;
00121
00122 glMatrixMode(GL_PROJECTION); CHECK_GL_ERRORS();
00123 glLoadIdentity(); CHECK_GL_ERRORS();
00124 gluPerspective(c->cam->get_field_of_view(), c->screen->get_aspect_ratio(), near_plane, far_plane);
00125
00126 glDisable(GL_DEPTH_TEST); CHECK_GL_ERRORS();
00127
00128 glEnable(GL_BLEND); CHECK_GL_ERRORS();
00129 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); CHECK_GL_ERRORS();
00130
00131 color::WHITE.set();
00132
00133 glEnable(GL_CULL_FACE); CHECK_GL_ERRORS();
00134
00135 if (c->render_flags & (context::RENDER_WIREFRAME | context::RENDER_UNTEXTURED))
00136 {
00137 glPolygonMode(GL_FRONT, GL_LINE);
00138 }
00139 else
00140 {
00141 glPolygonMode(GL_FRONT, GL_FILL);
00142 glEnable(GL_TEXTURE_2D); CHECK_GL_ERRORS();
00143 corona->bind();
00144 }
00145
00146 utils::draw_billboard(this, vector::ZERO, corona_radius);
00147
00148 glPopClientAttrib(); CHECK_GL_ERRORS();
00149 glPopAttrib(); CHECK_GL_ERRORS();
00150
00151
00152 draw_name(c, 1, far_plane);
00153 }
00154
00155 }
00156
00157
00158 }
00159
00160 }