Skip to content
Snippets Groups Projects
Commit 52920184 authored by user's avatar user
Browse files

Corrections

parent 39596f2c
No related branches found
No related tags found
2 merge requests!19Master,!17Jehoiakim
#include "MoveUtils.h"
// Méthode partagée par tous les comportements et permettant
// de définir leurs nouveaux paramètres de déplacement
void MoveUtils::setMoveParameters(Animal& a, int& x, int& y, int xLim, int yLim, double& orientation, double& speed, double& cumulX, double& cumulY){
double nx, ny;
double dx = cos( orientation )*speed;
double dy = -sin( orientation )*speed;
int cx, cy;
cx = static_cast<int>( cumulX ); cumulX -= cx;
cy = static_cast<int>( cumulY ); cumulY -= cy;
nx = x + dx + cx;
ny = y + dy + cy;
if ( (nx < 0) || (nx > xLim - 1) ) {
orientation = M_PI - orientation;
cumulX = 0.;}
else {
x = static_cast<int>( nx );
cumulX += nx - x;}
if ( (ny < 0) || (ny > yLim - 1) ) {
orientation = -orientation;
cumulY = 0.;}
else {
y = static_cast<int>( ny );
cumulY += ny - y;}
a.setCoordinates(x,y);
a.setCumul(cumulX,cumulY);
a.setOrientationSpeed(orientation,speed);
}
\ No newline at end of file
#ifndef MOVE_UTILS_H
#define MOVE_UTILS_H
#include "Animal.h"
class MoveUtils{
public:
static void setMoveParameters(Animal& a, int& x, int& y, int xLim, int yLim, double& orientation, double& speed, double& cumulX, double& cumulY);
};
#endif
\ No newline at end of file
#include "moveUtils.h"
void MoveUtils::setMoveParameters(Animal& a, int& x, int& y, int xLim, int yLim, double& orientation, double& speed, double& cumulX, double& cumulY){
double nx, ny;
double dx = cos( orientation )*speed;
double dy = -sin( orientation )*speed;
int cx, cy;
cx = static_cast<int>( cumulX ); cumulX -= cx;
cy = static_cast<int>( cumulY ); cumulY -= cy;
nx = x + dx + cx;
ny = y + dy + cy;
if ( (nx < 0) || (nx > xLim - 1) ) {
orientation = M_PI - orientation;
cumulX = 0.;}
else {
x = static_cast<int>( nx );
cumulX += nx - x;}
if ( (ny < 0) || (ny > yLim - 1) ) {
orientation = -orientation;
cumulY = 0.;}
else {
y = static_cast<int>( ny );
cumulY += ny - y;}
a.setCoordinates(x,y);
a.setCumul(cumulX,cumulY);
a.setOrientationSpeed(orientation,speed);
}
\ No newline at end of file
#ifndef MOVE_UTILS_H
#define MOVE_UTILS_H
#include "Animal.h"
class MoveUtils{
public:
static void setMoveParameters(Animal& a, int& x, int& y, int xLim, int yLim, double& orientation, double& speed, double& cumulX, double& cumulY);
};
#endif
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment