One who can write a code?
CodePudding user response:
# include & lt; Iostream>
#include
#include
#include
using namespace std;
Typedef struct MOVE {
VectorThe start;
Vectorend;
VectorThe location;
VectorDirection;
Float speedPerMs;
long time=0;
Long endTime=0;
Long timeGap=0;
MOVE (vectorStart, vector End, float speedPerMs, long time) : start (start) and end (the end), location (start), speedPerMs (speedPerMs), time (time) {
Auto length=(float) SQRT (pow (end [0] - start [0], 2) + pow (end [1] - start [1], 2));
Direction={(end [0] - start [0])/length, (end [1] - start [1])/length};
TimeGap=length/speedPerMs;
EndTime=time + timeGap;
}
} moveInfo;
Void move (moveInfo& Info, long time) {
Int dt=time - info. Time;
The info. The location of [0] +=info. Direction [0] * * info in dt speedPerMs;
The info. The location of [1] +=info. Direction [1] * * info in dt speedPerMs;
Info. Time=the time;
If (time & gt;=info. EndTime) {
The info. The location=info. End;
Info. End=info. Start;
Info. Start=info. The location;
Info. Direction={- info. Direction [0], - info. Direction [1]}.
The info. The endTime +=info. TimeGap;
}
}
Int main () {
Struct timeval time {};
Mingw_gettimeofday (& amp; Time, nullptr);
MoveInfo info ({0, 0}, {3, 5}, 0.01, and time. The tv_sec * 1000 + time. Tv_usec/1000);
For (int I=0; i <3000; + + I) {
Mingw_gettimeofday (& amp; Time, nullptr);
Move (info, time. Tv_sec * 1000 + time. Tv_usec/1000);
Cout}
}