您的位置:首页 > 其它

蔡军生先生第二人生的源码分析(九十九)雷达地图的实现

2008-09-06 11:53 651 查看
无论是在2D的游戏里,还是在3D的游戏里,雷达地图的实现,都是比较基本的功能了。因为随着游戏世界里越来越大,参加的玩家也越来越多,需要一个大体的地图来让玩家方便地看到全局的概貌。比如在打对战的游戏里,更加需要了解别人在那里战斗了。有了雷达地图之后,就可以让玩家更加方便地了解全局地图上发生的事情,也方便玩家相互查找,也让玩家不会走迷路。下面就来了解第二生里的怎么样实现雷达地图的实现,它的显示界面如下:



它主要通过类LLNetMap来实现的,它的声明代码如下:
#001 class LLNetMap : public LLUICtrl
#002 {
#003 public:

构造函数和析构函数。
#004 LLNetMap(const std::string& name, const LLRect& rect, const LLColor4& bg_color );
#005 virtual ~LLNetMap();
#006

返回窗口的类型。
#007 virtual EWidgetType getWidgetType() const;
#008 virtual LLString getWidgetTag() const;
#009

显示雷达地图。
#010 virtual void draw();

响应事件消息处理。
#011 virtual BOOL handleDoubleClick( S32 x, S32 y, MASK mask );
#012 virtual BOOL handleRightMouseDown( S32 x, S32 y, MASK mask );
#013 virtual BOOL handleScrollWheel(S32 x, S32 y, S32 clicks);
#014 virtual BOOL handleToolTip( S32 x, S32 y, LLString& msg, LLRect* sticky_rect_screen );
#015

设置缩放大小倍数。
#016 void setScale( F32 scale );

平移位置。
#017 void translatePan( F32 delta_x, F32 delta_y );
#018 void setPan( F32 x, F32 y ) { mTargetPanX = x; mTargetPanY = y; }
#019
#020 const LLVector3d& getObjectImageCenterGlobal() { return mObjectImageCenterGlobal; }

显示相应的点。
#021 void renderPoint(const LLVector3 &pos, const LLColor4U &color,
#022 S32 diameter, S32 relative_height = 0);
#023 void renderScaledPointGlobal( const LLVector3d& pos, const LLColor4U &color, F32 radius );
#024
#025 LLVector3 globalPosToView(const LLVector3d& global_pos);
#026 LLVector3d viewPosToGlobal(S32 x,S32 y);
#027
#028 static void setRotateMap( BOOL b ) { LLNetMap::sRotateMap = b; }
#029 static void handleZoomLevel(void* which);
#030
显示右下角的拉动箭头。
#031 void drawTracking( const LLVector3d& pos_global,
#032 const LLColor4& color,
#033 BOOL draw_arrow = TRUE);
#034
#035 protected:
#036 void setDirectionPos( LLTextBox* text_box, F32 rotation );
#037 void createObjectImage();
#038 static void teleport( const LLVector3d& destination );
#039 static void fly( const LLVector3d& destination );
#040
#041 public:

保存相应的属性。
#042 LLHandle<LLView> mPopupMenuHandle;
#043 LLColor4 mBackgroundColor;
#044
#045 F32 mScale; // Size of a
#046 region in pixels
#047 F32 mPixelsPerMeter; // world meters to map pixels
#048 F32 mObjectMapTPM; // texels per meter on map
#049 F32 mObjectMapPixels; // Width of object map in pixels;
#050 F32 mTargetPanX;
#051 F32 mTargetPanY;
#052 F32 mCurPanX;
#053 F32 mCurPanY;
#054 BOOL mUpdateNow;
#055 LLVector3d mObjectImageCenterGlobal;
#056 LLPointer<LLImageRaw> mObjectRawImagep;
#057 LLPointer<LLImageGL> mObjectImagep;

显示八个方向的文字框。
#058 LLTextBox* mTextBoxEast;
#059 LLTextBox* mTextBoxNorth;
#060 LLTextBox* mTextBoxWest;
#061 LLTextBox* mTextBoxSouth;
#062
#063 LLTextBox* mTextBoxSouthEast;
#064 LLTextBox* mTextBoxNorthEast;
#065 LLTextBox* mTextBoxNorthWest;
#066 LLTextBox* mTextBoxSouthWest;
#067
#068 LLRotateNetMapListener mNetMapListener;
#069
#070 static BOOL sRotateMap;
#071 static LLNetMap* sInstance;
#072 };

通过上面的类,就可以看到雷达地图实现的基本属性、大体框架,下一次再来详细地分析它是怎么实现显示点来代表全局的物体。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: