collision basics....

Source-code only - please, don't post questions here.
thesanman112
Posts: 538
Joined: Jul 15, 2005 4:13

collision basics....

well heres about the easiest demo I can come up with for 3d collision, hope it helps..

Code: Select all

`screen 12,,2vp=1dim  as single s,dis4,dis5,dis6,dis8,dis9,disa'xp=180:yp=180:zp=100x1=100:x2=200:x3=100:y1=200:y2=200:y3=100:z1=100:z2=100:z3=100dis8=sqr((x1-x2)^2+(y1-y2)^2+(z1-z2)^2)dis9=sqr((x2-x3)^2+(y2-y3)^2+(z2-z3)^2)disa=sqr((x3-x1)^2+(y3-y1)^2+(z3-z1)^2)start:clsline(x1,y1)-(x2,y2):line(x2,y2)-(x3,y3)line(x3,y3)-(x1,y1)dis4=sqr((x1-xp)^2+(y1-yp)^2+(z1-zp)^2)dis5=sqr((xp-x2)^2+(yp-y2)^2+(z2-zp)^2)dis6=sqr((x3-xp)^2+(y3-yp)^2+(z3-zp)^2)'start:pset (xp,yp)k\$=inkey\$if k\$="d" then xp=xp+1if k\$="s" then xp=xp-1if k\$="e" then yp=yp-1if k\$="x" then yp=yp+1if k\$="q" then zp=zp+1if k\$="a" then zp=zp-1if k\$=chr\$(27) then endlocate 1,1print"press e,x,s,d to move"locate 15,1:s=(dis8+dis9+disa)/2Area=sqr(s*(s-dis8)*(s-dis9)*(s-disa)):'print area''s=(dis4+dis5+dis8)/2area1=sqr(s*(s-dis4)*(s-dis5)*(s-dis8)):'print area1s=(dis5+dis6+dis9)/2area2=sqr(s*(s-dis5)*(s-dis6)*(s-dis9)):'print area2s=(dis4+disa+dis6)/2area3=sqr(s*(s-dis4)*(s-disa)*(s-dis6)):'print area3line(x1,y1)-(xp,yp),4line(x2,y2)-(xp,yp),4line(x3,y3)-(xp,yp),4print int(area1+area2+area3+.5)print areaswap vp,wp screenset wp,vPgoto start`
thesanman112
Posts: 538
Joined: Jul 15, 2005 4:13

looky

here is a demo for noob
thesanman112
Posts: 538
Joined: Jul 15, 2005 4:13

bing

scotty, hope it helps.
thesanman112
Posts: 538
Joined: Jul 15, 2005 4:13

Re: collision basics....

Just to refresh my memory...
Tourist Trap
Posts: 2197
Joined: Jun 02, 2015 16:24

Re: collision basics....

It is to be compiled in lang=qb I guess. No, it's fblite.
Ok this should work for everyone so:

Code: Select all

`#lang "fblite"screen 12,,2vp=1dim  as single s,dis4,dis5,dis6,dis8,dis9,disa'xp=180:yp=180:zp=100x1=100:x2=200:x3=100:y1=200:y2=200:y3=100:z1=100:z2=100:z3=100dis8=sqr((x1-x2)^2+(y1-y2)^2+(z1-z2)^2)dis9=sqr((x2-x3)^2+(y2-y3)^2+(z2-z3)^2)disa=sqr((x3-x1)^2+(y3-y1)^2+(z3-z1)^2)start:clsline(x1,y1)-(x2,y2):line(x2,y2)-(x3,y3)line(x3,y3)-(x1,y1)dis4=sqr((x1-xp)^2+(y1-yp)^2+(z1-zp)^2)dis5=sqr((xp-x2)^2+(yp-y2)^2+(z2-zp)^2)dis6=sqr((x3-xp)^2+(y3-yp)^2+(z3-zp)^2)'start:pset (xp,yp)k\$=inkey\$if k\$="d" then xp=xp+1if k\$="s" then xp=xp-1if k\$="e" then yp=yp-1if k\$="x" then yp=yp+1if k\$="q" then zp=zp+1if k\$="a" then zp=zp-1if k\$=chr\$(27) then endlocate 1,1print"press e,x,s,d to move"locate 15,1:s=(dis8+dis9+disa)/2Area=sqr(s*(s-dis8)*(s-dis9)*(s-disa)):'print area''s=(dis4+dis5+dis8)/2area1=sqr(s*(s-dis4)*(s-dis5)*(s-dis8)):'print area1s=(dis5+dis6+dis9)/2area2=sqr(s*(s-dis5)*(s-dis6)*(s-dis9)):'print area2s=(dis4+disa+dis6)/2area3=sqr(s*(s-dis4)*(s-disa)*(s-dis6)):'print area3line(x1,y1)-(xp,yp),4line(x2,y2)-(xp,yp),4line(x3,y3)-(xp,yp),4print int(area1+area2+area3+.5)print areaswap vp,wpscreenset wp, vPgoto start`

However, I don't really see what is colliding with what here. Can a word of tutorial be added?
thesanman112
Posts: 538
Joined: Jul 15, 2005 4:13

Re: collision basics....

Its for 3d collision that I wrote ten years ago.
Basically it finds the area of a triangulated point and compares it to a triangle that is stationary or static.
thesanman112
Posts: 538
Joined: Jul 15, 2005 4:13

Re: collision basics....

I know thats really simple terms.
There are three red triangles and one white triangle,
The area of the three red triangles is calculated,
And the area of the white triangle is calculated,
If we want to remain a constant distance away from grey triangle as we move around then we just move player or object up or down in the 3d environment so that the area of the red triangles are, say for example a value of 500 higher. I used this routine for a 3d demo walkaround world that looked like rolling hills..
thesanman112
Posts: 538
Joined: Jul 15, 2005 4:13

Re: collision basics....

I should also mention that apart from qb syntax, this was tested with fb .13...and was optimised as such...i believe at the time it was upwards of 1500 triangles that maintained a good high frame rate using opengl, on a pentium M 1.6gig laptop. And i had all visual opengl effects on. I dont even remember what they were but they were enabled...however to the point, i found that certain ways of doing calculations made things run alot faster for collision. I should also mention the laptop at the time couldnt run q3, but ran quake2 excellently with his res features enabled.
thesanman112
Posts: 538
Joined: Jul 15, 2005 4:13

Re: collision basics....

I also remember someone thinking it was strange to see a 2000 line program without a sub or function....hahahaa
If you want it fast then you need to count all the steps and make less of them...