00001 /* 00002 Copyright (C) 1997,1998,1999 00003 Kenji Hiranabe, Eiwa System Management, Inc. 00004 00005 This program is free software. 00006 Implemented by Kenji Hiranabe(hiranabe@esm.co.jp), 00007 conforming to the Java(TM) 3D API specification by Sun Microsystems. 00008 00009 Permission to use, copy, modify, distribute and sell this software 00010 and its documentation for any purpose is hereby granted without fee, 00011 provided that the above copyright notice appear in all copies and 00012 that both that copyright notice and this permission notice appear 00013 in supporting documentation. Kenji Hiranabe and Eiwa System Management,Inc. 00014 makes no representations about the suitability of this software for any 00015 purpose. It is provided "AS IS" with NO WARRANTY. 00016 00017 Copyright (C) 2006 00018 Rune Myrland, Skalden Studio AS 00019 SagaEngine adaptions, involving conversion from floating point values to fixed point values. 00020 Kenji Hiranabe's license apply. 00021 */ 00022 00023 #include "util/error/Log.hpp" 00024 #include "../math/CoorT.hpp" 00025 #include "../math/Trig.hpp" 00026 #include "AxisAngle4.hpp" 00027 #include "Quat4.hpp" 00028 #include "Euler3.hpp" 00029 #include <cmath> 00030 #include <cstdio> 00031 00032 namespace se_core { 00033 00034 void AxisAngle4 00035 ::set(const Quat4& q1) { 00036 setFromQuat(q1.x_, q1.y_, q1.z_, q1.w_); 00037 } 00038 00039 void AxisAngle4 00040 ::setFromQuat(coor_t x, coor_t y, coor_t z, coor_t w) { 00041 // This logic can calculate angle without normalization. 00042 // The direction of (x,y,z) and the sign of rotation cancel 00043 // each other to calculate a right answer. 00044 00045 // |sin a/2|, w = cos a/2 00046 coor_t sin_a2 = CoorT::sqrt(CoorT::pow2(x) + CoorT::pow2(y) + CoorT::pow2(z)); 00047 00048 // 0 <= angle <= PI , because 0 < sin_a2 00049 angle_ = BrayT::fromRad(2.0f * ::atan2(sin_a2, w)); 00050 x_ = x; 00051 y_ = y; 00052 z_ = z; 00053 } 00054 00055 00056 void AxisAngle4 00057 ::set(const coor_t len, const bray_t yaw) { 00058 x_ = Trig::sinScale(len, yaw); 00059 z_ = -Trig::cosScale(len, yaw); 00060 } 00061 00062 00063 void AxisAngle4 00064 ::set(const coor_t len, const bray_t yaw, const bray_t pitch) { 00065 set(len, yaw); 00066 00067 y_ = -Trig::sinScale(len, pitch); 00068 x_ = Trig::cosScale(x_, pitch); 00069 z_ = Trig::cosScale(z_, pitch); 00070 } 00071 00072 00073 void AxisAngle4 00074 ::set(const coor_t len, const Euler3& a1) { 00075 set(len, a1.yaw_, a1.pitch_); 00076 angle_ = a1.roll_; 00077 } 00078 00079 00080 const char* AxisAngle4 00081 ::toLog() const { 00082 sprintf(log_msg(), "AxisAngle4(%f, %f, %f, %d)", x_ * 1.0, y_ * 1.0, z_ * 1.0, angle_); 00083 return log_msg(); 00084 } 00085 } 00086
Home Page | SagaEngine trunk (updated nightly) reference generated Sun Dec 2 20:06:13 2007 by Doxygen version 1.3.9.1.