Panda3D
 All Classes Functions Variables Enumerations
coordinateSystem.cxx
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 string
00069 format_coordinate_system(CoordinateSystem cs) {
00070   ostringstream strm;
00071   strm << cs;
00072   return strm.str();
00073 }
00074 
00075 bool
00076 is_right_handed(CoordinateSystem cs) {
00077   if (cs == CS_default) {
00078     cs = get_default_coordinate_system();
00079   }
00080   switch (cs) {
00081   case CS_zup_right:
00082   case CS_yup_right:
00083     return true;
00084 
00085   case CS_zup_left:
00086   case CS_yup_left:
00087     return false;
00088 
00089   default:
00090     linmath_cat.error()
00091       << "Invalid coordinate system value: " << (int)cs << "\n";
00092     nassertr(false, false);
00093     return false;
00094   }
00095 }
00096 
00097 ostream &
00098 operator << (ostream &out, CoordinateSystem cs) {
00099   switch (cs) {
00100   case CS_default:
00101     return out << "default";
00102 
00103   case CS_zup_right:
00104     return out << "zup_right";
00105 
00106   case CS_yup_right:
00107     return out << "yup_right";
00108 
00109   case CS_zup_left:
00110     return out << "zup_left";
00111 
00112   case CS_yup_left:
00113     return out << "yup_left";
00114 
00115   case CS_invalid:
00116     return out << "invalid";
00117   }
00118 
00119   linmath_cat->error()
00120     << "Invalid coordinate_system value: " << (int)cs << "\n";
00121   nassertr(false, out);
00122   return out;
00123 }
00124 
00125 istream &
00126 operator >> (istream &in, CoordinateSystem &cs) {
00127   string word;
00128   in >> word;
00129   cs = parse_coordinate_system_string(word);
00130   if (cs == CS_invalid) {
00131     linmath_cat->error()
00132       << "Invalid coordinate_system string: " << word << "\n";
00133   }
00134   return in;
00135 }
00136 
 All Classes Functions Variables Enumerations