|
-
Oct 30th, 2001, 06:37 PM
#1
Need help with Object Collision
Okay, IntersectRect isn't working... I fear I'm not smart enough to use it!!!
VB Code:
Type RECT
LEFT As Long
RIGHT As Long
BOTTOM As Long
TOP As Long
End Type
Declare Function IntersectRect Lib "user32" (lpDestRect As RECT, lpSrc1Rect As RECT, lpSrc2Rect As RECT) As Long
Dim temparray As RECT
Dim rect1 As RECT
Dim rect2 As RECT
rect1.BOTTOM = 4
rect1.TOP = 1
rect1.LEFT = 1
rect1.RIGHT = 4
rect2.BOTTOM = 6
rect2.TOP = 2
rect2.LEFT = 2
rect2.RIGHT = 6
If IntersectRect(temparray, rect1, rect2) <> 0 Then
Call MsgBox("HIT HIT HIT")
Call MsgBox(temparray.TOP & vbTab & temparray.BOTTOM & vbCrLf & temparray.LEFT & vbTab & temparray.RIGHT)
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
-
Oct 30th, 2001, 06:47 PM
#2
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.
-
Oct 30th, 2001, 10:57 PM
#3
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.
-
Oct 31st, 2001, 12:39 AM
#4
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
-
Oct 31st, 2001, 12:57 AM
#5
Addicted Member
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
-
Oct 31st, 2001, 03:39 AM
#6
transcendental analytic
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.
-
Oct 31st, 2001, 07:39 AM
#7
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.
-
Oct 31st, 2001, 08:06 AM
#8
transcendental analytic
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.
-
Oct 31st, 2001, 08:24 AM
#9
I've heard that you can't even write a simple swap() function in Java... sick, no?
Z.
-
Oct 31st, 2001, 09:14 AM
#10
transcendental analytic
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|