Panda3D
coordinateSystem.cxx
1 // Filename: coordinateSystem.cxx
2 // Created by: drose (24Sep99)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "coordinateSystem.h"
16 #include "config_linmath.h"
17 #include "configVariableEnum.h"
18 #include "string_utils.h"
19 
20 #include "dconfig.h"
21 #include "pnotify.h"
22 
23 #include <ctype.h>
24 
26 ("coordinate-system", CS_zup_right,
27  PRC_DESC("The default coordinate system to use throughout Panda for "
28  "rendering, user input, and matrix operations, unless specified "
29  "otherwise."));
30 
31 
32 CoordinateSystem
33 get_default_coordinate_system() {
34  CoordinateSystem cs = default_cs;
35  return (cs == CS_default || cs == CS_invalid) ? CS_zup_right : cs;
36 }
37 
38 
39 CoordinateSystem
40 parse_coordinate_system_string(const string &str) {
41  if (cmp_nocase_uh(str, "default") == 0) {
42  return CS_default;
43 
44  } else if (cmp_nocase_uh(str, "zup") == 0 ||
45  cmp_nocase_uh(str, "zup-right") == 0 ||
46  cmp_nocase_uh(str, "z-up") == 0 ||
47  cmp_nocase_uh(str, "z-up-right") == 0) {
48  return CS_zup_right;
49 
50  } else if (cmp_nocase_uh(str, "yup") == 0 ||
51  cmp_nocase_uh(str, "yup-right") == 0 ||
52  cmp_nocase_uh(str, "y-up") == 0 ||
53  cmp_nocase_uh(str, "y-up-right") == 0) {
54  return CS_yup_right;
55 
56  } else if (cmp_nocase_uh(str, "z-up-left") == 0 ||
57  cmp_nocase_uh(str, "zup-left") == 0) {
58  return CS_zup_left;
59 
60  } else if (cmp_nocase_uh(str, "y-up-left") == 0 ||
61  cmp_nocase_uh(str, "yup-left") == 0) {
62  return CS_yup_left;
63  }
64 
65  return CS_invalid;
66 }
67 
68 string
69 format_coordinate_system(CoordinateSystem cs) {
70  ostringstream strm;
71  strm << cs;
72  return strm.str();
73 }
74 
75 bool
76 is_right_handed(CoordinateSystem cs) {
77  if (cs == CS_default) {
78  cs = get_default_coordinate_system();
79  }
80  switch (cs) {
81  case CS_zup_right:
82  case CS_yup_right:
83  return true;
84 
85  case CS_zup_left:
86  case CS_yup_left:
87  return false;
88 
89  default:
90  linmath_cat.error()
91  << "Invalid coordinate system value: " << (int)cs << "\n";
92  nassertr(false, false);
93  return false;
94  }
95 }
96 
97 ostream &
98 operator << (ostream &out, CoordinateSystem cs) {
99  switch (cs) {
100  case CS_default:
101  return out << "default";
102 
103  case CS_zup_right:
104  return out << "zup_right";
105 
106  case CS_yup_right:
107  return out << "yup_right";
108 
109  case CS_zup_left:
110  return out << "zup_left";
111 
112  case CS_yup_left:
113  return out << "yup_left";
114 
115  case CS_invalid:
116  return out << "invalid";
117  }
118 
119  linmath_cat->error()
120  << "Invalid coordinate_system value: " << (int)cs << "\n";
121  nassertr(false, out);
122  return out;
123 }
124 
125 istream &
126 operator >> (istream &in, CoordinateSystem &cs) {
127  string word;
128  in >> word;
129  cs = parse_coordinate_system_string(word);
130  if (cs == CS_invalid) {
131  linmath_cat->error()
132  << "Invalid coordinate_system string: " << word << "\n";
133  }
134  return in;
135 }
136 
This class specializes ConfigVariable as an enumerated type.