Results 1 to 10 of 10

Thread: Need help with Object Collision

  1. #1
    NOMADMAN
    Guest

    Need help with Object Collision

    Okay, IntersectRect isn't working... I fear I'm not smart enough to use it!!!

    VB Code:
    1. Type RECT
    2.     LEFT As Long
    3.     RIGHT As Long
    4.     BOTTOM As Long
    5.     TOP As Long
    6. End Type
    7.  
    8. Declare Function IntersectRect Lib "user32" (lpDestRect As RECT, lpSrc1Rect As RECT, lpSrc2Rect As RECT) As Long
    9.  
    10.     Dim temparray As RECT
    11.     Dim rect1 As RECT
    12.     Dim rect2 As RECT
    13.    
    14.     rect1.BOTTOM = 4
    15.     rect1.TOP = 1
    16.     rect1.LEFT = 1
    17.     rect1.RIGHT = 4
    18.    
    19.     rect2.BOTTOM = 6
    20.     rect2.TOP = 2
    21.     rect2.LEFT = 2
    22.     rect2.RIGHT = 6
    23.    
    24.     If IntersectRect(temparray, rect1, rect2) <> 0 Then
    25.         Call MsgBox("HIT HIT HIT")
    26.         Call MsgBox(temparray.TOP & vbTab & temparray.BOTTOM & vbCrLf & temparray.LEFT & vbTab & temparray.RIGHT)
    27.     End If

    This is just an example but I still can't get it to work... Whats wrong with it? Could somebody fix it! THANKS!

    NOMAD

  2. #2
    jim mcnamara
    Guest
    Here's some code & a link to a solid discussion

    http://www.vbforums.com/showthread.p...ight=collision

    PS -search the forums - this question has been answered 10 times every months for a year.

  3. #3
    Zaei
    Guest
    Easy one here, and I doubt that searching will help with this =).

    Your Type is defined in the wrong order. It MUST be Left Top Right Bottom:
    Code:
    Type RECT
        LEFT As Long
        TOP As Long
        RIGHT As Long
        BOTTOM As Long
    End Type
    Just change that, and it will work. It's not you that is stupid, its that you never got to learn about how memory works in a computer, and that is VB's fault =).

    Oh, how I love C++!

    Z.

  4. #4
    NOMADMAN
    Guest

    Thumbs up

    WOW! May I first start off by saying, THANK YOU!

    Secondly may I comment how RETARDED that is, by what you say it has something to do with memory... but I still think a higher level language like VB would know what to do.

    Anyway, thank you again, I couldn't find anywhere where they told me how RECT was supposed to be defined.

    NOMAD

  5. #5
    Addicted Member drewski's Avatar
    Join Date
    Feb 2000
    Location
    WA
    Posts
    242
    hey nomadman. do you have the api text viewer? it should be in the vb tools. if you have it open it up. click File-Load Text File-WIN32API.TXT This should bring up a whole bunch of stuff on the windows API. set the API Type to Types and then type in "rect" below. it should come right up the the type rect. now isn't that cool! you can use this to get bitblt, intersectrect and anything else you have heard of pertaining to the API.

    i hope you found this little tidbit of use.
    I see said the blind man as he spat into the wind.

    It all comes back to me now!

    A.D.T.'s VB

  6. #6
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    RETARDED or NOT

    Type structs, or user defined types, structs or class in c++ don't have accessors like com objects, the names LEFT and TOP only have meaning in compile time; the offsets within the variable itself.
    Using COM objects you have named functions at runtime, and have to use accessors to manipulate data in the class, you cannot go manipulate the data directly, but on the other hand you don't have to care what happens internally.

    Unlike Zaei I hate lowlevel programming, but I have to live with it, since there is complex hardware which our sofware rely on, which makes our paradigmns inefficient at times, but I am no RETARD Java programmer that just ignores it.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  7. #7
    Zaei
    Guest
    Java... I didnt think that commercial apps could be made in a scripting language =).

    NOMADMAN, for a bit more detail than what kedaman or I said...

    Memory works much like an array. You have cells of data, accessible through an index. Each cell contains one Byte. Now, We know that a Long takes 4 bytes of memory, and a RECT has 4 longs, so 4*4=16 bytes of memory. Since the Windows API was written in C, as kedaman said, it doesnt know what Left Top, Right, Bottom are, it just knows where they should be stored in a 16 byte block of memory. So, when you define your RECT as Left Right Top Bottom, VB stores it that way in memory, while the API is looking for Top in the space that Right is stored.

    Z.

  8. #8
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Unfortuantely it seems like the Java retards have a better future
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  9. #9
    Zaei
    Guest
    I've heard that you can't even write a simple swap() function in Java... sick, no?

    Z.

  10. #10
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Swap in java isn't more or less swap than C++

    void swap(Object a,Object b){
    Object temp=a;
    a=b;
    b=temp;
    }

    The sick thing with java that everything is an object and all but internal datatypes are on the heap; all variables are of course pointers. All lowlevel stuff removed, multiple inheritance removed, no generic programming at all, just use Object, the master of overheads.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width