28 double deltang = angle2 - angle1;
29 while (deltang < -180.0) deltang += 360.0;
30 while (deltang > 180.0) deltang -= 360.0;
40 while (angle < 0.0) angle += 360.0;
41 while (angle > 360.0) angle -= 360.0;
50 void PointerEventList::
51 output(std::ostream &out)
const {
52 if (_events.empty()) {
53 out <<
"(no pointers)";
55 Events::const_iterator ei;
59 while (ei != _events.end()) {
70 void PointerEventList::
71 write(std::ostream &out,
int indent_level)
const {
72 indent(out, indent_level) << _events.size() <<
" events:\n";
73 Events::const_iterator ei;
74 for (ei = _events.begin(); ei != _events.end(); ++ei) {
75 indent(out, indent_level + 2) << (*ei) <<
"\n";
85 pe._in_window = data._in_window;
86 pe._type = data._type;
88 pe._xpos = data._xpos;
89 pe._ypos = data._ypos;
90 pe._pressure = data._pressure;
93 if (_events.size() > 0) {
94 pe._dx = data._xpos - _events.back()._xpos;
95 pe._dy = data._ypos - _events.back()._ypos;
98 pe._length = csqrt(ddx*ddx + ddy*ddy);
99 if (pe._length > 0.0) {
102 pe._direction = _events.back()._direction;
104 pe._rotation =
delta_angle(_events.back()._direction, pe._direction);
112 _events.push_back(pe);
120 add_event(
bool in_win,
int xpos,
int ypos,
int seq,
double time) {
122 pe._in_window = in_win;
127 if (_events.size() > 0) {
128 pe._dx = xpos - _events.back()._xpos;
129 pe._dy = ypos - _events.back()._ypos;
132 pe._length = csqrt(ddx*ddx + ddy*ddy);
133 if (pe._length > 0.0) {
136 pe._direction = _events.back()._direction;
138 pe._rotation =
delta_angle(_events.back()._direction, pe._direction);
146 _events.push_back(pe);
153 add_event(
bool in_win,
int xpos,
int ypos,
double xdelta,
double ydelta,
int seq,
double time) {
155 pe._in_window = in_win;
162 pe._length = csqrt(xdelta*xdelta + ydelta*ydelta);
163 if (pe._length > 0.0) {
165 }
else if (!_events.empty()) {
166 pe._direction = _events.back()._direction;
170 if (!_events.empty()) {
171 pe._rotation =
delta_angle(_events.back()._direction, pe._direction);
175 _events.push_back(pe);
183 int tot_events = _events.size();
184 if (tot_events < 3) {
187 int last = tot_events-1;
188 double dx = _events[last]._xpos - x;
189 double dy = _events[last]._ypos - y;
190 double lastang = rad_2_deg(catan2(dy, dx));
192 for (
int i=last; (i>=0) && (total < 360.0) && (total > -360.0); i--) {
193 dx = _events[i]._xpos - x;
194 dy = _events[i]._ypos - y;
195 if ((dx==0.0)&&(dy==0.0)) {
198 double angle = rad_2_deg(catan2(dy,dx));
200 if (deltang * total < 0.0) {
206 return (total > 360.0) || (total < -360.0);
218 int pos = _events.size()-1;
220 while ((pos >= 0)&&(_events[pos]._time >= old)) {
221 double rot = _events[pos]._rotation;
222 if (rot < 0.0) rot = -rot;
242 vector_double pattern;
243 parse_pattern(ascpat, pattern);
246 for (
size_t i=0; i<pattern.size(); i++) {
256 void PointerEventList::
257 parse_pattern(
const std::string &ascpat, vector_double &pattern) {
260 for (
size_t i=0; i<ascpat.size(); i++) {
263 if ((c==
'E')||(c==
'e')) ang=0.0;
264 else if ((c==
'N')||(c==
'n')) ang=90.0;
265 else if ((c==
'W')||(c==
'w')) ang=180.0;
266 else if ((c==
'S')||(c==
's')) ang=270.0;
269 double newang = dir + offset;
273 if ((c !=
' ')&&(c !=
'\t')) {
274 event_cat.warning() <<
275 "Invalid pattern in PointerEventList::match_pattern\n";
280 pattern.push_back(dir);
287 pattern.push_back(dir);
290 std::cerr <<
"Pattern: ";
291 for (
int i=0; i<(int)pattern.size(); i++) {
292 std::cerr << pattern[i] <<
" ";
static ClockObject * get_global_clock()
Returns a pointer to the global ClockObject.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
double delta_angle(double angle1, double angle2)
Compute the difference between two angles.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
double total_turns(double sec) const
returns the total angular deviation that the trail has made in the specified time period.
void add_event(const PointerData &data, int seq, double time)
Adds a new event from the given PointerData object.
get_frame_time
Returns the time in seconds as of the last time tick() was called (typically, this will be as of the ...
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Holds the data that might be generated by a 2-d pointer input device, such as the mouse in the Graphi...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
double normalize_angle(double angle)
Compute the difference between two angles.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle is the identifier used to differentiate C++ class types.
double match_pattern(const std::string &pattern, double rot, double seglen)
This function is not implemented yet.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool encircles(int x, int y) const
Returns true if the trail loops around the specified point.
Records a pointer movement event.