📄 monitor.cpp
字号:
// goal box area right side
glColor4dv(sLineColor);
mGLServer.DrawGroundRectangle(Vector3(fl/2 - sGoalBoxLength, -gw/2 - sGoalBoxLength, 0.05), lw, gw + 11, 0);
mGLServer.DrawGroundRectangle(Vector3(fl/2 - sGoalBoxLength, -gw/2 - sGoalBoxLength, 0.05), sGoalBoxLength, lw, 0);
mGLServer.DrawGroundRectangle(Vector3(fl/2 - sGoalBoxLength, gw/2 + sGoalBoxLength, 0.05), sGoalBoxLength, lw, 0);
// goal box area left side
mGLServer.DrawGroundRectangle(Vector3(-fl/2 + sGoalBoxLength, -gw/2 - sGoalBoxLength, 0.05), lw, gw + 11, 0);
mGLServer.DrawGroundRectangle(Vector3(-fl/2 + sGoalBoxLength, -gw/2 - sGoalBoxLength, 0.05), -sGoalBoxLength, lw, 0);
mGLServer.DrawGroundRectangle(Vector3(-fl/2 + sGoalBoxLength, gw/2 + sGoalBoxLength, 0.05), -sGoalBoxLength, lw, 0);
// penalty area right side
mGLServer.DrawGroundRectangle(Vector3(fl/2 - sPenaltyLength, -gw/2 - sPenaltyLength, 0.05), lw, gw + 33, 0);
mGLServer.DrawGroundRectangle(Vector3(fl/2 - sPenaltyLength, -gw/2 - sPenaltyLength, 0.05), sPenaltyLength, lw, 0);
mGLServer.DrawGroundRectangle(Vector3(fl/2 - sPenaltyLength, gw/2 + sPenaltyLength, 0.05), sPenaltyLength, lw, 0);
// penalty area left side
mGLServer.DrawGroundRectangle(Vector3(-fl/2 + sPenaltyLength, -gw/2 - sPenaltyLength, 0.05), lw, gw + 33, 0);
mGLServer.DrawGroundRectangle(Vector3(-fl/2 + sPenaltyLength, -gw/2 - sPenaltyLength, 0.05), -sPenaltyLength, lw, 0);
mGLServer.DrawGroundRectangle(Vector3(-fl/2 + sPenaltyLength, gw/2 + sPenaltyLength, 0.05), -sPenaltyLength, lw, 0);
// center circle
mGLServer.DrawCircle(Vector3(0.0,0.0,0.05), sCenterRadius);
// fieldBox
mGLServer.DrawWireBox(Vector3(-fl/2.0,-fw/2.0,0.0),
Vector3(fl,fw,fh));
// draw shadows of cached positions
DrawScene(0, geoDebug, showReal, monitorOnly, wm);
glEnable(GL_DEPTH_TEST);
// goal
glColor4dv(sGoalColor);
mGLServer.DrawWireBox(Vector3(-fl/2,-gw/2.0,0),szGoal1);
// mGLServer.DrawGoal(Vector3(-fl/2,-gw/2.0,0),szGoal1,lw/2.0);
mGLServer.DrawGoal(Vector3(-fl/2-szGoal1.x,-gw/2.0,0),szGoal1,lw/2.0);
// goal
glColor4dv(sGoalColor);
mGLServer.DrawWireBox(Vector3(fl/2,-gw/2.0,0),szGoal2);
// mGLServer.DrawGoal(Vector3(fl/2,-gw/2.0,0),szGoal2,lw/2.0);
mGLServer.DrawGoal(Vector3(fl/2+szGoal2.x,-gw/2.0,0),szGoal2,lw/2.0);
// flags
if (!monitorOnly) {
double pos[8][2] = {-fl/2, -fw/2, fl/2, -fw/2, -fl/2, fw/2, fl/2, fw/2,
-fl/2, -gw/2, fl/2, -gw/2, -fl/2, gw/2, fl/2, gw/2};
for (int i = 0; i < 8; ++i) {
GLdouble tmp[4];
memcpy(tmp, sSphereDefaultColor, sizeof(tmp));
if (wm.noflag[i] > 0) {
tmp[0] /= 3; tmp[1] /= 3; tmp[2] /= 3;
tmp[3] = 0.8;
}
glColor4dv(tmp);
mGLServer.DrawSphere(Vector3(pos[i][0], pos[i][1], 0.3), 0.3, 20);
}
}
// draw cached positions
DrawScene(1, geoDebug, showReal, monitorOnly, wm);
DrawStatusText();
// draw 2D Elements
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluOrtho2D(-1, 1, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// draw the info text
DrawStatusLine();
// draw two dimensional overview
if (mDrawOverview)
{
DrawOverview();
}
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
// (end 2D Elements)
// glutSwapBuffers();
}
void
Monitor::MouseMotion(int x, int y)
{
Vector2 tmp(static_cast<double>(x), static_cast<double>(y));
mGLServer.SetViewByMouse(tmp, mMousePosition);
mMousePosition = tmp;
// glutPostRedisplay();
}
void
Monitor::Keyboard(unsigned char key, int /*x*/, int /*y*/)
{
Vector3 pos;
switch (key) {
case 'W':
//move cam in
mGLServer.MoveCamForward(mCamDelta);
break;
case 'S':
//move cam out
mGLServer.MoveCamForward(-mCamDelta);
break;
case 'A':
//strafe cam left
mGLServer.MoveCamStrafe(mCamDelta);
break;
case 'D':
// strafe cam right
mGLServer.MoveCamStrafe(-mCamDelta);
break;
case 'C':
// select camera mode
mCameraMode = NextCameraMode(mCameraMode);
break;
case VK_ADD:
//move camera up
mGLServer.MoveCamUp(mCamDelta);
break;
case VK_SUBTRACT:
//move camera down
mGLServer.MoveCamUp(-mCamDelta);
break;
case 'N':
// toggle drawing of unums
mDrawUnums = !mDrawUnums;
break;
case '2':
// toggle drawing of 2D overview
mDrawOverview = !mDrawOverview;
break;
case 'Q':
case VK_ESCAPE:
// quit
// mCommServer->SendDisconnectCmd();
exit(0);
case 'K' :
// kick off
// mCommServer->SendKickOffCmd(mKickOff);
break;
case 'B':
// drop ball
// mCommServer->SendDropBallCmd();
break;
case 'P' :
// pause simulation
// cout <<"--- Pausing Simulation" << endl;
mCommServer->SendPauseCmd();
break;
// case ' ':
// mKickOff = NextKickOffMode(mKickOff);
// break;
case 'R' :
// run simulation (after pause command)
cout <<"--- Running Simulation" << endl;
// mCommServer->SendRunCmd();
break;
//JAN
case ',' :
// toggle single step mode (aka _m_anual advance), forward
mSingleStep = !mSingleStep;
mAdvance = 0;
mBackward = false;
break;
case 'M' :
// toggle single step mode (aka _m_anual advance), backward
mSingleStep = !mSingleStep;
mAdvance = 0;
mBackward = true;
break;
case '?' :
// show keybindings
KeyBindings();
break;
#if 0
case 'V':
case 'v':
mCommServer->SendToWorldModel("(ball (pos 49 20 1) (vel 6.0 0.0 0.1))");
break;
#endif
default:
return;
}
// glutPostRedisplay();
}
void
Monitor::SpecialKeys(int glutkey, int /*x*/, int /*y*/)
{
/*
Vector3 pos;
switch (glutkey) {
case GLUT_KEY_UP:
//strafe cam forward
mGLServer.MoveCamStrafeForward(mCamDelta);
break;
case GLUT_KEY_DOWN:
//strafe cam back
mGLServer.MoveCamStrafeForward(-mCamDelta);
break;
case GLUT_KEY_LEFT:
// advance a step, backward
mAdvance = -1;
mSingleStep = true;
break;
case GLUT_KEY_RIGHT:
// advance a step, forward
mAdvance = 1;
mSingleStep = true;
break;
default:
return;
}
*/
// glutPostRedisplay();
}
void
Monitor::Mouse(int /*button*/, int /*state*/, int x, int y)
{
mMousePosition = Vector2(static_cast<double>(x),
static_cast<double>(y));
}
void
Monitor::Reshape(int width, int height)
{
mGLServer.Reshape(width,height);
}
void
Monitor::Idle()
{
if (mGameState.IsFinished())
{
cerr << "simulation finished... monitor exiting\n";
exit(0);
}
mCommServer->ReadMessage();
vector<Predicate>& predicates = mCommServer->GetPredicates();
if (mLogserver) {
if (mSingleStep) {
if (!mAdvance) {
return;
} else {
mCycle += mAdvance;
}
} else {
if (!mBackward) {
++ mCycle;
} else {
-- mCycle;
}
}
} else {
mCycle = predicates.size() - 1;
}
if (mCycle < 0) {
mCycle = 0;
mSingleStep = true;
} else if (mCycle >= predicates.size()) {
mCycle = predicates.size() - 1;
}
mGameState.SetCycle(mCycle);
mGameState.ProcessInput(predicates);
mAdvance = 0;
// glutPostRedisplay();
}
void Monitor::KeyBindings()
{
std::cerr <<
"\n\nKeybindings for rcssmonitor3D-lite:\n"
"\n"
"----------------------------------------------------\n"
"GENERAL\n"
"----------------------------------------------------\n"
"q | quit the monitor\n"
"p | pause the simulation/logplayer\n"
"r | unpause the simulation/logplayer\n"
"n | toggle display of uniform numbers\n"
"2 | toggle display of two dimensional overview\n"
"? | display keybindings\n"
"----------------------------------------------------\n"
"CAMERA MOVEMENT\n"
"----------------------------------------------------\n"
"c | toggle automatic (ball centered) camera\n"
"w/s | move camera forward/back (zoomlike)\n"
"a/d | move camera left/right\n"
"+/- | move camera up/down\n"
"Arrow up/down | move camera\n"
"----------------------------------------------------\n"
"SIMULATION\n"
"----------------------------------------------------\n"
"k | kick off (start the game)\n"
"b | drop the ball at its current position\n"
"[SPACE] | toggle kick off side (left-right-random)\n"
"----------------------------------------------------\n"
"LOGPLAYER\n"
"----------------------------------------------------\n"
"m | toggle single step mode for logplayer backward\n"
", | toggle single step mode for logplayer forward\n"
"Arrow left | move one step backward\n"
"Arrow right | move one step forward\n"
"----------------------------------------------------\n"
"\n";
}
Monitor::ECameraMode
Monitor::NextCameraMode(ECameraMode mode) const
{
switch (mode)
{
case eFree: return eFollowBall;
default: return eFree;
}
}
CommServerBase::EKickOff
Monitor::NextKickOffMode(CommServerBase::EKickOff mode) const
{
switch (mode)
{
case CommServerBase::eRandom: return CommServerBase::eLeft;
case CommServerBase::eLeft: return CommServerBase::eRight;
default: return CommServerBase::eRandom;
}
}
Monitor* Monitor::instMonitor = NULL;
// color constants
const GLdouble
Monitor::sGroundColor[4] = {0.1f, 0.5f, 0.1f, 1.0f};
const GLdouble
Monitor::sGoalColor[4] = {1.0f, 1.0f, 1.0f, 1.0f};
const GLdouble
Monitor::sBorderColor[4] = {0.2f, 0.8f, 0.2f, 1.0f};
const GLdouble
Monitor::sLineColor[4] = {0.6f, 1.0f, 0.6f, 1.0f};
const GLdouble
Monitor::sSphereDefaultColor[4] = { 0.8, 0.8, 0.2, 1.0 };
const GLdouble
Monitor::sUnumColor[4] = {1.0, 1.0, 1.0, 1.0};
// color for player of the different teams
GLdouble
Monitor::sTeamColorLeft[4] = {0.2f, 0.2f, 1.0f, 1.0f};
GLdouble
Monitor::sTeamColorRight[4] = {1.0f, 0.2f, 0.2f, 1.0f};
GLdouble
Monitor::sTeamColorNoSeen[4] = {0.5f, 0.5f, 0.5f, 0.5f};
// ball color
GLdouble
Monitor::sBallColor[4] = {1.0f, 1.0f, 1.0f, 1.0f};
// radius of center circle
const double
Monitor::sCenterRadius = 9.15;
// length of the goal box
const double
Monitor::sGoalBoxLength = 5.5;
// length of the penalty area
const double
Monitor::sPenaltyLength = 16.5;
// 2D Overview constants
const double
Monitor::s2DLowX = 0.01; // left pos
const double
Monitor::s2DLowY = 0.12; // top pos
const double
Monitor::s2DScale = 0.01; // Skalierung
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -