Author Topic: Collision Detection  (Read 442 times)

Offline johnno56

  • Live long and prosper.
Re: Collision Detection
« Reply #15 on: June 24, 2018, 01:50:46 AM »
GDK?
Logic is the beginning of wisdom.

Re: Collision Detection
« Reply #16 on: June 24, 2018, 05:41:11 AM »
Thank you, I'm glad to look at it. I'm not an undergraduate, so I first had to find out what you mean by the triangular / circle method. I found this in a bachelor's thesis on this subject, so again i know more.

Hi Johhno56, GDK is Unseen MachineĀ“s library downloadable here: https://www.qb64.org/forum/index.php?topic=284.0;topicseen
Coding is relax (At least sometimes)

Re: Collision Detection
« Reply #17 on: June 24, 2018, 07:14:48 AM »
A little beyond the thema - function for detecting collisions between point and ellipse:

Code: [Select]
'elipse collision detection for point
SCREEN 13
LET CenterX = 160: LET CenterY = 100: LET A = 40: LET B = 20

FOR F = 0 TO _PI(2) STEP .01
    PSET (CenterX + SIN(F) * A, CenterY + COS(F) * B)
NEXT F

DO
    WHILE _MOUSEINPUT: WEND
    LOCATE 1, 1: PRINT Ellipse(_MOUSEX, _MOUSEY, CenterX, CenterY, A, B)
LOOP UNTIL _KEYHIT = 27
END


FUNCTION Ellipse (X&, Y&, CX&, CY&, A&, B&)
    XY## = (((X& - CX&) ^ 2) / A& ^ 2) + (((Y& - CY&) ^ 2) / B& ^ 2)
    IF XY## <= 1.1 THEN Ellipse = 1 ELSE Ellipse = 0
END FUNCTION

Coding is relax (At least sometimes)

Re: Collision Detection
« Reply #18 on: June 24, 2018, 07:23:31 AM »
IMHO
GDK, maybe is it Game Development Kit ?  Like that other library of Terry Ritchie.
They have different structures and GDK has maintenance, about Terry Ritchie's Library it seems discontinued....
I have a previous old version of these library on my Pc (TOSHIBA)
Quote
'\\ UnseenGDK Core v1.4 - Updated March 3rd 2015
'// Created By John Onyon a.k.a Unseen Machine
'// Optimistation by CodeGuy
'// ScanKeys% function by Cypherium
'// Image rotation function by Galleon
'// Rotated rectangle collisions by Richard Notley

from Unseen was coming also VQB02 in the same package...
(IMHO  Visual QB??? but there is nothing like mouseBuilding Interface or Structure of a program...)
a library to build application windowing and manage input from mouse and keyboard
and a demo .... MacDock.BAS

Quote
'// VQB v.02 - By John Onyon a.k.a Unseen Machine
'// VQB_01 programs are NOT comaptible with this version.
.... I don't know if this project is still in being or discontinued.... but of his child must talk at first the father if he will!


Offline bplus

  • B = B + geberation
Re: Collision Detection
« Reply #19 on: June 24, 2018, 10:50:42 AM »
Quote
GDK, maybe is it Game Development Kit ? 

Dang! That's a great theory even if it were incorrect.

No, it's too good to be wrong? :D
« Last Edit: June 24, 2018, 10:52:00 AM by bplus »
B = B + ...

Offline bplus

  • B = B + geberation
Re: Collision Detection
« Reply #20 on: June 24, 2018, 11:26:24 AM »
The flaw of this theory is this:

Why name it with _Dev for .bm file?

but in fact in the last posting he had removed _Dev from the library file name. In fact, I had to fix my copy of his code to match the first .bm I downloaded.
« Last Edit: June 24, 2018, 11:29:06 AM by bplus »
B = B + ...

Offline bplus

  • B = B + geberation
Re: Collision Detection
« Reply #21 on: June 24, 2018, 11:32:03 AM »
I suppose these are developments from having your skull on fire!

BTW, VQB does sound like another excellent name of something!
« Last Edit: June 24, 2018, 11:33:11 AM by bplus »
B = B + ...

