⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 guiminimap.cc

📁 五行MMORPG引擎系统V1.0
💻 CC
📖 第 1 页 / 共 2 页
字号:
	//	if(obj)
	//	{
	//		Point3F pos = obj->getPosition();

	//		char buffer[64];
	//		dSprintf(buffer,64,"%2.0f,%2.0f",mFloor(pos.x),mFloor(pos.y) );
	//		mMiniMapTitle->setText(buffer);
	//	}
	//}
}

void GuiMiniMapCtrl::onRender(Point2I offset, const RectI & updateRect)
{
	//return;
   RectI rect = updateRect;

   setUpdate();

   // draw an x
   if( !bool(g_pTerrainBlock))
   {
      glBegin(GL_LINES);
      glColor3f(0,0,0);
      glVertex2f(rect.point.x, updateRect.point.y);
      glVertex2f(rect.point.x + updateRect.extent.x, updateRect.point.y + updateRect.extent.y);
      glVertex2f(rect.point.x, updateRect.point.y + updateRect.extent.y);
      glVertex2f(rect.point.x + updateRect.extent.x, updateRect.point.y);
      glEnd();
      return;
   }

   //
   setupScreenTransform(offset);

   // draw the terrain
   if(mSquareBitmap)
      rect.extent.x > rect.extent.y ? rect.extent.x = rect.extent.y : rect.extent.y = rect.extent.x;
   dglSetClipRect(rect);

   dglClearBitmapModulation();
   dglDrawBitmapStretch(mTextureHandle, rect);

   // draw all the objects
   Vector<SceneObject*> objects;
   U32 mask = InteriorObjectType | PlayerObjectType | VehicleObjectType | StaticShapeObjectType | WaterObjectType | TriggerObjectType;
   //U32 mask =  PlayerObjectType ;
   gClientContainer.findObjects(mask, findObjectsCallback, &objects);

   glEnable(GL_BLEND);
   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
   glBegin(GL_QUADS);

   // project 'em
   for(U32 i = 0; i < objects.size(); i++)
   {
      // get the color
      if(objects[i]->getTypeMask() & WaterObjectType)
         glColor4ub(mWaterObjectColor.red, mWaterObjectColor.green, mWaterObjectColor.blue, mWaterObjectColor.alpha);
      else
         glColor4ub(mDefaultObjectColor.red, mDefaultObjectColor.green, mDefaultObjectColor.blue, mDefaultObjectColor.alpha);

      const Box3F & objBox = objects[i]->getObjBox();
      const MatrixF & objTransform = objects[i]->getTransform();
      const VectorF & objScale = objects[i]->getScale();

      U32 numPlanes = 0;
      PlaneF testPlanes[3];
      U32 planeIndices[3];

      U32 j;
      for(j = 0; (j < 6) && (numPlanes < 3); j++)
      {
         PlaneF plane;
         plane.x = BoxNormals[j].x;
         plane.y = BoxNormals[j].y;
         plane.z = BoxNormals[j].z;

         if(j&1)
            plane.d = (((const F32 *)objBox.min)[(j-1)>>1]);
         else
            plane.d = -(((const F32 *)objBox.max)[j>>1]);

         //
         mTransformPlane(objTransform, objScale, plane, &testPlanes[numPlanes]);

         planeIndices[numPlanes] = j;

         if(mDot(testPlanes[numPlanes], Point3F(0,0,1)) > 0.f)
            numPlanes++;
      }

      // dump the polys
      for(j = 0; j < numPlanes; j++)
      {
         for(U32 k = 0; k < 4; k++)
         {
            U32 vertIndex = BoxVerts[planeIndices[j]][k];

            Point3F pnt;
            pnt.set(BoxPnts[vertIndex].x ? objBox.max.x : objBox.min.x,
                    BoxPnts[vertIndex].y ? objBox.max.y : objBox.min.y,
                    BoxPnts[vertIndex].z ? objBox.max.z : objBox.min.z);

            // scale it
            pnt.convolve(objScale);

            Point3F proj;
            objTransform.mulP(pnt, &proj);

            Point2F pos = worldToScreen(Point2F(proj.x, proj.y));
            glVertex2f(pos.x, pos.y);
         }
      }
   }

   glEnd();
   glDisable(GL_BLEND);



   // render the camera
   if(mRenderCamera)
   {
      CameraQuery camera;
      GameProcessCameraQuery(&camera);

      // farplane too far, 90' looks wrong...
      camera.fov = mDegToRad(60.f);
      camera.farPlane = 500.f;

      //
      F32 rot = camera.fov / 2;

      //
      VectorF ray;
      VectorF projRayA, projRayB;

      ray.set(camera.farPlane * -mSin(rot), camera.farPlane * mCos(rot), 0);
      camera.cameraMatrix.mulV(ray, &projRayA);

      ray.set(camera.farPlane * -mSin(-rot), camera.farPlane * mCos(-rot), 0);
      camera.cameraMatrix.mulV(ray, &projRayB);

      Point3F camPos;
      camera.cameraMatrix.getColumn(3, &camPos);

      Point2F s = worldToScreen(Point2F(camPos.x, camPos.y));
      Point2F e1 = worldToScreen(Point2F(camPos.x + projRayA.x, camPos.y + projRayA.y));
      Point2F e2 = worldToScreen(Point2F(camPos.x + projRayB.x, camPos.y + projRayB.y));

      glColor4ub(mCameraColor.red, mCameraColor.green, mCameraColor.blue, mCameraColor.alpha);
      glBegin(GL_LINES);
      glVertex2f(s.x, s.y);
      glVertex2f(e1.x, e1.y);
      glVertex2f(s.x, s.y);
      glVertex2f(e2.x, e2.y);
      glEnd();
   }


 //  if(mMiniMapTitle.isNull() && bool(mProfile->mFont))
	//{	
	//	GameConnection * connection = GameConnection::getLocalClientConnection();

	//	ShapeBase * obj = 0;
	//	if(connection)
	//		obj = connection->getControlObject();

	//	if(obj)
	//	{
	//		Point3F pos = obj->getPosition();

	//		char buffer[64];
	//		dSprintf(buffer,64,"%2.0f,%2.0f",mFloor(pos.x),mFloor(pos.y) );
	//		static ColorI clr(255,255,255,255);
	//		dglDrawText(mProfile->mFont,offset,buffer,&clr);
	//	}


	//}
   renderChildControls(offset, updateRect);
}




