forked from rtv/Stage
/
model_getset.cc
227 lines (176 loc) · 3.99 KB
/
model_getset.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#include "stage.hh"
using namespace Stg;
void Model::SetGeom( const Geom& val )
{
UnMapWithChildren();
geom = val;
blockgroup.CalcSize();
NeedRedraw();
MapWithChildren();
CallCallbacks( CB_GEOM );
}
void Model::SetColor( Color val )
{
color = val;
NeedRedraw();
}
void Model::SetMass( stg_kg_t val )
{
mass = val;
}
void Model::SetStall( stg_bool_t val )
{
stall = val;
}
void Model::SetGripperReturn( int val )
{
vis.gripper_return = val;
}
void Model::SetFiducialReturn( int val )
{
vis.fiducial_return = val;
// non-zero values mean we need to be in the world's set of
// detectable models
if( val == 0 )
world->FiducialErase( this );
else
world->FiducialInsert( this );
}
void Model::SetFiducialKey( int val )
{
vis.fiducial_key = val;
}
void Model::SetLaserReturn( stg_laser_return_t val )
{
vis.laser_return = val;
}
void Model::SetObstacleReturn( int val )
{
vis.obstacle_return = val;
}
void Model::SetBlobReturn( int val )
{
vis.blob_return = val;
}
void Model::SetRangerReturn( int val )
{
vis.ranger_return = val;
}
void Model::SetBoundary( int val )
{
boundary = val;
}
void Model::SetGuiNose( int val )
{
gui.nose = val;
}
void Model::SetGuiMove( int val )
{
gui.move = val;
}
void Model::SetGuiGrid( int val )
{
gui.grid = val;
}
void Model::SetGuiOutline( int val )
{
gui.outline = val;
}
void Model::SetWatts( stg_watts_t val )
{
watts = val;
}
void Model::SetMapResolution( stg_meters_t val )
{
map_resolution = val;
}
// set the pose of model in global coordinates
void Model::SetGlobalPose( const Pose& gpose )
{
SetPose( parent ? parent->GlobalToLocal( gpose ) : gpose );
}
int Model::SetParent( Model* newparent)
{
// remove the model from its old parent (if it has one)
if( parent )
parent->RemoveChild( this );
else
world->RemoveChild( this );
// link from the model to its new parent
this->parent = newparent;
if( newparent )
newparent->AddChild( this );
else
world->AddModel( this );
CallCallbacks( CB_PARENT );
SetGlobalPose( oldPose ); // Needs to recalculate position due to change in parent
return 0; //ok
}
// get the model's velocity in the global frame
Velocity Model::GetGlobalVelocity() const
{
Pose gpose = GetGlobalPose();
double cosa = cos( gpose.a );
double sina = sin( gpose.a );
Velocity gv;
gv.x = velocity.x * cosa - velocity.y * sina;
gv.y = velocity.x * sina + velocity.y * cosa;
gv.a = velocity.a;
return gv;
}
// set the model's velocity in the global frame
void Model::SetGlobalVelocity( const Velocity& gv )
{
Pose gpose = GetGlobalPose();
double cosa = cos( gpose.a );
double sina = sin( gpose.a );
Velocity lv;
lv.x = gv.x * cosa + gv.y * sina;
lv.y = -gv.x * sina + gv.y * cosa;
lv.a = gv.a;
this->SetVelocity( lv );
}
// get the model's position in the global frame
Pose Model::GetGlobalPose() const
{
// if I'm a top level model, my global pose is my local pose
if( parent == NULL )
return pose;
// otherwise
Pose global_pose = parent->GetGlobalPose() + pose;
if ( parent->stack_children ) // should we be on top of our parent?
global_pose.z += parent->geom.size.z;
return global_pose;
}
void Model::VelocityEnable()
{
velocity_enable = true;
world->active_velocity.insert( this );
}
void Model::VelocityDisable()
{
velocity_enable = false;
world->active_velocity.erase( this );
}
void Model::SetVelocity( const Velocity& val )
{
velocity = val;
CallCallbacks( CB_VELOCITY );
}
// set the model's pose in the local frame
void Model::SetPose( const Pose& newpose )
{
// if the pose has changed, we need to do some work
if( memcmp( &pose, &newpose, sizeof(Pose) ) != 0 )
{
pose = newpose;
pose.a = normalize(pose.a);
// if( isnan( pose.a ) )
// printf( "SetPose bad angle %s [%.2f %.2f %.2f %.2f]\n",
// token, pose.x, pose.y, pose.z, pose.a );
NeedRedraw();
MapWithChildren();
world->dirty = true;
}
CallCallbacks( CB_POSE );
}