00001 // 00002 // $Id: test_frame.cpp 2 2008-03-01 20:58:50Z kulibali $ 00003 // 00004 // Copyright (c) 2008, The Periapsis Project. All rights reserved. 00005 // 00006 // Redistribution and use in source and binary forms, with or without 00007 // modification, are permitted provided that the following conditions are 00008 // met: 00009 // 00010 // * Redistributions of source code must retain the above copyright notice, 00011 // this list of conditions and the following disclaimer. 00012 // 00013 // * Redistributions in binary form must reproduce the above copyright 00014 // notice, this list of conditions and the following disclaimer in the 00015 // documentation and/or other materials provided with the distribution. 00016 // 00017 // * Neither the name of the The Periapsis Project nor the names of its 00018 // contributors may be used to endorse or promote products derived from 00019 // this software without specific prior written permission. 00020 // 00021 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 00022 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 00023 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 00024 // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 00025 // OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00026 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00027 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00028 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00029 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00030 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00031 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00032 // 00033 00034 #include "scenegraph/test_frame.hpp" 00035 #include "math/quaternion.hpp" 00036 00037 #include "platform/hardware.hpp" 00038 00039 #include <math.h> 00040 00041 namespace gsgl 00042 { 00043 00044 using namespace data; 00045 using namespace math; 00046 00047 namespace scenegraph 00048 { 00049 00050 BROKER_DEFINE_CREATOR(gsgl::scenegraph::test_frame); 00051 00052 00053 test_frame::test_frame(const config_record & obj_conf, const config_record & sys_conf) 00054 : node(obj_conf, sys_conf), rotate(true), draw_me(true), angle(0), radius(10.0f) 00055 { 00056 //if (obj_conf[L"rotate"].to_lower() == L"false") 00057 // rotate = false; 00058 //if (obj_conf[L"draw"].to_lower() == L"false") 00059 // draw_me = false; 00060 //if (!obj_conf[L"radius"].is_empty()) 00061 // radius = static_cast<gsgl::real_t>(obj_conf[L"radius"].to_double()); 00062 } // test_frame::test_frame() 00063 00064 00065 test_frame::~test_frame() 00066 { 00067 } // test_frame::~test_frame() 00068 00069 00070 void test_frame::init(context *) 00071 { 00072 if (rotate) 00073 { 00074 angle = 0; 00075 recalc(); 00076 } 00077 } // test_frame::init() 00078 00079 00080 void test_frame::draw(context *c) 00081 { 00082 if (draw_me) 00083 { 00084 glColor4f(0.0f, 1.0f, 0.0f, 1.0f); 00085 draw_coordinate_system(c, radius); 00086 } 00087 } // test_frame::draw() 00088 00089 00090 void test_frame::update(context *c) 00091 { 00092 if (draw_me) 00093 { 00094 angle = static_cast<gsgl::real_t>((::fmod((c->cur_time - c->start_time) * c->time_scale, 60.0) / 60.0f) * math::PI * 2.0); 00095 recalc(); 00096 } 00097 } // test_frame::update() 00098 00099 00100 gsgl::real_t test_frame::get_priority(context *) 00101 { 00102 return pos_in_eye_space().mag2(); 00103 } // test_frame::get_priority() 00104 00105 00106 void test_frame::recalc() 00107 { 00108 quaternion rq(vector::Z_AXIS, angle); 00109 quaternion qq(vector::X_AXIS, static_cast<gsgl::real_t>(-23.0 * math::DEG2RAD)); 00110 00111 get_orientation() = qq * rq; 00112 } // test_frame::recalc() 00113 00114 } // namespace scenegraph 00115 00116 } // namespace gsgl