Polyvector on Windows CE

Previous topic - Next topic

MrTAToad

Not sure whether its a problem with the Windows CE 6.5 emulator, but it appears that when using :

Code (glbasic) Select
scale=1.0
WHILE TRUE
thing(0,100,100,RGB(255,0,0),scale,0.0)
thing(1,100,100,RGB(255,0,0),scale,angle)
INC angle,0.25
INC scale,0.1
SHOWSCREEN
WEND

KEYWAIT



FUNCTION thing: id, x, y, col, sc, phi
LOCAL i, x1,y1,x2,y2, cp, sp
sp = SIN(phi)
cp = COS(phi)
FOR i=0 TO objn[id]-2
x1 = objx[id][i  ]*sc
y1 = objy[id][i  ]*sc
x2 = objx[id][i+1]*sc
y2 = objy[id][i+1]*sc
Line( x1*cp-y1*sp + x, x1*sp+y1*cp + y, _
x2*cp-y2*sp + x, x2*sp+y2*cp + y, col)
NEXT
ENDFUNCTION


// collision of thing/thing
FUNCTION col_thth: x1,y1, x2,y2
LOCAL x,y
x = x1-x2
y = y1-y2
x = x*x+y*y // SQR(a)<1 <-> a<1
IF x<1 THEN RETURN TRUE
RETURN FALSE
ENDFUNCTION


FUNCTION Line: x1, y1, x2, y2, col
LOCAL c,s,p, w, dx, dy, ddx, ddy, ux, uy, lg
GLOBAL colormode

// IF colormode=FALSE THEN col=RGB(200,200,150)
ALPHAMODE .7

//line width
w = 16

// direction of line
ddx = x2-x1
ddy = y2-y1
lg = SQR(ddx*ddx+ddy*ddy)
IF lg<0.5 THEN RETURN

// short caps
lg=lg*2
// dir vector
dx=ddx*w/lg
dy=ddy*w/lg
// up vector
ux=dy
uy=-dx

// cap1
STARTPOLY 0
POLYVECTOR x1+ux-dx, y1+uy-dy,  0.5, 0.5,col
POLYVECTOR x1-ux-dx, y1-uy-dy,  0.5,63.5,col
POLYVECTOR x1-ux,    y1-uy,    31.5,63.5,col
POLYVECTOR x1+ux,    y1+uy,    31.5, 0.5,col
ENDPOLY

// center
STARTPOLY 0
POLYVECTOR x1+ux, y1+uy, 31.5,  0.5,col
POLYVECTOR x1-ux, y1-uy, 31.5, 63.5,col
POLYVECTOR x2-ux, y2-uy, 31.5, 63.5,col
POLYVECTOR x2+ux, y2+uy, 31.5,  0.5,col
ENDPOLY

// cap2
STARTPOLY 0
POLYVECTOR x2+ux,    y2+uy,    31.5,  0.5,col
POLYVECTOR x2-ux,    y2-uy,    31.5, 63.5,col
POLYVECTOR x2-ux+dx, y2-uy+dy, 63.5, 63.5,col
POLYVECTOR x2+ux+dx, y2+uy+dy, 63.5,  0.5,col
ENDPOLY
ENDFUNCTION


The lines dont join up...

[attachment deleted by admin]

Kitty Hello

the example does not compile. Oh dear, it should work, though.

MrTAToad

Forgot the data :

Code (glbasic) Select
DIM objn[20]
DIM objx[20][20]
DIM objy[20][20]

objn[0]=5
objx[0][0]=-1; objy[0][0]=-1
objx[0][1]=1; objy[0][1]=-1
objx[0][2]=1; objy[0][2]=1
objx[0][3]=-1; objy[0][3]=1
objx[0][4]=-1; objy[0][4]=-1

objn[1]=5
objx[1][0]=-0.5; objy[1][0]=-0.5
objx[1][1]=2; objy[1][1]=-0.5
objx[1][2]=2; objy[1][2]=0.5
objx[1][3]=-0.5; objy[1][3]=0.5
objx[1][4]=-0.5; objy[1][4]=-0.5