Panda3D
|
00001 // Filename: coordinateSystem.cxx 00002 // Created by: drose (24Sep99) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #include "coordinateSystem.h" 00016 #include "config_linmath.h" 00017 #include "configVariableEnum.h" 00018 #include "string_utils.h" 00019 00020 #include "dconfig.h" 00021 #include "pnotify.h" 00022 00023 #include <ctype.h> 00024 00025 static ConfigVariableEnum<CoordinateSystem> default_cs 00026 ("coordinate-system", CS_zup_right, 00027 PRC_DESC("The default coordinate system to use throughout Panda for " 00028 "rendering, user input, and matrix operations, unless specified " 00029 "otherwise.")); 00030 00031 00032 CoordinateSystem 00033 get_default_coordinate_system() { 00034 CoordinateSystem cs = default_cs; 00035 return (cs == CS_default || cs == CS_invalid) ? CS_zup_right : cs; 00036 } 00037 00038 00039 CoordinateSystem 00040 parse_coordinate_system_string(const string &str) { 00041 if (cmp_nocase_uh(str, "default") == 0) { 00042 return CS_default; 00043 00044 } else if (cmp_nocase_uh(str, "zup") == 0 || 00045 cmp_nocase_uh(str, "zup-right") == 0 || 00046 cmp_nocase_uh(str, "z-up") == 0 || 00047 cmp_nocase_uh(str, "z-up-right") == 0) { 00048 return CS_zup_right; 00049 00050 } else if (cmp_nocase_uh(str, "yup") == 0 || 00051 cmp_nocase_uh(str, "yup-right") == 0 || 00052 cmp_nocase_uh(str, "y-up") == 0 || 00053 cmp_nocase_uh(str, "y-up-right") == 0) { 00054 return CS_yup_right; 00055 00056 } else if (cmp_nocase_uh(str, "z-up-left") == 0 || 00057 cmp_nocase_uh(str, "zup-left") == 0) { 00058 return CS_zup_left; 00059 00060 } else if (cmp_nocase_uh(str, "y-up-left") == 0 || 00061 cmp_nocase_uh(str, "yup-left") == 0) { 00062 return CS_yup_left; 00063 } 00064 00065 return CS_invalid; 00066 } 00067 00068 bool 00069 is_right_handed(CoordinateSystem cs) { 00070 if (cs == CS_default) { 00071 cs = get_default_coordinate_system(); 00072 } 00073 switch (cs) { 00074 case CS_zup_right: 00075 case CS_yup_right: 00076 return true; 00077 00078 case CS_zup_left: 00079 case CS_yup_left: 00080 return false; 00081 00082 default: 00083 linmath_cat.error() 00084 << "Invalid coordinate system value: " << (int)cs << "\n"; 00085 nassertr(false, false); 00086 return false; 00087 } 00088 } 00089 00090 ostream & 00091 operator << (ostream &out, CoordinateSystem cs) { 00092 switch (cs) { 00093 case CS_default: 00094 return out << "default"; 00095 00096 case CS_zup_right: 00097 return out << "zup_right"; 00098 00099 case CS_yup_right: 00100 return out << "yup_right"; 00101 00102 case CS_zup_left: 00103 return out << "zup_left"; 00104 00105 case CS_yup_left: 00106 return out << "yup_left"; 00107 00108 case CS_invalid: 00109 return out << "invalid"; 00110 } 00111 00112 linmath_cat->error() 00113 << "Invalid coordinate_system value: " << (int)cs << "\n"; 00114 nassertr(false, out); 00115 return out; 00116 } 00117 00118 istream & 00119 operator >> (istream &in, CoordinateSystem &cs) { 00120 string word; 00121 in >> word; 00122 cs = parse_coordinate_system_string(word); 00123 if (cs == CS_invalid) { 00124 linmath_cat->error() 00125 << "Invalid coordinate_system string: " << word << "\n"; 00126 } 00127 return in; 00128 } 00129