Re: Collision Detection
« Reply #22 on: June 24, 2018, 05:07:14 PM »
Hi Petr
fine your sample but so much static....
so I have added a little movement in it

see here
 
Code: [Select]
'elipse collision detection for point
SCREEN 13 'w320xh200 I don't remember well dimensions of old legacy screen mode :-)
LET CenterX = 80: LET CenterY = 100: LET A = 40: LET B = 20
LET MoveX = 1: LET MoveY = 1

DO
    WHILE _MOUSEINPUT: WEND
' output engine (Not mine) :-)
    FOR F = 0 TO _PI(2) STEP .01
        PSET (CenterX + SIN(F) * A, CenterY + COS(F) * B)
    NEXT F

' refreshing after an elapsed time   
    _DELAY 0.02
    CLS
' logic engine to let stay ellipse in the screen
    IF (CenterX - A <= 0) THEN
        MoveX = 1
    ELSE
        IF (CenterX + A >= 320) THEN MoveX = -1
    END IF

    IF (CenterY - B <= 0) THEN
        MoveY = 1
    ELSE
        IF (CenterY + B >= 200) THEN MoveY = -1
    END IF
' logic engine calculating new position of ellipse
    CenterX = CenterX + MoveX 'centerx++/centerx--
    CenterY = CenterY + MoveY 'centery++/ centery--

    LOCATE 1, 1: PRINT Ellipse(_MOUSEX, _MOUSEY, CenterX, CenterY, A, B)
LOOP UNTIL _KEYHIT = 27
END


FUNCTION Ellipse (X&, Y&, CX&, CY&, A&, B&)
    XY## = (((X& - CX&) ^ 2) / A& ^ 2) + (((Y& - CY&) ^ 2) / B& ^ 2)
    IF XY## <= 1.1 THEN Ellipse = 1 ELSE Ellipse = 0
END FUNCTION

@Bplus
hey boy but  are you talking about my brain or my skull? :-(( For now weather is hot but not such so hot!

Quote
I suppose these are developments from having your skull on fire!

a skull can be a head without a brain into it.... just a zombie head :-)
I cannot imagine what can be thought in a head on fire... and moreover in a skull on fire....
like this https://tse3.mm.bing.net/th?id=OIP.tONt-rsCjWByGGeqc9QaiQHaHa&pid=15.1&P=0&w=300&h=300
or this one http://www.desktopanimated.com/img/Preview/FireSkull3.jpg
or just this last http://3.bp.blogspot.com/_6GGcln-fE78/TCXYCwNk2NI/AAAAAAAAAWk/mwmCK9izrG0/s1600/Fire+Skull.jpg

Ok I have found the just SkullOnFire... it is attached

Re: Collision Detection
« Reply #23 on: June 24, 2018, 05:36:02 PM »
Hi TempoDiBasic, thank you. Now it's nicer. I've been looking at your source, and I have never seen the skull picture now, so I say, what it would be. BPlus had some sort of muse :-D mood today, as I read on the forum. He gave his passage full of muse. And my muse is sleeping today: -D
Coding is relax (At least sometimes)

Offline bplus

  • B = B + geberation
Re: Collision Detection
« Reply #24 on: June 24, 2018, 07:37:39 PM »
For burning skull, I was talking about unseen machine's latest avatar!

We were talking about the naming of his GDK system and I was wondering why he named his .BM file unseenGDK_Dev.bm which translates to unseen Game Develoment Kit _ Development.bm the word "development" looked a bit redundant.
B = B + ...

Offline Unseen Machine

  • QB64 Elite
Re: Collision Detection
« Reply #25 on: June 24, 2018, 07:48:41 PM »
_DEV is cause it is the Development version, being edited, its so i dont get confused!

VQB is now moving into v.4, ill be putting it out soon.

Unseen

Offline bplus

  • B = B + geberation
Re: Collision Detection
« Reply #26 on: June 24, 2018, 08:04:57 PM »
;-))  I see, very logical, now.

Very curious about VQB!
B = B + ...

