00001
00002 #include "Motion/WalkMC.h"
00003 #ifdef TGT_HAS_WALK
00004
00005 #include "Behaviors/Nodes/WalkNode.h"
00006 #include "DualCoding/VRmixin.h"
00007 #include "Shared/MarkScope.h"
00008 #include "Shared/Config.h"
00009
00010 bool WalkRequest::operator==(const WalkRequest& other) const {
00011 return ( x == other.x && y == other.y && a == other.a
00012 && time == other.time && velocityMode == other.velocityMode
00013 && filename == other.filename);
00014 }
00015
00016 std::ostream& operator<<(std::ostream &os, const WalkRequest &req) {
00017 os << "WalkRequest[x=" << req.x << ", y=" << req.y << ", a=" << req.a
00018 << ", time=" << req.time
00019 << ", velocityMode=" << (req.velocityMode ? "true" : "false")
00020 << ", storedVelocities=" << (req.storedVelocities ? "true" : "false")
00021 << "]" << std::endl;
00022 return os;
00023 }
00024
00025 void WalkNode::preStart() {
00026 MCNode<WalkMC,defWalkNodeName,defWalkNodeDesc>::preStart();
00027 if ( const DataEvent<WalkRequest> *ev = dynamic_cast<const DataEvent<WalkRequest>*>(event) )
00028 req = ev->getData();
00029 if ( !req.filename.empty() )
00030 getMC()->loadFile(::config->motion.makePath(req.filename).c_str());
00031
00032
00033
00034
00035 DualCoding::VRmixin::isWalkingFlag = true;
00036 }
00037
00038 void WalkNode::postStart() {
00039 MCNode<WalkMC,defWalkNodeName,defWalkNodeDesc>::postStart();
00040 if ( req.storedVelocities ) {
00041 if ( !req.velocityMode ) {
00042 getMC()->setTargetDisplacement(req.x, req.y, req.a, req.time);
00043 } else if ( req.time<0 ) {
00044 getMC()->setTargetVelocity(req.x, req.y, req.a);
00045 } else {
00046 getMC()->setTargetVelocity(req.x, req.y, req.a, req.time);
00047 }
00048 }
00049 }
00050
00051 void WalkNode::stop() {
00052 getMC()->zeroVelocities();
00053 DualCoding::VRmixin::isWalkingFlag = false;
00054 MCNode<WalkMC,defWalkNodeName,defWalkNodeDesc>::stop();
00055 }
00056
00057 void WalkNode::setDisplacement(float xdist, float ydist, float adist, float time) {
00058 req = WalkRequest(xdist,ydist,adist,time,false,req.filename);
00059 if(isActive())
00060 getMC()->setTargetDisplacement(req.x, req.y, req.a, req.time);
00061 }
00062
00063 void WalkNode::setVelocity(float xvel, float yvel, float avel) {
00064 req = WalkRequest(xvel,yvel,avel,req.filename);
00065 if(isActive())
00066 getMC()->setTargetVelocity(req.x, req.y, req.a);
00067 }
00068
00069 void WalkNode::setVelocity(float xvel, float yvel, float avel, float time) {
00070 req = WalkRequest(xvel,yvel,avel,time,true,req.filename);
00071 if(isActive())
00072 getMC()->setTargetVelocity(req.x, req.y, req.a, req.time);
00073 }
00074
00075 #endif