📄 main.cpp
字号:
int len;
NMUDP1->ReadBuffer(buff, 4096, len);
AnsiString s;
if(buff[0]=='M'){
s = buff+2;
Memo1->Lines->Add(s);
return;
} else if (buff[0] == '!') {
MyPaint();
return;
}
geoDebug.push_back(buff);
// MyPaint();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::TrackBar1Change(TObject *Sender)
{
SendWM(TrackBar1->Position);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
if (!mLiveMonitor) {
TrackBar1->Position += interval;
if (TrackBar1->Position >= TrackBar1->Max) {
TrackBar1->Position = TrackBar1->Max - 1;
}
SendWM(TrackBar1->Position);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ToolButton5Click(TObject *Sender)
{
Timer1->Enabled = true;
if(interval<0)
interval = -interval;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ToolButton4Click(TObject *Sender)
{
Timer1->Enabled = false;
Timer1->Interval = 150;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ToolButton3Click(TObject *Sender)
{
Timer1->Enabled = true;
if(interval>0)
interval = -interval;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ToolButton2Click(TObject *Sender)
{
TrackBar1->Position --;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ToolButton6Click(TObject *Sender)
{
TrackBar1->Position ++;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ToolButton1Click(TObject *Sender)
{
TrackBar1->Position = 1;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ToolButton8Click(TObject *Sender)
{
Timer1->Interval /= 2;
if (Timer1->Interval > 150. / 8 - 1e-7) {
Timer1->Interval = 150. / 8;
}
/*
interval *=2;
if(interval>16)
interval = 16;
*/
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ToolButton7Click(TObject *Sender)
{
Timer1->Interval *= 2;
if (Timer1->Interval > 1200 - 1e-7) {
Timer1->Interval = 1200;
}
/*
interval /=2;
if(interval<1)
interval = 1;
*/
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer2Timer(TObject *Sender)
{
int i;
for(i=0;i<connects;i++)
{
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ServerSocket1ClientConnect(TObject *Sender,
TCustomWinSocket *Socket)
{
connects ++;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ServerSocket1ClientDisconnect(TObject *Sender,
TCustomWinSocket *Socket)
{
connects --;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Timer1->Enabled = false;
interval = 1;
if(OpenDialog1->Execute()){
for(int i=0;i<11;i++)
collWM[i].clear();
monitor.clear();
ReadFiles(OpenDialog1->Files);
SendWM(TrackBar1->Position);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
SendWM(TrackBar1->Position);
}
//---------------------------------------------------------------------------
void TForm1::ParseWM()
{
//TODO: Add your source code here
int myNumber;
double currentTime;
int pm;
double player_size=0.22,ball_size=0.111;
istringstream is(strWM);
string s;
// TCanvas* c = Image2->Canvas;
//===========================================
// my number
is>>s; is>>wm.myNumber;
// current time
is>>s; is>>wm.currentTime;
// play mode
is>>s; is>>wm.pm;
// sensation count
is>>s; is>>wm.mSensationCount;
// my position
is>>s; is>>wm.myPos.x>>wm.myPos.y>>wm.myPos.z;
// my velocity
is>>s; is>>wm.myVel.x>>wm.myVel.y>>wm.myVel.z;
// my position in the next cycle
is>>s; is>>wm.nextPos.x>>wm.nextPos.y>>wm.nextPos.z;
// my velocity in the next cycle
is>>s; is>>wm.nextVel.x>>wm.nextVel.y>>wm.nextVel.z;
// my pan angle && tile angle
is>>s; is>>wm.myPanAngle>>wm.myTiltAngle;
// positions of teammates
for(int i=0;i<11;i++){
is>>s>>s>>s;
is>>wm.ourPos[i].x>>wm.ourPos[i].y>>wm.ourPos[i].z;
is>>s>>s>>s;
is>>wm.ourVel[i].x>>wm.ourVel[i].y>>wm.ourVel[i].z;
if(i == wm.myNumber -1) {
wm.ourPos[i] = wm.myPos;
continue;
}
}
// positions of opponents
for(int i=0;i<11;i++){
is>>s>>s>>s;
is>>wm.oppPos[i].x>>wm.oppPos[i].y>>wm.oppPos[i].z;
is>>s>>s>>s;
is>>wm.oppVel[i].x>>wm.oppVel[i].y>>wm.oppVel[i].z;
}
// the position and velocity of the ball
is>>s;
is>>wm.ballPos.x>>wm.ballPos.y>>wm.ballPos.z;
is>>wm.ballVel.x>>wm.ballVel.y>>wm.ballVel.z;
// the cycles with no flag/player/ball seen
is >> s;
for (int i = 0; i < 8; ++i) { // flag
is >> wm.noflag[i];
}
for (int i = 0; i < 11; ++i) { // teammates
is >> wm.noour[i];
}
for (int i = 0; i < 11; ++i) { // oppenents
is >> wm.noopp[i];
}
is >> wm.noball;
// set onto screen
for (int i = 0; i < 11; ++ i) {
hMonitor.mGameState.SetPlayer(i,
Vector3(wm.ourPos[i].x, wm.ourPos[i].y, wm.ourPos[i].z),
TI_LEFT, i + 1);
hMonitor.mGameState.SetPlayer(11 + i,
Vector3(wm.oppPos[i].x, wm.oppPos[i].y, wm.oppPos[i].z),
TI_RIGHT, i + 1);
}
hMonitor.mGameState.SetPanTilt(wm.myPanAngle, wm.myTiltAngle,
Vector3(wm.myPos.x, wm.myPos.y, wm.myPos.z));
hMonitor.mGameState.SetBall(Vector3(wm.ballPos.x, wm.ballPos.y, wm.ballPos.z));
hMonitor.mGameState.SetTime(wm.currentTime);
hMonitor.mGameState.SetPlayMode(wm.pm);
}
Vector TForm1::RealToScreen(Vector p)
{
Vector result;
result.y=p.y*scale;
result.x=p.x*scale;
result.x += center.x;
result.y += center.y;
result.z += center.z;
return result;
}
void TForm1::MyPaint()
{
wglMakeCurrent(hdc, hrc);
// glOrtho(-1, 1, -1.2, 1, -1, 1);
//TODO: Add your source code here
Vector pos;
int i;
double x,y;
/*
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(1, 1, 1);
glBegin(GL_LINE_LOOP);
glVertex3f(0, 0, 0);
glVertex3f(0.5, 0, 0);
glVertex3f(0.5, 0.5, 0);
glVertex3f(0, 0.5, 0);
glEnd();
*/
if (monitor.size() > 0) {
// parse && display WM
if (!mLiveMonitor && !mMonitorOnly) {
if (!mMonitorOnly) {
ParseWM();
}
if (mShowReal || mMonitorOnly) {
Predicate predicate;
Parser::Parse(strWMReal, predicate);
if (!mMonitorOnly) {
hMonitor.mGameStateReal.ProcessInput(predicate);
} else {
hMonitor.mGameState.ProcessInput(predicate);
}
if (mFieldReverse) {
Vector3 pos;
if (!mMonitorOnly) {
hMonitor.mGameStateReal.GetBall(pos);
} else {
hMonitor.mGameState.GetBall(pos);
}
pos.x = -pos.x; pos.y = -pos.y;
if (!mMonitorOnly) {
hMonitor.mGameStateReal.SetBall(pos);
} else {
hMonitor.mGameState.SetBall(pos);
}
for (int i = 0; i < 22; ++ i) {
TTeamIndex side;
int unum;
double size;
if (!mMonitorOnly) {
hMonitor.mGameStateReal.GetPlayer(i, pos, side, unum, size);
} else {
hMonitor.mGameState.GetPlayer(i, pos, side, unum, size);
}
pos.x = -pos.x; pos.y = -pos.y;
if (!mMonitorOnly) {
hMonitor.mGameStateReal.SetPlayer(i, pos, side, unum);
} else {
hMonitor.mGameState.SetPlayer(i, pos, side, unum);
}
}
}
}
}
if (mMonitorOnly) {
mShowReal = false;
}
if (mFieldReverse) {
swap(wm.noflag[0], wm.noflag[3]);
swap(wm.noflag[1], wm.noflag[2]);
swap(wm.noflag[4], wm.noflag[7]);
swap(wm.noflag[5], wm.noflag[6]);
}
hMonitor.Display(geoDebug, mShowReal, mMonitorOnly || mLiveMonitor, wm);
if (mFieldReverse) {
swap(wm.noflag[0], wm.noflag[3]);
swap(wm.noflag[1], wm.noflag[2]);
swap(wm.noflag[4], wm.noflag[7]);
swap(wm.noflag[5], wm.noflag[6]);
}
}
glFlush();
SwapBuffers(hdc);
wglMakeCurrent(hdc,NULL);
return;
}
void __fastcall TForm1::FormPaint(TObject *Sender)
{
MyPaint();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormMouseDown(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
if (Button == mbLeft) {
mouse_left_down = true;
mouse = Vector(X,Y);
hMonitor.Mouse(0, 0, X, Y);
} else if (Button == mbRight) {
mouse_right_down = true;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormMouseMove(TObject *Sender, TShiftState Shift,
int X, int Y)
{
/*
if(mouse_down){
center += (Vector(X,Y)-mouse);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -