⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 object.cpp

📁 2006年世界杯足球赛2D仿真组第16名的源代码。在此代码上随便改改
💻 CPP
字号:
/* *  Copyright 2002-2005, Mersad Team, Allameh Helli High School (NODET). * *  This program is free software, you can redistribute it and/or modify *  it under the terms of the GNU General Public License as published by *  the Free Software Foundation. * *  This program is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *  GNU Library General Public License for more details. * *  This file is created by: Ahmad Boorghany * *  Released on Monday 1 August 2005, 10 Mordad 1384 by Mersad RoboCup Team. *  For more information please read README file.*/#include <cmath>#include <cassert>#include <Config.h>#include <Degree.h>#include <Logger.h>#include <Object.h>#include <Defines.h>#include <SExpression.h>using namespace std;using namespace Degree;// class ObjectObject::Object(){	seeTime = 0;	velSeeTime = 0;	posDeviation = MAX_POS_DEV;	validPosDeviation = MAX_POS_DEV;	velDeviation = MAX_VEL_DEV;	readyToUpdateFlag = false;}Object::~Object(){}void Object::parse(const SExpression &exp, unsigned curTime){	SExpAtomic *at;	seeDistChange = NOVALUE;	seeDirChange = -NOVALUE;	seeDirection = -NOVALUE;	at = dynamic_cast<SExpAtomic *>(exp[1]);	assert(at);	seeDistance = at->asFloat();	unsigned decreaseNum = 0;	at = dynamic_cast<SExpAtomic *>(exp[exp.size() - 1]);	if (at->toString() == "t")		decreaseNum = 1;//LOG << "exp: " << exp.toString() << "<>" << exp.size() << endl;	if (exp.size() - decreaseNum > 2)	{		at = dynamic_cast<SExpAtomic *>(exp[2]);		assert(at);		seeDirection = at->asFloat();	}	if (exp.size() - decreaseNum > 4)	{		at = dynamic_cast<SExpAtomic *>(exp[3]);		assert(at);		seeDistChange = at->asFloat();		at = dynamic_cast<SExpAtomic *>(exp[4]);		assert(at);		seeDirChange = at->asFloat();		velSeeTime = curTime;	}	seeDirection *= -1;	seeDirChange *= -1;	seeTime = curTime;	readyToUpdateFlag = true;}void Object::setServerParamVars(const Param &serverParam){	maxMoment = serverParam["maxmoment"].asFloat();	minMoment = serverParam["minmoment"].asFloat();	maxPower = serverParam["maxpower"].asFloat();	minPower = serverParam["minpower"].asFloat();	quantizeStep = serverParam["quantize_step"].asFloat();	quantizeStepL = serverParam["quantize_step_l"].asFloat();}float Object::getDistance(const Object &obj) const{	return hypot(getPos().getX() - obj.getPos().getX(),				 getPos().getY() - obj.getPos().getY());}float Object::getDistance(const Point &point) const{	return hypot(getPos().getX() - point.x,				 getPos().getY() - point.y);}void Object::kill(){	posDeviation = MAX_POS_DEV;	validPosDeviation = MAX_POS_DEV;	velDeviation = MAX_VEL_DEV;}bool Object::isValid() const{	if (validPosDeviation < MAX_POS_DEV)		return true;	return false;}// Getting functionsbool Object::isReadyToUpdate() const{	return readyToUpdateFlag;}float Object::getPosDeviation() const{	return posDeviation;}float Object::getValidPosDeviation() const{	return validPosDeviation;}float Object::getVelDeviation() const{	return velDeviation;}float Object::getSeeDistance() const{	return seeDistance;}float Object::getSeeDirection() const{	return seeDirection;}float Object::getSeeDistChange() const{	return seeDistChange;}float Object::getSeeDirChange() const{	return seeDirChange;}unsigned Object::getSeeTime() const{	return seeTime;}unsigned Object::getVelSeeTime() const{	return velSeeTime;}float Object::getAccelMax() const{	return accelMax;}float Object::getDecay() const{	return decay;}float Object::getRand() const{	return rand;}float Object::getSize() const{	return size;}float Object::getSpeedMax() const{	return speedMax;}float Object::getMaxMoment() const{	return maxMoment;}float Object::getMinMoment() const{	return minMoment;}float Object::getMaxPower() const{	return maxPower;}float Object::getMinPower() const{	return minPower;}float Object::getQuantizeStep() const{	return quantizeStep;}float Object::getQuantizeStepL() const{	return quantizeStepL;}const Vector &Object::getPos() const{	return (const Vector &)position;}const Vector &Object::getVel() const{	return (const Vector &)velocity;}const Vector &Object::getAbsVec() const{	return (const Vector &)absVector;}const Vector &Object::getBodyVec() const{	return (const Vector &)bodyVector;}const Vector &Object::getHeadVec() const{	return (const Vector &)headVector;}// Setting functionsvoid Object::setReadyToUpdate(bool readyToUpdateFlagArg){	readyToUpdateFlag = readyToUpdateFlagArg;}void Object::setPosDeviation(float posDeviationArg){	posDeviation = posDeviationArg;}void Object::setValidPosDeviation(float validPosDeviationArg){	validPosDeviation = validPosDeviationArg;}void Object::setVelDeviation(float velDeviationArg){	velDeviation = velDeviationArg;}void Object::setSeeDistance(float seeDistanceArg){	seeDistance = seeDistanceArg;}void Object::setSeeDirection(float seeDirectionArg){	seeDirection = seeDirectionArg;}void Object::setSeeDistChange(float seeDistChangeArg){	seeDistChange = seeDistChangeArg;}void Object::setSeeDirChange(float seeDirChangeArg){	seeDirChange = seeDirChangeArg;}void Object::setSeeTime(unsigned seeTimeArg){	seeTime = seeTimeArg;}void Object::setVelSeeTime(unsigned velSeeTimeArg){	velSeeTime = velSeeTimeArg;}void Object::setDecay(float decayArg){	decay = decayArg;}Vector &Object::setPos(){	return (Vector &)position;}Vector &Object::setVel(){	return (Vector &)velocity;}Vector &Object::setAbsVec(){	return (Vector &)absVector;}Vector &Object::setBodyVec(){	return (Vector &)bodyVector;}Vector &Object::setHeadVec(){	return (Vector &)headVector;}// class Flagvoid FieldFlag::parse(int idArg, const SExpression &exp, unsigned curTime){	Object::parse(exp, curTime);	id = idArg;}void FieldFlag::update(const FieldData &fieldData){	Point point;	point = fieldData.getFlagPos(id);	position.setAsCartesian(point.x,point.y);	headVector.setAsPolar(seeDistance,seeDirection);	posDeviation = seeDistance / 20;	validPosDeviation = posDeviation;}int FieldFlag::getId() const{	return id;}// class Linevoid FieldLine::parse(int idArg, const SExpression &exp, unsigned curTime){	Object::parse(exp, curTime);	id = idArg;}void FieldLine::update(const FieldData &fieldData){	Point point;	point = fieldData.getLinePos(id);	position.setAsCartesian(point.x,point.y);	headVector.setAsPolar(seeDistance,seeDirection);	posDeviation = seeDistance / 20;	validPosDeviation = posDeviation;	prependOrient = fieldData.getPrependOrient(id);}int FieldLine::getId() const{	return id;}float FieldLine::getPrependOrient() const{	return prependOrient;}// class Goalvoid FieldGoal::parse(int idArg, const SExpression &exp, unsigned curTime){	Object::parse(exp, curTime);	id = idArg;}void FieldGoal::parseFullState(int idArg, const SExpression &exp,	   unsigned curTime){	SExpAtomic *at;	float x, y;	seeDistChange = NOVALUE;	seeDirChange = -NOVALUE;	seeDirection = -NOVALUE;	at = dynamic_cast<SExpAtomic *>(exp[1]);	assert(at);	x = at->asFloat();	at = dynamic_cast<SExpAtomic *>(exp[2]);	assert(at);	y = at->asFloat() * (-1);	position.setAsCartesian(x, y);		seeTime = curTime;	id = idArg;}void FieldGoal::update(const FieldData &fieldData){	Point point;	point = fieldData.getGoalPos(id);	position.setAsCartesian(point.x,point.y);	headVector.setAsPolar(seeDistance,seeDirection);	posDeviation = seeDistance / 20;	validPosDeviation = posDeviation;}int FieldGoal::getId() const{	return id;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -