rect

Getting the center of surfaces in pygame with python 3.4

半城伤御伤魂 提交于 2020-01-05 03:06:33
问题 I'm having troubles getting the center of surfaces with pygame. It defaults to the upper left corner of surfaces when trying to place them on other surfaces. To demonstrate what I mean I wrote a short program. import pygame WHITE = (255, 255, 255) pygame.init() #creating a test screen screen = pygame.display.set_mode((500, 500), pygame.RESIZABLE) #creating the canvas game_canvas = screen.copy() game_canvas.fill(WHITE) #drawing the canvas onto screen with coords 50, 50 (tho its using the upper

用C#一步一步构建一个完整的D3D场景(四) 控件

我与影子孤独终老i 提交于 2020-01-03 21:23:29
由于要从底层重新写自己的控件,花了一定的时间,目前已经完成基类的工作,并用基类派生了三个简单的控件(Button,Label和CheckBox),均已调试完毕。 下面直接给出完整的D3D_Control类。 public abstract class D3D_Control { private string m_ControlName; private D3D_Scene m_Scene; private D3D_Control m_Parent; private bool m_Loaded; private bool m_Show; private Point m_Location; private Size m_Size; private bool m_TopMost; private bool m_Visible; private bool m_Enable; private bool m_CanFocus; private bool m_Focus; private bool m_MouseEntered; private Sprite m_Sprite; private Color m_TextureBackColor; private float m_TextureTransparency; private Texture m_Texture; private int

Opencv中Mat图的长、宽、行、列以及图像像素的概念问题

廉价感情. 提交于 2020-01-03 03:55:38
今天在看矩形滤波的时候忽然脑子短路,把一些概念全弄混了,现总结一下,以便下次再混的时候可以参考确认下,自己的理解,有错的地方还请指正。 首先,在Opencv2中基本上都是用的Mat来表示图像了,C++的函数调用中基本上也都是Mat图,从根本上说,一张图像是一个由数值组成的矩阵,矩阵的每一个元素代表一个像素。对于灰度图像而言,像素有8位无符号数表示,其中0代表黑色,255代表白色。那么矩阵和图像间到底是一个什么样的关系呢。 第一:Mat图有行和列,即cv::Mat中有公有成员变量cols和rows,注意,这里的cols就是图像的宽度width,rows就是图像的高度height。这个width和height我们可以在其它Opencv的成员中得到,比如矩形Rect,而矩形Rect就是一个经常会用到的结构了,我自己接触到的就包括鼠标选择矩形区域、框住目标的矩形区域、滤波器矩形模版、目标的矩形特征、矩形内的运算等等。可以说Rect是一个非常常用的结构,也是Opencv里非常有用的一个结构,本质上矩形区域就是图像的一个子部分,或者说图像矩阵的一个子矩阵。 这里我引用《OpenCV学习笔记(四十一)——再看基础数据结构core》中关于Rect的介绍,Rect_类有些意思,成员变量x、y、width、height,分别为左上角点的坐标和矩形的宽和高。常用的成员函数有Size(

How to make rect from the intersection of two?

血红的双手。 提交于 2020-01-03 03:40:21
问题 I'm working on a breakout clone and I've been trying to figure out how to get the intersection rect of two colliding rects so I can measure how deep the ball entered the block in both x and y axis and decide which component of the velocity I'll reverse. I figured I could calculate the depth for each case like this: But if I had the intersection rect than I woudn't have to worry if the ball hits the block from the left/right or top/bottom (since I would be only reversing the x and y axis

“等一下,我碰!”——常见的2D碰撞检测

不羁的心 提交于 2020-01-01 22:05:06
转自:https://aotu.io/notes/2017/02/16/2d-collision-detection/ 在 2D 环境下,常见的碰撞检测方法如下: 外接图形判别法 轴对称包围盒(Axis-Aligned Bounding Box),即无旋转矩形。 圆形碰撞 圆形与矩形(无旋转) 圆形与旋转矩形(以矩形中心点为旋转轴) 光线投射法 分离轴定理 其他 地图格子划分 像素检测 下文将由易到难的顺序介绍上述各种碰撞检测方法:外接图形判别法 > 其他 > 光线投射法 > 分离轴定理。 另外,有一些场景只要我们约定好限定条件,也能实现我们想要的碰撞,如下面的碰壁反弹: 当球碰到边框就反弹(如 x/y轴方向速度取反 )。 if(ball.left < 0 || ball.right > rect.width) ball.velocityX = -ball.velocityX if(ball.top < 0 || ball.bottom > rect.height) ball.velocityY = -ball.velocityY 再例如当一个人走到 100px 位置时不进行跳跃,就会碰到石头等等。 因此,某些场景只需通过设定到适当的参数即可实现碰撞检测。 外接图形判别法 轴对称包围盒(Axis-Aligned Bounding Box) 概念:判断任意两个(无旋转

MFC 画图CDC双缓冲

一曲冷凌霜 提交于 2020-01-01 01:33:17
void CPCBGUIView::OnDraw(CDC* pDC) { //CPCBGUIDoc* pDoc = GetDocument(); //ASSERT_VALID(pDoc); //if (!pDoc) // return; CDC m_pMemDC; CBitmap m_pBitmap; CRect rect; GetClientRect(rect); int x=rect.Width(); int y=rect.Height(); m_pMemDC.CreateCompatibleDC(pDC); m_pBitmap.CreateCompatibleBitmap(pDC,x,y); m_pMemDC.SelectObject(m_pBitmap); pDC->SetMapMode(MM_ANISOTROPIC);//自定义方式 x向右增加 y向上增加 pDC->SetWindowExt(x,y); pDC->SetViewportExt(x,-y); pDC->SetWindowOrg(0,y); m_pMemDC.SetMapMode(MM_ANISOTROPIC); m_pMemDC.SetWindowExt(x,y); m_pMemDC.SetViewportExt(x,-y); m_pMemDC.SetWindowOrg(0,y); m_pMemDC

MFC中的CDC 绘图(2)

北城以北 提交于 2020-01-01 01:32:48
.面色(刷) 在Windows中,面状图必须用刷(brush)来填充,所以面色是由刷色来确定的。MFC中的刷类为CBrush(它也是CGDIObject的派生类),刷的创建与使用的步骤与笔的相似。 构造函数有4个: CBrush( ); // 创建一个刷的空对象 CBrush( COLORREF crColor ); // 创建颜色为crColor的实心刷 CBrush( int nIndex, COLORREF crColor ); // 创建风格由nIndex指定且颜色为crColor的条纹(hatch孵化)刷,其中nIndex可取条纹风格(Hatch Styles)值: 符号常量 数字常量 风格 HS_HORIZONTAL 0 水平线 HS_VERTICAL 1 垂直线 HS_FDIAGONAL 2 正斜线 HS_BDIAGONAL 3 反斜线 HS_CROSS 4 十字线(正网格) HS_DIAGCROSS 5 斜十字线(斜网格) CBrush( CBitmap* pBitmap ); // 创建位图为pBitmap的图案刷 如:pDC->FillRect( &rect, new CBrush( RGB(r, g, b) ) ); 与构造函数相对应,有多个创建不同类型刷的成员函数: BOOL CreateSolidBrush( COLORREF crColor );

MFC中CDC的使用 绘图(三)

时光总嘲笑我的痴心妄想 提交于 2020-01-01 01:31:58
5.清屏 Windows没有提供专门的清屏函数,可以调用CWnd的下面两个函数调用来完成该功能: void Invalidate(BOOL bErase = TRUE); void UpdateWindow( ); 或调用CWnd的函数 BOOL RedrawWindow( LPCRECT lpRectUpdate = NULL, CRgn* prgnUpdate = NULL, UINT flags = RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE ); 来完成。 例如(菜单项ID_CLEAR的事件处理函数): CDrawView::OnClear() { // 调用OnDraw来清屏 //Invalidate(); //UpdateWindow( ); RedrawWindow( ); } 也可以用画填充背景色矩形的方法来清屏,如: RECT rect; GetClientRect(&rect); pDC->FillSolidRect(&rect, RGB(255, 255, 255)); 6.在控件上绘图 可以在对话框资源中放置图片控件,并对其类型属性选Frame。可在对话框的绘图消息响应函数OnPaint或其他函数中,用CWnd类的函数GetDlgItem: CWnd* GetDlgItem( int nID ) const;

Windows绘图基础

亡梦爱人 提交于 2020-01-01 01:29:46
Author:秋时残叶 Date:2017.12.30 《windows程序设计》笔记 1.GDI函数 GDI包含几百个函数,可以分类为: 获取(建立)和释放(销毁)设备环境的函数 获取设备环境信息的函数 绘图函数 设置和获取设备环境属性的函数 使用GDI"对象"的函数 2. GDI基本图形 线条和曲线 可被填充的封闭区域 位图 文本 3. 其它 映射模式和转换 图元文件 区域 路径 剪裁 调色板 打印 4. GetDC和BeginPaint区别: 从GetDC函数返回的句柄可以在整个窗口客户区的客户区内绘制,并且, GetDC和RealseDC并不使任何客户区的无效区域变为有效。 还有一个更通用的获取设备环境句柄的函数: hdc = CreateDC(pszDriver, pszDevice, pszOutput, pData,; ...... DeleteDC(hdc); 可以通过这样获取整个屏幕的设备环境句柄: CreateDC(L"DISPLAY", NULL, NULL, NULL); 可以通过在调用GetDC时使用一个NULL参数来获取整个屏幕的设备环境。 5. 信息上下文 仅需要环境信息,而不需要在上面绘制东西,可以用: CreateIC(L"DISPALY", NULL, NULL, NULL); 6. 处理位图时,用到"内存设备环境" hdcMem =

How can I randomly place several non-colliding rects?

落花浮王杯 提交于 2019-12-30 03:20:09
问题 I'm working on some 2D games with Pygame. I need to place several objects at the same time randomly without them intersecting . I have tried a few obvious methods but they didn't work. Obvious methods follow (in pseudo): create list of objects for object in list: for other object in list: if object collides with other object: create new list of objects That method took forever. Other method I tried: create list of objects for object in list: for other object in list: if object collides with