Example #1
0
double RobotController::onAction(ActionEvent &evt)
{
	LOG_MSG(("\ncurrent time : %f", evt.time()));

	static int cnt = 0;

	try {
		const char *name = myname();
		SimObj *obj = getObj(name);
		obj->dump();
		if (!obj->dynamics()) {

			double angle = 2*PI*cnt*0.01;

			double xx = 5*sin(angle);
			double yy = 0.5;
			double zz = 5*cos(angle);
		
			LOG_MSG(("pos (%f, %f, %f)", xx, yy, zz));
			obj->setPosition(xx, yy, zz);
			obj->setAxisAndAngle(0.0, 1.0, 0.0, angle);
		}
		obj->dump();

	} catch(SimObj::NoAttributeException &) {
		
	} catch(SimObj::AttributeReadOnlyException &) {
		
	} catch(SimObj::Exception &) {
		
	}
	cnt++;

	return 0.1;
}
Example #2
0
double DetectEntitiesController::onAction(ActionEvent &evt)
{
	std::vector<std::string> agents;
	std::vector<std::string>::iterator i;
	static int count = 0;

	//	LOG_MSG(("bear onAction(count=%d)\n", count));

	bool b = detectEntities(agents);
	if (b)
	{
		int n = agents.size();
		if (n>0)
		{
			LOG_MSG(("%d entities detected", n));
			for (int i=0; i<n; i++)
			{
				std::string name = agents[i];
				LOG_MSG(("[%d] (%s)", i, name.c_str()));
			}
		}
	}
	else
	{
		LOG_MSG(("detectEntities failed"));
	}

	try {
		SimObj *o = getObj(myname());
		if (o && !o->dynamics())
		{
			double deg = count * 10.0;
			double rad = -3.141592/180*deg;

			o->setAxisAndAngle(0.0, 1.0, 0.0, rad);
		}
	} catch(SimObj::NoAttributeException &) {
	} catch(SimObj::AttributeReadOnlyException &) {
	} catch(SimObj::Exception &) {
	}

	count++;

	return 2.0;
}
Example #3
0
void SetAttrController::onRecvMessage(RecvMessageEvent &evt)
{
	double x, y, z;

	LOG_MSG(("message from : %s", evt.getSender()));
	int n = evt.getSize();
	for (int i=0; i<n; i++) {
		LOG_MSG(("[%d] (%s)", i, evt.getString(i)));
	}

	SimObj *o = getObj(myname());

	if (n>0 && o && !o->dynamics()) {
		const char *cmd = evt.getString(0);
		if (cmd) {
			if (strcmp(cmd, "p")==0) {
				// ----------------------------
				//	position set (x, y, z)
				// ----------------------------
				const char *param = evt.getString(1);
				if (param) {
					LOG_MSG(("set position (param=%s)", param));
					if (parseVector3(param, x, y, z)) {
						LOG_MSG(("(%f, %f, %f)", x, y, z));
						o->setPosition(x, y, z);
					}
				}
			} else if (strcmp(cmd, "vp")==0) {
				// ----------------------------
				//	view pos
				// ----------------------------
				const char *param = evt.getString(1);
				if (param) {
					LOG_MSG(("set view position (param=%s)", param));
					if (parseVector3(param, x, y, z)) {
						LOG_MSG(("(%f, %f, %f)", x, y, z));
						o->vpx(x);
						o->vpy(y);
						o->vpz(z);
					}
				}
			} else if (strcmp(cmd, "vv")==0) {
				// ----------------------------
				//	view vector
				// ----------------------------
				const char *param = evt.getString(1);
				if (param) {
					LOG_MSG(("set view vector (param=%s)", param));
					if (parseVector3(param, x, y, z)) {
						LOG_MSG(("(%f, %f, %f)", x, y, z));
						o->vvx(x);
						o->vvy(y);
						o->vvz(z);
					}
				}
			} else if (strcmp(cmd, "lep")==0) {
				// ----------------------------
				//	left eye pos
				// ----------------------------
				const char *param = evt.getString(1);
				if (param) {
					LOG_MSG(("set left eye position (param=%s)", param));
					if (parseVector3(param, x, y, z)) {
						LOG_MSG(("(%f, %f, %f)", x, y, z));
						o->lepx(x);
						o->lepy(y);
						o->lepz(z);
					}
				}
			} else if (strcmp(cmd, "lev")==0) {
				// ----------------------------
				//	left eye vector
				// ----------------------------
				const char *param = evt.getString(1);
				if (param) {
					LOG_MSG(("set left eye vector (param=%s)", param));
					if (parseVector3(param, x, y, z)) {
						LOG_MSG(("(%f, %f, %f)", x, y, z));
						o->levx(x);
						o->levy(y);
						o->levz(z);
					}
				}
			} else if (strcmp(cmd, "rep")==0) {
				// ----------------------------
				//	right eye pos
				// ----------------------------
				const char *param = evt.getString(1);
				if (param) {
					LOG_MSG(("set right eye position (param=%s)", param));
					if (parseVector3(param, x, y, z)) {
						LOG_MSG(("(%f, %f, %f)", x, y, z));
						o->repx(x);
						o->repy(y);
						o->repz(z);
					}
				}
			} else if (strcmp(cmd, "rev")==0) {
				// ----------------------------
				//	right eye vector
				// ----------------------------
				const char *param = evt.getString(1);
				if (param) {
					LOG_MSG(("set right eye vector (param=%s)", param));
					if (parseVector3(param, x, y, z)) {
						LOG_MSG(("(%f, %f, %f)", x, y, z));
						o->revx(x);
						o->revy(y);
						o->revz(z);
					}
				}
			}
		}
	}
}