Re: Collision Detection
« Reply #27 on: June 27, 2018, 06:39:22 PM »
This is only the final part of the program, which I will release as long as I finish:

WARNING FOR BPLUS! FULLSCREEN IS USED :-D
Code: [Select]
'IF o theraphy :-D (how, for hell write correct conditions?)

object0: '0 are empty places, 1 are points
DATA 0,0,0,0,0
DATA 0,1,1,1,1
DATA 0,0,0,0,1
DATA 1,1,1,1,1
DATA 1,0,0,0,0

DIM O(4, 4)
'load object data to array for this example. This values return next program i send here soon as possible.
FOR ObjectLoad = 0 TO 24
    READ value
    O(x, y) = value
    x = x + 1: IF x > 4 THEN x = 0: y = y + 1
NEXT

SCREEN _NEWIMAGE(320, 240, 256): _FULLSCREEN
'show what is in array
FOR y = 0 TO 4
    FOR x = 0 TO 4
        IF O(x, y) = 1 THEN PSET (160 + x, 100 + y), 14
NEXT x, y

'now own collision detection form. If Object 1 is in quad Object 2 or above, then:
'example - first row: first row is 5 x empty pixel. Let say, object 2 is comming to this area to third pixel:

'original: 0,0,0,0,0    new: 0,0,1,0,0 - beacause in this row for Object1 are zeros, is none collision.

'If object1 go next 1 pixel down, second row for Object1 is: 0,1,1,1,1 - and now is comming to third position where but is 1. Also is object collision.

'so this programmable:
Object1X = 160
Object1Y = 100
_MOUSEHIDE
DO
    WHILE _MOUSEINPUT
        Object2X = _MOUSEX
        Object2Y = _MOUSEY
    WEND
    CLS
    FOR y = 0 TO 4
        FOR x = 0 TO 4
            IF O(x, y) = 1 THEN

                PSET (Object1X + x, Object1Y + y), 14
                PSET (Object2X + x, Object2Y + y), 15
            END IF
    NEXT x, y


    coll = 0
    'first standard QUAD condition and THEN detail comparation:  (both objects are 5 x 5 pixels)
    IF Object2X >= Object1X - 5 AND Object2X <= Object1X + 5 THEN
        TTT = TIMER
        IF Object2Y >= Object1Y - 5 AND Object2Y <= Object1Y + 5 THEN
            LOCATE 1, 1: PRINT "In collision area "
            FOR TY = Object1Y TO Object1Y + 4
                FOR TX = Object1X TO Object1X + 4

                    FOR tTY = Object2Y TO Object2Y + 4
                        FOR tTX = Object2X TO Object2X + 4
                            IF O(TX - Object1X, TY - Object1Y) = 1 AND O(tTX - Object2X, tTY - Object2Y) = 1 AND TX = tTX AND TY = tTY THEN coll = 1: GOTO E ELSE coll = 0
                            'Of course, for a higher program speed, it's better to use a step higher than 1 for the shape of the object. Let's assume that your character is 60 pixels high,
                            ' moving in one step by 10 pixels. Then, the enemy moves with a 10-pixel pitch, so only every ten of the pixel per circuit character is needed.
            NEXT tTX, tTY, TX, TY
        END IF
        LOCATE 3, 1: PRINT TIMER - TTT
    END IF
    E:
    IF coll THEN LOCATE 2, 1: PRINT "Is collision " ELSE LOCATE 2, 1: PRINT "Not collision"
    _DISPLAY
LOOP UNTIL _KEYHIT = 27
Coding is relax (At least sometimes)

Offline bplus

  • B = B + geberation
Re: Collision Detection
« Reply #28 on: June 27, 2018, 06:55:54 PM »
Thanks for warning, I am now armed with Alt+F4 and ready for no escape. ;)

This seems like allot of work and works!
B = B + ...

Re: Collision Detection
« Reply #29 on: June 27, 2018, 07:11:22 PM »
Divide and rule. The digital monster was stubborn, so I had to divide it. :-D
Coding is relax (At least sometimes)