6 #include "vart/xmlscene.h"
7 #include "vart/xmljointaction.h"
8 #include "vart/collector.h"
9 #include "vart/action.h"
10 #include "vart/meshobject.h"
12 #include "vart/snlocator.h"
32 humanPtr->StickRightFoot();
33 humanPtr->moveLeftLegPtr->Activate();
38 humanPtr->StickLeftFoot();
39 humanPtr->moveRightLegPtr->Activate();
41 steppingRight = !steppingRight;
63 maxStepRotation(human.maxStepRotation),
64 isWalking(human.isWalking)
66 SceneNode* rootJointPtr;
70 rootJointPtr = ( *human.childList.begin() )->RecursiveCopy();
71 AddChild(*rootJointPtr);
72 SetDescription(human.GetDescription());
82 static const float delta = 3.5;
84 Point4D direction = pos - Position();
86 float stepAngle = maxStepRotation;
87 if (direction.Length() < delta)
89 float angle = direction.GenericAngleTo(forward);
92 if ((forward.GetZ()*direction.GetX() - forward.GetX()*direction.GetZ()) < 0)
96 if (angle > stepAngle)
105 if (angle > stepAngle)
114 Transform translation;
115 translation.MakeTranslation(displacement);
116 adjustment.CopyMatrix(translation * adjustment);
121 assert(
false &&
"VART::Human::Copy() not implemented!");
127 assert(
false &&
"VART::Human::ComputeBoundingBox() not implemented!");
133 position.CopyMatrix(adjustment * position);
134 pathToStickPosPtr = &pathToRFoot;
135 stickPositionPtr = &rfFront;
137 Point4D rightFootOffset;
138 ComputeLocalStickPosition(&rightFootOffset);
140 Point4D forward = position * orientation * (rightFootOffset - rfFront);
141 forward.SetY(-adjustment.GetData()[13]);
142 trans.MakeTranslation(forward);
143 position.CopyMatrix(trans * position);
149 position.CopyMatrix(adjustment * position);
150 pathToStickPosPtr = &pathToLFoot;
151 stickPositionPtr = &lfFront;
153 Point4D leftFootOffset;
154 ComputeLocalStickPosition(&leftFootOffset);
156 Point4D forward = position * orientation * (leftFootOffset - lfFront);
157 forward.SetY(-adjustment.GetData()[13]);
158 trans.MakeTranslation(forward);
159 position.CopyMatrix(trans * position);
165 position.TraverseDepthFirst(operatorPtr);
166 SceneNode::TraverseDepthFirst(operatorPtr);
173 orientation.LocateDepthFirst(locatorPtr);
174 if (locatorPtr->NotFinished())
175 SceneNode::LocateDepthFirst(locatorPtr);
181 glLoadName(pickName);
182 glPushName(pickName);
183 adjustment.DrawForPicking();
190 bool result = scene.LoadFromFile(fileName);
194 hipJointPtr =
dynamic_cast<Joint*
>(scene.GetObjects().front());
195 orientation.AddChild(*hipJointPtr);
196 scene.Unreference(hipJointPtr);
199 MeshObject* rightFootFingersMeshPtr =
200 dynamic_cast<MeshObject*
>(hipJointPtr->FindChildByName(
"R_footfingersMesh"));
201 assert(rightFootFingersMeshPtr != NULL);
202 hipJointPtr->FindPathTo(rightFootFingersMeshPtr, &pathToRFoot);
203 Point4D::xWeight = 0.1;
204 Point4D::yWeight = 3;
205 Point4D::zWeight = 2;
206 Point4D::operatorLess = &Point4D::WeightedLess;
207 rightFootFingersMeshPtr->SmallerVertex(&rfFront);
211 MeshObject* leftFootFingersMeshPtr =
212 dynamic_cast<MeshObject*
>(hipJointPtr->FindChildByName(
"L_footfingersMesh"));
213 assert(leftFootFingersMeshPtr != NULL);
214 hipJointPtr->FindPathTo(leftFootFingersMeshPtr, &pathToLFoot);
215 Point4D::xWeight = -0.1;
216 Point4D::yWeight = 3;
217 Point4D::zWeight = 2;
218 leftFootFingersMeshPtr->SmallerVertex(&lfFront);
219 Point4D::operatorLess = &Point4D::LexicographicalLess;
220 Dot* leftFootFrontDotPtr =
new Dot(lfFront);
221 leftFootFrontDotPtr->color = Color::RED();
222 leftFootFingersMeshPtr->AddChild(*leftFootFrontDotPtr);
223 stickPositionPtr = &lfFront;
224 pathToStickPosPtr = &pathToLFoot;
227 restPtr = LoadAction(
"rest.xml");
230 restPtr->SetPriority(1);
235 breathePtr = LoadAction(
"breathe.xml");
238 breathePtr->SetPriority(2);
239 breathePtr->Activate();
249 return adjustment.DrawOGL();
260 breathePtr->Activate();
262 breathePtr->Deactivate();
273 restPtr->Deactivate();
279 Transform translation;
280 translation.MakeTranslation(offset);
281 position.CopyMatrix(translation * position);
289 ComputeStickPosition(&rotCenter);
290 rotation.MakeRotation(rotCenter, Point4D::Y(), radians);
291 position.CopyMatrix(rotation * position);
293 rotation.ApplyTo(&forward);
298 static const float delta = 1.4;
299 Point4D location = adjustment * position * orientation * Point4D::ORIGIN();
300 Point4D distanceVector = destination - location;
302 distanceVector.SetY(0);
303 float distance = abs(distanceVector.Length());
305 return (distance < delta);
310 orientation.MakeXRotation(-1.5707963267948966192313216916398);
311 Transform translation;
312 translation.MakeTranslation(0, -rfFront.GetZ(), 0);
313 orientation.CopyMatrix(translation * orientation);
314 position.MakeIdentity();
315 adjustment.MakeIdentity();
320 return adjustment * position * orientation * Point4D::ORIGIN();
325 scenePtr->AddObject(
this);
330 assert(hipJointPtr != NULL);
331 XmlJointAction* actionPtr =
new XmlJointAction;
332 if (actionPtr->LoadFromFile(fileName, *hipJointPtr))
334 cerr <<
"Human::LoadAction (" << fileName <<
") OK" << endl;
335 actionList.push_back(actionPtr);
336 if (fileName ==
"right_front.xml")
338 moveRightLegPtr = actionPtr;
339 actionPtr->SetPriority(50);
341 if (fileName ==
"left_front.xml")
343 moveLeftLegPtr = actionPtr;
344 actionPtr->SetPriority(50);
350 cerr <<
"Human::LoadAction (" << fileName <<
") FAILED!" << endl;
360 pathToStickPosPtr->GetTransform(&transform);
361 *resultPtr = transform * (*stickPositionPtr);
367 ComputeLocalStickPosition(resultPtr);
368 *resultPtr = adjustment * position * orientation * *resultPtr;
373 Point4D stickPosition;
374 ComputeLocalStickPosition(&stickPosition);
378 adjustment.MakeTranslation(position * orientation * (*stickPositionPtr - stickPosition));
383 transPtr->CopyMatrix(adjustment * position * orientation);
391 cout <<
"Start walking" << endl;
392 moveLeftLegPtr->callbackPtr = &stepManager;
393 moveRightLegPtr->callbackPtr = &stepManager;
394 moveRightLegPtr->Activate();
395 cout <<
"stick position: " << *stickPositionPtr << endl;
396 restPtr->Deactivate();
401 if (moveLeftLegPtr->IsActive())
405 cout <<
"Stop walking" << endl;
406 moveLeftLegPtr->callbackPtr = NULL;
407 moveLeftLegPtr->Deactivate();
408 moveRightLegPtr->callbackPtr = NULL;
409 moveRightLegPtr->Deactivate();
419 float angle = AngleToPosition(dest, NULL);
426 list<JointAction*>::iterator iter = actionList.begin();
427 for(; iter != actionList.end(); ++iter)
429 (*iter)->ModifyDofMovers(modifier);
virtual void LocateDepthFirst(SNLocator *locatorPtr) const
void ModifyActions(DMModifier &modifier)
Modifies registered actions.
XmlJointAction * LoadAction(const std::string &fileName)
Loads action from given file name.
virtual void DrawForPicking() const
SGPath * pathToStickPosPtr
Transform adjustment
A transform that makes a point on human's geometry to stick at the ground.
Transform position
A transform that puts the human at his position and orientation.
void RotateOnY(float radians)
virtual bool DrawInstanceOGL() const
JointAction * moveRightLegPtr
void ActivateBreatheAction(bool status)
Transform orientation
A transform that puts the human vertical on Y, scales him to the right size and puts his feet at Y = ...
float AngleToPosition(const Point4D &pos, float *totalAngle) const
Builds its internal map of dof movers.
Articulated object for humanoid representation.
void ChangeAdjustment(const Point4D &displacement)
void ComputeStickPosition(Point4D *resultPtr)
virtual void ComputeBoundingBox()
Header file for V-ART class "Human" (contrib).
void ComputeTransform(Transform *transPtr)
void Move(const Point4D &offset)
bool isWalking
currently walking?
void ActivateRestAction(bool status)
bool LoadFromFile(const std::string &fileName)
Loads from a XML file.
virtual SceneNode * Copy()
Point4D forward
A vector that points forward on the floor plane (world coordinates)
void ComputeLocalStickPosition(Point4D *resultPtr)
Computes and returns the position of the right foot front.
Point4D * stickPositionPtr
bool WalkTo(const Point4D &dest, const Point4D &orientation)
bool ReachedDestiantion() const
Returns true if the human has reached its destination.
JointAction * moveLeftLegPtr
Human()
Creates an uninitialized humanoid.
void PutIntoScene(Scene *scenePtr)
Adds the humanoid to a scene.
virtual void TraverseDepthFirst(SNOperator *operatorPtr)
StepManager(Human *human)
float maxStepRotation
Maximal rotation (radians) during a single step.