|
Post by Nicky Peter Hollyoake on Aug 2, 2016 17:55:02 GMT -5
I'm using projection to find the collision between a circle and any segment, but it sees it as an infinity line and I tried fixing it but can't seem to find any good solution. Any advice on this problem?
const w=800, h=600
glMatrixMode(GL_PROJECTION) glLoadidentity() glOrTho(0, w, h, 0, 0, 1) glMatrixMode(GL_MODELVIEW) glLoadidentity() glDisable(GL_DEPTH_TEST) ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
declare function collision()
const r#=20
dim a#(1)=vec2(100, 100), b#(1)=vec2(400, 400) dim p#(1) dim i
while TRUE glClear(GL_COLOR_BUFFER_BIT) p#=vec2(mouse_x()*w, mouse_y()*h)
glColor3f(1, 1, 1) glBegin(GL_LINES) glVertex2fv(a#) glVertex2fv(b#) glEnd()
if collision() then glColor3f(1, 0, 0) else glColor3f(1, 1, 1) endif
glBegin(GL_LINE_LOOP) for i = 0 to 359 glVertex2fv(p# + vec2(cosd(i)*r#, sind(i)*r#)) next glEnd()
swapbuffers() wend
function collision() dim c#(1)=((p#*b#)/(b#*b#))*b# dim e#(1)=p#-c# dim loe#=sqr(pow(e#(0), 2) + pow(e#(0), 2))
if loe# < r# then return true endif
return false endfunction
- Nickyy
|
|