📄 monitor.cpp
字号:
default: glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, sSphereDefaultColor); //glColor4fv(sSphereDefaultColor); } mGLServer.DrawSphere(pos, size, 8, false); glDisable(GL_LIGHTING); if (mDrawUnums && unum > 0) { glColor4fv(sUnumColor); std::stringstream ss; ss << unum; mGLServer.DrawText3D(ss.str(), pos + salt::Vector3f(0.0,0.0,0.3f)); } glEnable(GL_LIGHTING); }}voidMonitor::DrawBall(const salt::Vector3f& pos, float size, int pass){ if (pass == 0) { const GLfloat outerlineColor[] = {0.2f,0.2f,0.2f,1.0f}; glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, outerlineColor); mGLServer.DrawShadowOfSphere(pos, size); } else // pass=1, second pass with depth test { glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, sBallColor); //glColor4fv(sBallColor); mGLServer.DrawSphere(pos, size); }}// Example for DrawDebugvoidMonitor::DrawDebug(){ // this example method just draws the positive axes on the field glColor4fv(sDebugColorPink); // mGLServer.DrawArbitraryLine(Vector3f(0,0,0), Vector3f(10,0,0)); // mGLServer.DrawArbitraryLine(Vector3f(0,0,0), Vector3f(0,10,0)); // mGLServer.DrawArbitraryLine(Vector3f(0,0,0), Vector3f(0,0,10)); Vector3f pos; float size; if (mGameState.GetBall(pos, size)) { mGLServer.DrawCircle(pos, 1.0, 0 , 360); } return;}voidMonitor::DrawVelocities(){ Vector3f pos, oldpos; float timeDiff = mGameState.GetTime() - mOldGameState.GetTime(); // if no time has passed, no velocity can be calculated // TODO: this should set a default for stop clock cycles if (timeDiff == 0.0) return; //glDisable(GL_DEPTH_TEST); glColor3f(0.2f, 0.2f, 0.2f); if (mGameState.GetBall(pos) && mOldGameState.GetBall(oldpos)) { //DrawBall(pos, size, pass); //For scaling must divide by (timeDiff) mGLServer.DrawArbitraryLine(pos, pos + (pos-oldpos)/timeDiff); //mGLServer.DrawArbitraryLine(pos, pos + (pos-oldpos)/timeDiff); } int i = 0; int unum; TTeamIndex side; float size; while (mGameState.GetPlayer(i, pos, side, unum, size)) { mOldGameState.GetPlayer(i, oldpos, side, unum, size); mGLServer.DrawArbitraryLine(pos, pos + (pos-oldpos)/timeDiff); ++i; } //glEnable(GL_DEPTH_TEST);}voidMonitor::Display(){ glEnable(GL_POINT_SMOOTH); glEnable(GL_LINE_SMOOTH); glEnable(GL_BLEND); glEnable(GL_LIGHTING); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); const Vector3f szGoal1 = mGameState.GetGoalSize(false); const Vector3f szGoal2 = mGameState.GetGoalSize(true); glClearColor(0.0f,0.0f,0.0f,1.0f); //glClearColor(0.15f,0.15f,0.3f,1.0f); glClear (GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT); glColor3f (1.0, 1.0, 1.0); glLoadIdentity(); mGLServer.ApplyCamera(); const float& fl = mGameState.GetFieldLength(); const float& fw = mGameState.GetFieldWidth(); const float& fh = mGameState.GetFieldHeight(); const float& lw = mGameState.GetLineWidth(); const float& bs = mGameState.GetBorderSize(); const float& gw = mGameState.GetGoalWidth(); // skybox background if (mUseTexture) { glEnable(GL_TEXTURE_2D); mGLServer.DrawSkyBackground(0,0,100,200,200,200);// glDisable(GL_TEXTURE_2D); } // ground glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, sGroundColor); //glColor4fv(sGroundColor); //glColor4fv(sDebugColorPink); // left half //JANxxx// if (mUseTexture)// glEnable(GL_TEXTURE_2D); mGLServer.DrawGroundRectangle(Vector3f(-fl/2 + lw, -fw/2 + lw, 0), fl/2 - lw - lw/2, fw - 2*lw, 0); // right half mGLServer.DrawGroundRectangle(Vector3f(lw/2, -fw/2 + lw, 0), fl/2 - lw - lw/2, fw - 2*lw, 0); if (mUseTexture) glDisable(GL_TEXTURE_2D);// ------------------------------// glPushMatrix();// glRotatef(0,1,0,0);// //glTranslatef(pos[0],pos[1], pos[2]);// glNormal3f(0,0,1);// glBegin(GL_QUADS);// glVertex3f(-4.5,-4.5,3.0);// glVertex3f( 4.5,-4.5,3.0);// glVertex3f( 4.5, 4.5,3.0);// glVertex3f(-4.5, 4.5,3.0);// glEnd();// glPopMatrix(); //-------------------------------------------------------------- // border glColor4fv(sBorderColor); glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, sBorderColor); mGLServer.DrawGroundRectangle(Vector3f(-fl/2-bs,-fw/2-bs,-0.01), fl + 2*bs, fw+2*bs,-0.01); glDisable (GL_DEPTH_TEST); const GLfloat outerlineColor[] = {0.2f,0.2f,0.2f,1.0f}; glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, outerlineColor); //glColor3f(0.2f,0.2f,0.2f); glLineWidth(4); mGLServer.DrawArbitraryLine(Vector3f(-fl/2-bs,-fw/2-bs,0.01),Vector3f(-fl/2-bs,fw/2+bs,0.02)); mGLServer.DrawArbitraryLine(Vector3f( fl/2+bs,-fw/2-bs,0.01),Vector3f( fl/2+bs,fw/2+bs,0.02)); mGLServer.DrawArbitraryLine(Vector3f(-fl/2-bs,-fw/2-bs,0.01),Vector3f(fl/2+bs,-fw/2-bs,0.02)); mGLServer.DrawArbitraryLine(Vector3f(-fl/2-bs, fw/2+bs,0.01),Vector3f(fl/2+bs,fw/2+bs,0.02)); // fieldBox// glLineWidth(1);// mGLServer.DrawWireBox(Vector3f(-fl/2.0,-fw/2.0,0.0),// Vector3f(fl,fw,fh)); // lines glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, sLineColor); //glColor4fv(sLineColor); glLineWidth(3); mGLServer.DrawArbitraryLine(Vector3f(-fl/2,-fw/2,0.01),Vector3f(-fl/2,fw/2,0.02)); mGLServer.DrawArbitraryLine(Vector3f( fl/2,-fw/2,0.01),Vector3f( fl/2,fw/2,0.02)); mGLServer.DrawArbitraryLine(Vector3f(-fl/2,-fw/2,0.01),Vector3f(fl/2,-fw/2,0.02)); mGLServer.DrawArbitraryLine(Vector3f(-fl/2, fw/2,0.01),Vector3f(fl/2,fw/2,0.02)); mGLServer.DrawArbitraryLine(Vector3f(0,-fw/2,0.01),Vector3f(0,fw/2,0.02)); // goal box area right side mGLServer.DrawArbitraryLine(Vector3f(fl/2 - sGoalBoxLength, -gw/2 - sGoalBoxLength, 0.02), Vector3f(fl/2, -gw/2 - sGoalBoxLength, 0.02)); mGLServer.DrawArbitraryLine(Vector3f(fl/2 - sGoalBoxLength, gw/2 + sGoalBoxLength, 0.02), Vector3f(fl/2, gw/2 + sGoalBoxLength, 0.02)); mGLServer.DrawArbitraryLine(Vector3f(fl/2 - sGoalBoxLength, -gw/2 - sGoalBoxLength, 0.02), Vector3f(fl/2 - sGoalBoxLength, gw/2 + sGoalBoxLength, 0.02) ); //mGLServer.DrawGroundRectangle(Vector3f(fl/2 - sGoalBoxLength, -gw/2 - sGoalBoxLength, 0.05), lw, gw + 11, 0); //mGLServer.DrawGroundRectangle(Vector3f(fl/2 - sGoalBoxLength, -gw/2 - sGoalBoxLength, 0.05), sGoalBoxLength, lw, 0); //mGLServer.DrawGroundRectangle(Vector3f(fl/2 - sGoalBoxLength, gw/2 + sGoalBoxLength, 0.05), sGoalBoxLength, lw, 0); // goal box area left side mGLServer.DrawArbitraryLine(Vector3f(-fl/2 + sGoalBoxLength, -gw/2 - sGoalBoxLength, 0.02), Vector3f(-fl/2, -gw/2 - sGoalBoxLength, 0.02)); mGLServer.DrawArbitraryLine(Vector3f(-fl/2 + sGoalBoxLength, gw/2 + sGoalBoxLength, 0.02), Vector3f(-fl/2, gw/2 + sGoalBoxLength, 0.02)); mGLServer.DrawArbitraryLine(Vector3f(-fl/2 + sGoalBoxLength, -gw/2 - sGoalBoxLength, 0.02), Vector3f(-fl/2 + sGoalBoxLength, gw/2 + sGoalBoxLength, 0.02) ); //mGLServer.DrawGroundRectangle(Vector3f(-fl/2 + sGoalBoxLength, -gw/2 - sGoalBoxLength, 0.05), lw, gw + 11, 0); //mGLServer.DrawGroundRectangle(Vector3f(-fl/2 + sGoalBoxLength, -gw/2 - sGoalBoxLength, 0.05), -sGoalBoxLength, lw, 0); //mGLServer.DrawGroundRectangle(Vector3f(-fl/2 + sGoalBoxLength, gw/2 + sGoalBoxLength, 0.05), -sGoalBoxLength, lw, 0); // penalty area right side mGLServer.DrawArbitraryLine(Vector3f(fl/2 - sPenaltyLength, -gw/2 - sPenaltyLength, 0.02), Vector3f(fl/2, -gw/2 - sPenaltyLength, 0.02)); mGLServer.DrawArbitraryLine(Vector3f(fl/2 - sPenaltyLength, gw/2 + sPenaltyLength, 0.02), Vector3f(fl/2, gw/2 + sPenaltyLength, 0.02)); mGLServer.DrawArbitraryLine(Vector3f(fl/2 - sPenaltyLength, -gw/2 - sPenaltyLength, 0.02), Vector3f(fl/2 - sPenaltyLength, gw/2 + sPenaltyLength, 0.02) ); //mGLServer.DrawGroundRectangle(Vector3f(fl/2 - sPenaltyLength, -gw/2 - sPenaltyLength, 0.05), lw, gw + 33, 0); //mGLServer.DrawGroundRectangle(Vector3f(fl/2 - sPenaltyLength, -gw/2 - sPenaltyLength, 0.05), sPenaltyLength, lw, 0); //mGLServer.DrawGroundRectangle(Vector3f(fl/2 - sPenaltyLength, gw/2 + sPenaltyLength, 0.05), sPenaltyLength, lw, 0); // penalty area left side mGLServer.DrawArbitraryLine(Vector3f(-fl/2 + sPenaltyLength, -gw/2 - sPenaltyLength, 0.02), Vector3f(-fl/2, -gw/2 - sPenaltyLength, 0.02)); mGLServer.DrawArbitraryLine(Vector3f(-fl/2 + sPenaltyLength, gw/2 + sPenaltyLength, 0.02), Vector3f(-fl/2, gw/2 + sPenaltyLength, 0.02)); mGLServer.DrawArbitraryLine(Vector3f(-fl/2 + sPenaltyLength, -gw/2 - sPenaltyLength, 0.02), Vector3f(-fl/2 + sPenaltyLength, gw/2 + sPenaltyLength, 0.02) ); //mGLServer.DrawGroundRectangle(Vector3f(-fl/2 + sPenaltyLength, -gw/2 - sPenaltyLength, 0.05), lw, gw + 33, 0); //mGLServer.DrawGroundRectangle(Vector3f(-fl/2 + sPenaltyLength, -gw/2 - sPenaltyLength, 0.05), -sPenaltyLength, lw, 0); //mGLServer.DrawGroundRectangle(Vector3f(-fl/2 + sPenaltyLength, gw/2 + sPenaltyLength, 0.05), -sPenaltyLength, lw, 0); glLineWidth(2); mGLServer.DrawCircle(Vector3f(-fl/2, -fw/2, 0.02), 1.0); mGLServer.DrawCircle(Vector3f(-fl/2, fw/2, 0.02), 1.0); mGLServer.DrawCircle(Vector3f( fl/2, -fw/2, 0.02), 1.0); mGLServer.DrawCircle(Vector3f( fl/2, fw/2, 0.02), 1.0); // center circle mGLServer.DrawCircle(Vector3f(0.0,0.0,0.015), sCenterRadius); // draw shadows of cached positions DrawScene(0); glEnable(GL_DEPTH_TEST); // goal glLineWidth(1); glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, sGoalColor); //glColor3f(0.6f,0.6f,0.4f); mGLServer.DrawWireBox(Vector3f(-fl/2 - 0.0,-gw/2.0,0.0),szGoal1); //glColor4fv(sGoalColor); mGLServer.DrawGoal(Vector3f(-fl/2,-gw/2.0,0),szGoal1,lw/2.0); // goal glLineWidth(1); //glColor3f(0.6f,0.6f,0.4f); mGLServer.DrawWireBox(Vector3f(fl/2 + 0.0,-gw/2.0,0.0),szGoal2); //glColor4fv(sGoalColor); mGLServer.DrawGoal(Vector3f(fl/2,-gw/2.0,0),szGoal2,lw/2.0); glLineWidth(1); // draw cached positions DrawScene(1); glDisable(GL_LIGHTING); if (mDrawDebug) DrawDebug(); // JAN if (mDrawVelocity) DrawVelocities(); DrawStatusText(); // draw 2D Elements glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); float aspect = float(mGLServer.GetWidth())/mGLServer.GetHeight(); gluOrtho2D(-1.0*aspect, 1.0*aspect, -1.0, 1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // draw the info text DrawStatusLine(); // mit fenstergroesse skalieren// glBegin(GL_QUADS);// glVertex2f(1.0,1.0);// glVertex2f(1.0,0.0);// glVertex2f(0.0,0.0);// glVertex2f(0.0,1.0);// glEnd(); // draw two dimensional overview if (mDrawOverview) { DrawOverview(); } glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); // (end 2D Elements) checkAndShow(); glutSwapBuffers();}voidMonitor::MouseMotion(int x, int y){ Vector2f tmp(static_cast<float>(x), static_cast<float>(y)); mGLServer.SetViewByMouse(tmp, mMousePosition); mMousePosition = tmp; glutPostRedisplay();}voidMonitor::Keyboard(unsigned char key, int /*x*/, int /*y*/){ float hfl = mGameState.GetFieldLength()/2; Vector3f uv = mGLServer.GetUpVector(); salt::Vector3f 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); // reset time to show icon (10 cycles) mShowCamIconTime = 10; break; case '+': //move camera up mGLServer.MoveCamUp(mCamDelta); break; case '-': //move camera down mGLServer.MoveCamUp(-mCamDelta); break; case '{': // select CenterBall camera mode mCenterBallCameraZ += 1.0; break; case '}': // select CenterBall camera mode mCenterBallCameraZ -= 1.0; break; case ']': mCenterBallCameraY += 2.0; break; case '[': mCenterBallCameraY -= 2.0; break; case ')': { //Rotate cam to right Vector3f t(mGLServer.GetLookAtPos()-mGLServer.GetCameraPos() ); Vector3f d(cos(0.02) * t.x() + sin(0.02) * t.y() ,-sin(0.02) * t.x() + cos(0.02) * t.y(), t.z()); mGLServer.SetLookAtPos(d + mGLServer.GetCameraPos()); mGLServer.SetUpVector(Vector3f(0,0,1)); } break; case '(': { //Rotate cam to left Vector3f t(mGLServer.GetLookAtPos()-mGLServer.GetCameraPos() ); Vector3f d(cos(0.02) * t.x() - sin(0.02) * t.y() ,sin(0.02) * t.x() + cos(0.02) * t.y(), t.z()); mGLServer.SetLookAtPos(d + mGLServer.GetCameraPos()); mGLServer.SetUpVector(Vector3f(0,0,1)); } break; case '1': // toggle drawing of debug stuff mDrawDebug = !mDrawDebug; break; case '2': // toggle drawing of 2D overview mDrawOverview = !mDrawOverview; break; case '3': //Move cam behind left goal mGLServer.SetCameraPos(Vector3f(-hfl-5,0,4.2)); mGLServer.SetLookAtPos(Vector3f(0,0,1)); mGLServer.SetUpVector(Vector3f(0,0,1)); break; case '4': //Move cam behind right goal mGLServer.SetCameraPos(Vector3f(hfl+5,0,4.2)); mGLServer.SetLookAtPos(Vector3f(0,0,1)); mGLServer.SetUpVector(Vector3f(0,0,1)); break; case '5': //Move cam to left half mGLServer.SetCameraPos(NextCameraPosition(mLeftCamPositions)); if (mCameraMode == eFree) mGLServer.SetLookAtPos(Vector3f(0,0,1)); mGLServer.SetUpVector(Vector3f(0,0,1)); break; case '6': //Move cam to right half mGLServer.SetCameraPos(NextCameraPosition(mRightCamPositions)); if (mCameraMode == eFree) mGLServer.SetLookAtPos(Vector3f(0,0,1)); mGLServer.SetUpVector(Vector3f(0,0,1)); break; case 'n': // toggle drawing of unums mDrawUnums = !mDrawUnums; break; case 'q': // quit mCommServer->SendDisconnectCmd(); exit(0); case 'k' : // kick off cerr << "(rcssmonitor3d) " << mGameState.GetTime() << ": Kickoff " << ((mKickOff == CommServerBase::eLeft) ? "left" : ((mKickOff == CommServerBase::eRight) ? "right" : "random")) << endl; mCommServer->SendKickOffCmd(mKickOff); break; case 'b': // drop ball mCommServer->SendDropBallCmd(); break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -