00001 00006 /* Copyright © 2009 James Legg. 00007 This program is free software: you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation, either version 3 of the License, or 00010 (at your option) any later version. 00011 */ 00012 00013 #include "stream_loader.h" 00014 #include "FormErrors.h" 00015 00016 btTransform transform_from_stream(std::istream & stream) 00017 { 00018 btTransform result; 00019 btScalar x,y,z,w; 00020 // origin 00021 stream >> x >> y >> z; 00022 result.setOrigin(btVector3(x,y,z)); 00023 00024 // rotation 00025 stream >> x >> y >> z >> w; 00026 result.setRotation(btQuaternion(x, y, z, w)); 00027 return result; 00028 } 00029 00030 std::ostream & operator<<(std::ostream & stream, btTransform transform) 00031 { 00032 btVector3 origin(transform.getOrigin()); 00033 stream << origin.x() << ' ' 00034 << origin.y() << ' ' 00035 << origin.z() << '\t'; 00036 00037 btQuaternion rotation(transform.getRotation()); 00038 stream << rotation.x() << ' ' 00039 << rotation.y() << ' ' 00040 << rotation.z() << ' ' 00041 << rotation.w(); 00042 return stream; 00043 } 00044 00045 const unsigned int latest_string_version = 1; 00046 00047 void string_to_stream(std::ostream & stream, std::string string) 00048 { 00049 stream << latest_string_version << ' ' 00050 << string.length() << ' ' 00051 << string; 00052 } 00053 00054 std::string string_from_stream(std::istream & stream) 00055 { 00056 unsigned int version; 00057 // Do we know how to read this string? 00058 stream >> version; 00059 if (version == 0) throw CorruptedError(); 00060 if (version > latest_string_version) throw NewVersionError(); 00061 // find the length of the string. 00062 std::size_t length; 00063 stream >> length; 00064 std::string result; 00065 result.reserve(length); 00066 // read the space seperator. 00067 char c; 00068 stream >> c; 00069 // get the string 1 character at a time. 00070 for (unsigned int i = 0; i < length; i++) 00071 { 00072 result.push_back(c); 00073 stream.get(c); 00074 } 00075 DEBUG_MESSAGE(result); 00076 return result; 00077 } 00078 00079 std::ostream & operator<<(std::ostream & destination, const btVector3 & vector) 00080 { 00081 destination << vector.x() << ' ' 00082 << vector.y() << ' ' 00083 << vector.z(); 00084 return destination; 00085 } 00086 00087 std::istream & operator>>(std::istream & source, btVector3 & vector) 00088 { 00089 btScalar x, y, z; 00090 source >> x >> y >> z; 00091 vector.setX(x); 00092 vector.setY(y); 00093 vector.setZ(z); 00094 return source; 00095 } 00096 00097 std::ostream & operator<<(std::ostream & destination, const btQuadWord & quad) 00098 { 00099 destination << quad.x() 00100 << " " << quad.y() 00101 << " " << quad.z() 00102 << " " << quad.w(); 00103 return destination; 00104 } 00105 00106 std::istream & operator>>(std::istream & source, btQuadWord & quad) 00107 { 00108 btScalar x, y, z, w; 00109 source >> x >> y >> z >> w; 00110 quad.setX(x); 00111 quad.setY(y); 00112 quad.setZ(z); 00113 quad.setW(w); 00114 return source; 00115 }
Generated at Mon Sep 6 00:41:12 2010 by Doxygen version 1.4.7 for Racer version svn335.