00001 /* 00002 * placement.cpp 00003 * 00004 * Copyright (C) 2009 Thomas A. Vaughan 00005 * All rights reserved. 00006 * 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions are met: 00010 * * Redistributions of source code must retain the above copyright 00011 * notice, this list of conditions and the following disclaimer. 00012 * * Redistributions in binary form must reproduce the above copyright 00013 * notice, this list of conditions and the following disclaimer in the 00014 * documentation and/or other materials provided with the distribution. 00015 * * Neither the name of the <organization> nor the 00016 * names of its contributors may be used to endorse or promote products 00017 * derived from this software without specific prior written permission. 00018 * 00019 * THIS SOFTWARE IS PROVIDED BY THOMAS A. VAUGHAN ''AS IS'' AND ANY 00020 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00021 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00022 * DISCLAIMED. IN NO EVENT SHALL THOMAS A. VAUGHAN BE LIABLE FOR ANY 00023 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00025 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00026 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00028 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 * 00030 * Implementation placement objects. See placement.h 00031 */ 00032 00033 // includes -------------------------------------------------------------------- 00034 #include "placement.h" // always include our own header first! 00035 00036 #include <iostream> 00037 #include <math.h> 00038 00039 #include "util/token_stream.h" 00040 00041 00042 00043 static const float s_radiansPerDegree = M_PI / 180.0; 00044 00045 00046 //////////////////////////////////////////////////////////////////////////////// 00047 // 00048 // static helper methods 00049 // 00050 //////////////////////////////////////////////////////////////////////////////// 00051 00052 00053 //////////////////////////////////////////////////////////////////////////////// 00054 // 00055 // public API 00056 // 00057 //////////////////////////////////////////////////////////////////////////////// 00058 00059 placement_t 00060 parsePlacement 00061 ( 00062 IO std::istream& stream 00063 ) 00064 { 00065 ASSERT(stream.good(), "bad?"); 00066 00067 placement_t p; 00068 std::string token; 00069 00070 // read vectors 00071 point3d_t euler; 00072 euler.clear(); // zero rotations by default 00073 while (true) { 00074 getNextToken(stream, token); 00075 if ("}" == token) { 00076 break; 00077 } else if ("position" == token) { 00078 parsePoint3d(stream, p.position); 00079 } else if ("euler" == token) { 00080 parsePoint3d(stream, euler); 00081 } else { 00082 ASSERT_THROW(false, 00083 "Unknown token reading placement: " << token); 00084 } 00085 } 00086 00087 // convert degrees to radians 00088 euler = s_radiansPerDegree * euler; 00089 00090 // transform euler to quaternion 00091 p.rotation.setEulerZYX(euler.z, euler.y, euler.x); 00092 // euler.dump("Just read Euler: "); 00093 // p.rotation.dump(" quaternion representation"); 00094 // end of placement 00095 00096 // all done! 00097 return p; 00098 } 00099