//------------------------------------------------------------------------------

void GuiMiniMapCtrl::onMouseUp(const GuiEvent & event)
{
}

void GuiMiniMapCtrl::onMouseDown(const GuiEvent & event)
{

	Point2F pos = screenToWorld(Point2F(event.mousePoint.x, event.mousePoint.y));
	setControlObjPos(pos);
	Con::executef(this,3,"onPlayerNavigateTo",Con::getFloatArg(pos.x),Con::getFloatArg(pos.y));

}


void GuiMiniMapCtrl::onMouseMove(const GuiEvent & event)
{
}

// update the mission area here...
void GuiMiniMapCtrl::onMouseDragged(const GuiEvent & event)
{

}

void GuiMiniMapCtrl::onMouseEnter(const GuiEvent &)
{
	//Canvas->setCursor();
 //  setCursor(DefaultCursor);
}

void GuiMiniMapCtrl::onMouseLeave(const GuiEvent &)
{
   //mLastHitMode = nothing;
   //setCursor(DefaultCursor);
}

//------------------------------------------------------------------------------

//客户端无法直接改变位置
void GuiMiniMapCtrl::setControlObjPos(const Point2F & pos)
{
   GameConnection * connection = GameConnection::getConnectionToServer();

   ShapeBase * obj = 0;
   if(connection)
      obj = connection->getControlObject();

   if(!obj)
   {
      Con::errorf(ConsoleLogEntry::General, "GuiMiniMapCtrl::setControlObjPos: could not get a control object!");
      return;
   }

   // move it
   MatrixF mat = obj->getTransform();

   Point3F current;
   mat.getColumn(3, &current);

   //
   if(bool(g_pTerrainBlock))
   {
      F32 height;
      g_pTerrainBlock->getHeight(pos, &height);
      if(current.z < height)
         current.z = height + 10.f;
   }

   //
   current.set(pos.x, pos.y, current.z);
   mat.setColumn(3, current);
   obj->setTransform(mat);
}



//------------------------------------------------------------------------------

void GuiMiniMapCtrl::initPersistFields()
{
   Parent::initPersistFields();


   addGroup("Misc");	
   addField("handleFrameColor", TypeColorI, Offset(mHandleFrameColor, GuiMiniMapCtrl));
   addField("handleFillColor", TypeColorI, Offset(mHandleFillColor, GuiMiniMapCtrl));
   addField("defaultObjectColor", TypeColorI, Offset(mDefaultObjectColor, GuiMiniMapCtrl));
   addField("waterObjectColor", TypeColorI, Offset(mWaterObjectColor, GuiMiniMapCtrl));
   addField("missionBoundsColor", TypeColorI, Offset(mMissionBoundsColor, GuiMiniMapCtrl));
   addField("cameraColor", TypeColorI, Offset(mCameraColor, GuiMiniMapCtrl));
   addField("squareBitmap", TypeBool, Offset(mSquareBitmap, GuiMiniMapCtrl));
   addField("renderCamera", TypeBool, Offset(mRenderCamera, GuiMiniMapCtrl));
   //addField("miniMapName", TypeString, Offset(mMiniMapName, GuiMiniMapCtrl));
   endGroup("Misc");	
}




⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -