collision icon indicating copy to clipboard operation
collision copied to clipboard

Algorithm issue

Open gogo55 opened this issue 5 years ago • 1 comments

I believe, there is an issue in the collision recognition. Example:

`import pygame as pg import sys import os from collision import *

SCREENSIZE = (1200,900) screen = pg.display.set_mode(SCREENSIZE, pg.DOUBLEBUF|pg.HWACCEL)

v = Vector p0 = Concave_Poly(v(0,0), []) p0.set_points([ Vector(697.1654965313376, 179.9115879140274), Vector(764.9587442373818, 222.3859986276198), Vector(743.3817435948768, 256.82496846229026), Vector(675.5884958888325, 214.35055774869784), ]) p1 = Concave_Poly(v(0,0), []) p1.set_points([ Vector(875.0138897016246, 123.17802988652383), Vector(943.1811884599225, 165.04949248334466), Vector(949.304599935167, 170.46229454571227), Vector(1019.8568670514846, 271.73421253085047), Vector(1040.1360798659869, 381.7005038144338), Vector(1020.1348828367004, 479.85313011280556), Vector(974.5176923937827, 555.6645122896266),
Vector(939.825961238999, 534.4962957968701), Vector(980.5408637494689, 470.69216659798064), Vector(999.8705586307079, 387.20481118696586), Vector(985.0376168510401, 292.6920133572453), Vector(927.0230429423466, 204.44967187871185), Vector(921.9104854607375, 199.67848025255998), Vector(853.7431867024396, 157.80701765573914), ])

clock = pg.time.Clock() stop = False cont = False while 1: for event in pg.event.get(): if event.type == pg.QUIT: sys.exit() pressed = pg.key.get_pressed()

    # Hit SPACE to continue after the error
    if pressed[pg.K_SPACE]: cont = True

screen.fill((0,0,0))

if not stop or cont: p0.pos.x += 0.1

p0c, p1c, p2c = (0,255,255),(0,255,255),(0,255,255)
p0bc = (255,255,255)
p1bc = (255,255,255)

if collide(p0,p1): 
    p1c = (255,0,0); p0c = (255,0,0);
    stop = True
    
if test_aabb(p0.aabb,p1.aabb): p1bc = (255,0,0); p0bc = (255,0,0);

pg.draw.polygon(screen, p0c, p0.points, 3)
pg.draw.polygon(screen, p1c, p1.points, 3)
pg.draw.polygon(screen, p0bc, (p0.aabb[0],p0.aabb[1],p0.aabb[3],p0.aabb[2]), 3)
pg.draw.polygon(screen, p1bc, (p1.aabb[0],p1.aabb[1],p1.aabb[3],p1.aabb[2]), 3)

pg.display.flip()
clock.tick(100)

`

gogo55 avatar Jan 08 '20 14:01 gogo55

This one has me stumped, as changing your values to integers made it work fine.

qwertyquerty avatar Apr 15 '20 17:04 qwertyquerty