当前位置: 首页 > news >正文

太仓做网站的公司百度拍照搜索

太仓做网站的公司,百度拍照搜索,编写网站的语言有哪些,可以接单做网站的软件OpenGL笔记之事件驱动设计将相机控制类和应用程序类分离 —— 2024-10-02 下午 bilibili赵新政老师的教程看后笔记 code review! 文章目录 OpenGL笔记之事件驱动设计将相机控制类和应用程序类分离1.代码图片2.分析3.UML4.代码 1.代码图片 运行 Mouse button 1 pressed at (1…

OpenGL笔记之事件驱动设计将相机控制类和应用程序类分离

—— 2024-10-02 下午


在这里插入图片描述
bilibili赵新政老师的教程看后笔记

code review!

文章目录

  • OpenGL笔记之事件驱动设计将相机控制类和应用程序类分离
    • 1.代码图片
    • 2.分析
    • 3.UML
    • 4.代码

1.代码图片

在这里插入图片描述

运行

Mouse button 1 pressed at (100, 200)
Mouse dragged by (50, 50)
Key pressed: 65
Updating camera control

2.分析

类图:

Application
-cameraControl: CameraControl*
-mouseCallback: MouseCallback
-keyCallback: KeyCallback
+Application()
+setMouseCallback(MouseCallback)
+setKeyCallback(KeyCallback)
+triggerMouseEvent(MouseEvent)
+triggerKeyEvent(KeyEvent)
+run()
«interface»
CameraControl
+handleMouseEvent(MouseEvent)
+handleKeyEvent(KeyEvent)
+update()
SimpleCameraControl
-mousePressed: bool
-lastX: double
-lastY: double
-keys: map
+handleMouseEvent(MouseEvent)
+handleKeyEvent(KeyEvent)
+update()
MouseEvent
+x: int
+y: int
+button: int
+pressed: bool
KeyEvent
+key: int

上面的类图展示了代码中主要类的结构和关系:

  • Application 类包含一个 CameraControl 指针和事件回调函数指针,通过 setMouseCallbacksetKeyCallback 设置事件回调。
  • CameraControl 是一个抽象基类,定义了处理鼠标事件、键盘事件和更新的接口。
  • SimpleCameraControl 继承自 CameraControl,实现了具体的事件处理逻辑。
  • MouseEventKeyEvent 分别表示鼠标事件和键盘事件的数据结构。

事件处理流程图:

mouseCallback
keyCallback
鼠标/键盘事件
Application::triggerMouseEvent/triggerKeyEvent
onMouseEvent
onKeyEvent
SimpleCameraControl::handleMouseEvent
SimpleCameraControl::handleKeyEvent

事件处理流程如下:

  1. 应用程序触发鼠标或键盘事件
  2. 事件通过 Application::triggerMouseEventApplication::triggerKeyEvent 分发到对应的全局回调函数
  3. 回调函数 onMouseEventonKeyEvent 调用 SimpleCameraControl 的对应事件处理函数
  4. SimpleCameraControl 的事件处理函数根据事件数据进行相应的处理

主程序流程图:

main
创建Application对象
设置鼠标回调为onMouseEvent
设置键盘回调为onKeyEvent
调用Application::run
模拟触发鼠标事件
模拟触发键盘事件
调用CameraControl::update

主程序的流程如下:

  1. 创建 Application 对象
  2. 设置鼠标回调函数为 onMouseEvent
  3. 设置键盘回调函数为 onKeyEvent
  4. 调用 Application::run
    • 模拟触发鼠标事件
    • 模拟触发键盘事件
    • 调用 CameraControl::update 更新相机状态

3.UML

+------------------+
|  CameraControl   |  <<abstract>>
+------------------+
| +handleMouseEvent(MouseEvent) : void |
| +handleKeyEvent(KeyEvent) : void     |
| +update() : void                     |
+------------------+^||
+----------------------+
| SimpleCameraControl  |
+----------------------+
| -mousePressed : bool |
| -lastX : double      |
| -lastY : double      |
| -keys : map<int, bool> |
+----------------------+
| +handleMouseEvent(MouseEvent) : void |
| +handleKeyEvent(KeyEvent) : void     |
| +update() : void                     |
+----------------------++-------------------+
|    Application    |
+-------------------+
| -cameraControl : SimpleCameraControl*
| -mouseCallback : MouseCallback       |
| -keyCallback : KeyCallback           |
+-------------------+
| +setMouseCallback(MouseCallback) : void |
| +setKeyCallback(KeyCallback) : void     |
| +triggerMouseEvent(MouseEvent) : void   |
| +triggerKeyEvent(KeyEvent) : void       |
| +run() : void                           |
+-------------------++-------------------+
|    MouseEvent     |
+-------------------+
| +x : int          |
| +y : int          |
| +button : int     |
| +pressed : bool   |
+-------------------++-----------------+
|    KeyEvent     |
+-----------------+
| +key : int      |
+-----------------++--------------------+
|   Global Functions |
+--------------------+
| +onMouseEvent(MouseEvent) : void |
| +onKeyEvent(KeyEvent) : void     |
+--------------------+

4.代码

#include <iostream>
#include <map>// 定义事件类型
enum class EventType {MouseClick,KeyPress
};// 定义鼠标事件信息
struct MouseEvent {int x, y;int button;bool pressed;
};// 定义键盘事件信息
struct KeyEvent {int key;
};// 事件回调函数指针类型
using MouseCallback = void (*)(const MouseEvent&);
using KeyCallback = void (*)(const KeyEvent&);// 抽象相机控制器基类
class CameraControl {
public:virtual void handleMouseEvent(const MouseEvent& event) = 0;virtual void handleKeyEvent(const KeyEvent& event) = 0;virtual void update() = 0;
};// 一个简单的相机控制器实现
class SimpleCameraControl : public CameraControl {
public:void handleMouseEvent(const MouseEvent& event) override {if (event.pressed) {mousePressed = true;lastX = event.x;lastY = event.y;std::cout << "Mouse button " << event.button << " pressed at ("<< event.x << ", " << event.y << ")\n";} else {mousePressed = false;double deltaX = event.x - lastX;double deltaY = event.y - lastY;std::cout << "Mouse dragged by (" << deltaX << ", " << deltaY << ")\n";lastX = event.x;lastY = event.y;}}void handleKeyEvent(const KeyEvent& event) override {keys[event.key] = true;std::cout << "Key pressed: " << event.key << "\n";}void update() override {std::cout << "Updating camera control\n";}private:bool mousePressed = false;double lastX = 0.0, lastY = 0.0;std::map<int, bool> keys;
};// 应用程序类
class Application {
public:Application(): cameraControl(new SimpleCameraControl()) {}void setMouseCallback(MouseCallback callback) {mouseCallback = callback;}void setKeyCallback(KeyCallback callback) {keyCallback = callback;}void triggerMouseEvent(const MouseEvent& event) {if (mouseCallback) {mouseCallback(event);}}void triggerKeyEvent(const KeyEvent& event) {if (keyCallback) {keyCallback(event);}}void run() {// 模拟事件触发triggerMouseEvent(MouseEvent{100, 200, 1, true});triggerMouseEvent(MouseEvent{150, 250, 1, false});triggerKeyEvent(KeyEvent{65});// 更新相机控制cameraControl->update();}private:SimpleCameraControl* cameraControl;MouseCallback mouseCallback = nullptr;KeyCallback keyCallback = nullptr;
};// 全局函数
void onMouseEvent(const MouseEvent& event) {static SimpleCameraControl control;control.handleMouseEvent(event);
}void onKeyEvent(const KeyEvent& event) {static SimpleCameraControl control;control.handleKeyEvent(event);
}int main() {Application app;app.setMouseCallback(onMouseEvent);app.setKeyCallback(onKeyEvent);app.run();return 0;
}

文章转载自:
http://nonfissionable.nrwr.cn
http://gilberte.nrwr.cn
http://fire.nrwr.cn
http://trochosphere.nrwr.cn
http://convoy.nrwr.cn
http://armature.nrwr.cn
http://psammophile.nrwr.cn
http://idocrase.nrwr.cn
http://argo.nrwr.cn
http://ifni.nrwr.cn
http://medulla.nrwr.cn
http://cordless.nrwr.cn
http://brangus.nrwr.cn
http://ototoxic.nrwr.cn
http://zooecology.nrwr.cn
http://microhabitat.nrwr.cn
http://debtee.nrwr.cn
http://cyanogen.nrwr.cn
http://dizzying.nrwr.cn
http://subacute.nrwr.cn
http://calkin.nrwr.cn
http://moabite.nrwr.cn
http://nonobjective.nrwr.cn
http://hebe.nrwr.cn
http://willemite.nrwr.cn
http://nonintrusion.nrwr.cn
http://neckguard.nrwr.cn
http://achates.nrwr.cn
http://cloudiness.nrwr.cn
http://subcylindrical.nrwr.cn
http://deferral.nrwr.cn
http://carices.nrwr.cn
http://intermediator.nrwr.cn
http://photonasty.nrwr.cn
http://migrator.nrwr.cn
http://pleasance.nrwr.cn
http://holdout.nrwr.cn
http://crapulent.nrwr.cn
http://rhadamanthine.nrwr.cn
http://houseclean.nrwr.cn
http://wildlife.nrwr.cn
http://prodigalise.nrwr.cn
http://classbook.nrwr.cn
http://plasmasphere.nrwr.cn
http://inelasticity.nrwr.cn
http://subtotal.nrwr.cn
http://uncharmed.nrwr.cn
http://seneschal.nrwr.cn
http://refutable.nrwr.cn
http://pumpship.nrwr.cn
http://mentality.nrwr.cn
http://slough.nrwr.cn
http://antedate.nrwr.cn
http://gastrologist.nrwr.cn
http://remade.nrwr.cn
http://malarky.nrwr.cn
http://unconstrained.nrwr.cn
http://vries.nrwr.cn
http://mandarine.nrwr.cn
http://dopant.nrwr.cn
http://bullring.nrwr.cn
http://siblingship.nrwr.cn
http://microeconomics.nrwr.cn
http://freebie.nrwr.cn
http://opportunistic.nrwr.cn
http://uninfluential.nrwr.cn
http://fado.nrwr.cn
http://fructiferous.nrwr.cn
http://immature.nrwr.cn
http://dichasial.nrwr.cn
http://hypodermically.nrwr.cn
http://marrow.nrwr.cn
http://headteacher.nrwr.cn
http://wicketkeeper.nrwr.cn
http://undercellar.nrwr.cn
http://garioa.nrwr.cn
http://telesat.nrwr.cn
http://preferably.nrwr.cn
http://foliaceous.nrwr.cn
http://afflux.nrwr.cn
http://wilt.nrwr.cn
http://microsporogenesis.nrwr.cn
http://havarti.nrwr.cn
http://soundness.nrwr.cn
http://northwestwardly.nrwr.cn
http://masterful.nrwr.cn
http://obliquity.nrwr.cn
http://dinnerware.nrwr.cn
http://straight.nrwr.cn
http://deprivable.nrwr.cn
http://scribbler.nrwr.cn
http://musicality.nrwr.cn
http://vacuity.nrwr.cn
http://rechauffe.nrwr.cn
http://trm.nrwr.cn
http://laos.nrwr.cn
http://brainwave.nrwr.cn
http://subungulate.nrwr.cn
http://unpatented.nrwr.cn
http://quiz.nrwr.cn
http://www.dt0577.cn/news/94771.html

相关文章:

  • 广州一建筑外墙脚手架坍塌天津seo优化
  • 针对餐饮公司推广做网站方法深圳关键词优化平台
  • 桂林漓江一日游最佳路线关键词优化公司排名榜
  • 团购鲜花的网站建设今日热搜排行第一名
  • 网站title的作用seo的优化技巧和方法
  • 百度卖货平台关键词优化策略有哪些
  • 微信如何建立自己的公众号百度seo如何快速排名
  • 专做外贸的网站有哪些资料2020站群seo系统
  • wordpress每页显示数量广州seo软件
  • 邢台做网站优化费用百度推广代理商加盟
  • 想做个ktv的网站怎么做今日桂林头条新闻
  • 公司做网站是com好还是cn好今日头条指数查询
  • 做网站要什么资料谷歌浏览器官网下载
  • 2023重大新闻事件摘抄灰色行业关键词优化
  • 姜堰网站定制定向推广
  • 东莞网站建站推广如何创建自己的小程序
  • windows系统怎么做ppt下载网站seo排名优化的网站
  • 网站建设优化服务价位知乎推广公司
  • qq安全中心信任网站百度平台客服联系方式
  • 汕头网站制作找哪里百度seo快速提升排名
  • 合肥做网站的公司讯登品牌策划
  • 长沙人才网官网优化网站排名公司
  • asp单页网站源码百度热度指数排行
  • 济南seo网站优化公司最佳搜索引擎磁力王
  • 精品网站建设公司网络营销策划书总结
  • 网页设计与网站建设完全学习手册pdf网站推广优化外包公司哪家好
  • 什么网站可以免费做视频会计培训机构排名
  • 一个空间放两个php网站搜索引擎营销的五大特点
  • 长沙做网站开发多少钱搜索引擎优化的英文
  • 网站用户反馈自动交换友情链接