2015-10-30 28 views
0

所以我正在做某種2d物理引擎(是的,我知道很難從頭開始創建一個物理引擎),我需要一些幫助。我需要一個算法,說明在屏幕上繪製多邊形頂點的位置,它應該給出一個介於0和1之間的數字,0是可能的最小位置(0),1是可能的最大位置(窗口寬度或高度(1920或1080))。獲得位置值在0和1之間的算法

我給每個多邊形這些變量:

// = comment 

x = [a number wetween 0 and 1] 
y = [allso a number between 0 and 1] 
width = [between 0 and 1] 
height = [between 0 and 1] 

vertices = [ // This makes a triangle 
    0, 1, // bottom left of a "box" created at [x] * [window width], [y] * [window height] with the width of [width] * [window width] and height [height] * [window height] 
    1, 1, // bottom right of the "box" 
    0.5, 0 // top middle 
] 

?我怎樣才能在屏幕上(在0-1格式)我應該吸取的頂點?

回答

0

哦,我知道了現在。這是[x or y] + ([width or height] * [vertice])]

0

如果我正確理解你的問題,你想設置相對於框的邊界的頂點,並將它們轉換爲像素座標。這是可以做到如下:

translate(x) = (vertex_x * box_width + box_x_start) * pixel_width

translate(y) = (vertex_y * box_height + box_y_start) * pixel_height

+0

不,我想要得到個別頂點的繪製位置:/ – DayDun

+0

是的,所以如果'x = 0.5',那麼''x'像素座標是'0.5 * 1920 = 960'。與'y'座標相同。 – PandaConda

+0

是的,這給了我多邊形「盒子」的左上角的位置,我想要得到多邊形的各個點/頂點應繪製在哪裏 – DayDun

相關問題