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/large_rocky_body.hpp"
00035 #include "space/large_lithosphere.hpp"
00036 #include "space/rocky_body_atmosphere.hpp"
00037 #include "scenegraph/camera.hpp"
00038 #include "platform/color.hpp"
00039 #include "platform/lowlevel.hpp"
00040
00041 using namespace gsgl;
00042 using namespace gsgl::data;
00043 using namespace gsgl::math;
00044 using namespace gsgl::scenegraph;
00045 using namespace gsgl::platform;
00046
00047 namespace periapsis
00048 {
00049
00050 namespace space
00051 {
00052
00053 BROKER_DEFINE_CREATOR(periapsis::space::large_rocky_body);
00054
00055
00056 large_rocky_body::large_rocky_body(const config_record & obj_config)
00057 : celestial_body(obj_config)
00058 {
00059
00060 body_rotator *rotator = !obj_config[L"rotator"].is_empty() ? rotator = dynamic_cast<body_rotator *>(broker::global_instance()->create_object(obj_config[L"rotator"], obj_config)) : 0;
00061 get_rotating_frame() = get_lithosphere() = new large_lithosphere(get_name() + L" lithosphere [rotating frame]", this, rotator);
00062
00063
00064 if (!obj_config[L"atmosphere_depth"].is_empty())
00065 {
00066 get_atmosphere() = new rocky_body_atmosphere(get_name() + L" atmosphere [rotating]", get_lithosphere(), 0);
00067 }
00068 }
00069
00070
00071 large_rocky_body::~large_rocky_body()
00072 {
00073 }
00074
00075
00076 gsgl::real_t large_rocky_body::get_priority(context *c)
00077 {
00078 return utils::pos_in_eye_space(this).mag2();
00079 }
00080
00081
00082 void large_rocky_body::init(context *c)
00083 {
00084 celestial_body::init(c);
00085 }
00086
00087
00088 void large_rocky_body::draw(context *c)
00089 {
00090 lithosphere *litho = get_lithosphere();
00091 if (litho)
00092 {
00093 glPushAttrib(GL_ALL_ATTRIB_BITS); CHECK_GL_ERRORS();
00094 glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS); CHECK_GL_ERRORS();
00095
00096 vector ep = utils::pos_in_eye_space(this);
00097
00098 gsgl::real_t radius = gsgl::max_val(get_polar_radius(), get_equatorial_radius());
00099 gsgl::real_t dist = ep.mag();
00100 gsgl::real_t zdist = -ep.get_z();
00101 gsgl::real_t far_plane = zdist + (radius * 1.1f);
00102 gsgl::real_t near_plane = zdist - (radius * 1.1f);
00103 if (near_plane <= 0)
00104 near_plane = 1;
00105
00106 glMatrixMode(GL_PROJECTION); CHECK_GL_ERRORS();
00107 glLoadIdentity(); CHECK_GL_ERRORS();
00108 gluPerspective(c->cam->get_field_of_view(), c->screen->get_aspect_ratio(), near_plane, far_plane); CHECK_GL_ERRORS();
00109
00110
00111 gsgl::real_t screen_width = utils::pixel_size(dist, radius, c->cam->get_field_of_view(), c->screen->get_height());
00112
00113 color::WHITE.set();
00114
00115 if (screen_width < MIN_PIXEL_WIDTH)
00116 {
00117 get_draw_results() |= node::NODE_DREW_POINT;
00118 draw_point(MIN_PIXEL_WIDTH);
00119 }
00120 else
00121 {
00122 glClearDepth(1); CHECK_GL_ERRORS();
00123 glClear(GL_DEPTH_BUFFER_BIT); CHECK_GL_ERRORS();
00124 glEnable(GL_DEPTH_TEST); CHECK_GL_ERRORS();
00125
00126 glEnable(GL_CULL_FACE); CHECK_GL_ERRORS();
00127 glPolygonMode(GL_FRONT_AND_BACK, (c->render_flags & context::RENDER_WIREFRAME) ? GL_LINE : GL_FILL); CHECK_GL_ERRORS();
00128
00129
00130 if (!(c->render_flags & context::RENDER_UNLIT) && !(get_draw_flags() & NODE_DRAW_UNLIT))
00131 {
00132 glEnable(GL_LIGHTING); CHECK_GL_ERRORS();
00133
00134 glLightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE); CHECK_GL_ERRORS();
00135 glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE); CHECK_GL_ERRORS();
00136
00137
00138 glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color::WHITE.get_val()); CHECK_GL_ERRORS();
00139 glMaterialfv(GL_FRONT, GL_SPECULAR, color::BLACK.get_val()); CHECK_GL_ERRORS();
00140 glMaterialfv(GL_FRONT, GL_EMISSION, color::BLACK.get_val()); CHECK_GL_ERRORS();
00141 glMaterialf(GL_FRONT, GL_SHININESS, 8); CHECK_GL_ERRORS();
00142 }
00143
00144
00145 if (!(c->render_flags & context::RENDER_UNTEXTURED))
00146 {
00147 glEnable(GL_TEXTURE_2D);
00148 }
00149
00150
00151 glMatrixMode(GL_MODELVIEW);
00152 glPushMatrix();
00153 glLoadMatrixf(litho->get_modelview().ptr());
00154
00155 litho->draw(c);
00156
00157 glMatrixMode(GL_MODELVIEW);
00158 glPopMatrix();
00159 }
00160
00161 glPopClientAttrib(); CHECK_GL_ERRORS();
00162 glPopAttrib(); CHECK_GL_ERRORS();
00163
00164 draw_name(c, 1, far_plane);
00165 }
00166 else
00167 {
00168 celestial_body::draw(c);
00169 }
00170 }
00171
00172
00173 void large_rocky_body::update(context *c)
00174 {
00175 celestial_body::update(c);
00176 }
00177
00178
00179 void large_rocky_body::cleanup(context *c)
00180 {
00181 celestial_body::cleanup(c);
00182 }
00183
00184
00185 }
00186
00187 }