問(wèn)題描述
我正在嘗試制作一種紙牌散開(kāi)的紙牌游戲.現(xiàn)在使用具有功能的 Allegro API 來(lái)顯示它:
I'm trying to make a card game where the cards fan out. Right now to display it Im using the Allegro API which has a function:
al_draw_rotated_bitmap(OBJECT_TO_ROTATE,CENTER_X,CENTER_Y,X
,Y,DEGREES_TO_ROTATE_IN_RADIANS);
所以有了這個(gè),我可以輕松地制作我的粉絲效果.問(wèn)題是知道哪張卡在鼠標(biāo)下面.為此,我想到了進(jìn)行多邊形碰撞測(cè)試.我只是不確定如何旋轉(zhuǎn)卡片上的 4 個(gè)點(diǎn)來(lái)組成多邊形.我基本上需要做和Allegro一樣的操作.
so with this I can make my fan effect easily. The problem is then knowing which card is under the mouse. To do this I thought of doing a polygon collision test. I'm just not sure how to rotate the 4 points on the card to make up the polygon. I basically need to do the same operation as Allegro.
比如卡片的4點(diǎn)是:
card.x
card.y
card.x + card.width
card.y + card.height
我需要一個(gè)類似的功能:
I would need a function like:
POINT rotate_point(float cx,float cy,float angle,POINT p)
{
}
謝謝
推薦答案
先減去樞軸點(diǎn)(cx,cy)
,然后旋轉(zhuǎn),再添加點(diǎn).
First subtract the pivot point (cx,cy)
, then rotate it, then add the point again.
未經(jīng)測(cè)試:
POINT rotate_point(float cx,float cy,float angle,POINT p)
{
float s = sin(angle);
float c = cos(angle);
// translate point back to origin:
p.x -= cx;
p.y -= cy;
// rotate point
float xnew = p.x * c - p.y * s;
float ynew = p.x * s + p.y * c;
// translate point back:
p.x = xnew + cx;
p.y = ynew + cy;
return p;
}
這篇關(guān)于圍繞另一個(gè)點(diǎn)旋轉(zhuǎn)一個(gè)點(diǎn) (2D)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!