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