VBBR |
Posted - Jul 18 2004 : 09:52:47 AM Well, I want to find the direction vector between two vectors. Now I think I heard somewhere that this could be accomplished using the cross product (or dot product or one of those). Of course I don't remember how, hehe.
So, any help please on how to find the direction vector? |
game_maker |
Posted - Jul 19 2004 : 1:31:32 PM nice
I have added "jump" physics/math to our code
Download Attachment: Sliding.zip 5.42 KB
regards |
VBBR |
Posted - Jul 18 2004 : 7:41:21 PM And here it is, all fixed! Just update the KeyDown event as follows:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) Dim NewX As Single, NewY As Single, I As Long, S As Single S = 100 If KeyCode = vbKeyRight Then NewX = S If KeyCode = vbKeyLeft Then NewX = -S If KeyCode = vbKeyDown Then NewY = S If KeyCode = vbKeyUp Then NewY = -S Debug.Print NewY If NewX Or NewY Then C.X = C.X + NewX C.Y = C.Y + NewY For I = 0 To UBound(xLine) If GetColl(xLine(I)) Then C.X = C.X - NewX C.Y = C.Y - NewY If xLine(I).Type = 1 Then Dim Speed As Vector2D Speed = Vector_Make(xLine(I).P1, xLine(I).P2) If NewX > 0 Then If Speed.X < 0 Then Speed = Vector_ConstProduct(Speed, -1) ElseIf NewX < 0 Then If Speed.X > 0 Then Speed = Vector_ConstProduct(Speed, -1) End If If NewY > 0 Then If Speed.Y < 0 Then Speed = Vector_ConstProduct(Speed, -1) ElseIf NewY < 0 Then If Speed.Y > 0 Then Speed = Vector_ConstProduct(Speed, -1) End If Speed = Vector_Normlize(Speed) Speed = Vector_ConstProduct(Speed, S) C = Vector_VectorAdd(C, Speed) End If End If Next I End If Draw End Sub
|
VBBR |
Posted - Jul 18 2004 : 7:04:42 PM Oh, I found a small bug. Here, this is part of the code for KeyDown.
If GetColl(xLine(I)) Then C.X = C.X - NewX C.Y = C.Y - NewY If xLine(I).Type = 1 Then Dim Speed As Vector2D Speed = Vector_Make(xLine(1).P1, xLine(1).P2) Speed = Vector_Normlize(Speed) Speed = Vector_ConstProduct(Speed, S) C = Vector_VectorAdd(C, Speed) End If End If
Now you put 1 instead of I there. The right would be
If GetColl(xLine(I)) Then C.X = C.X - NewX C.Y = C.Y - NewY If xLine(I).Type = 1 Then Dim Speed As Vector2D Speed = Vector_Make(xLine(I).P1, xLine(I).P2) Speed = Vector_Normlize(Speed) Speed = Vector_ConstProduct(Speed, S) C = Vector_VectorAdd(C, Speed) End If End If
This solves some strange problems I was having. But now the problem is as follows. For each line: - If the upper point is to the right of the down point the ball ALWAYS go up; - If the upper point is to the left of the down point the ball ALWAYS go down.
I will try to fix this here. Anyway, a BIG thanks to you for figuring that out. |
game_maker |
Posted - Jul 18 2004 : 6:03:06 PM Ya I understand now
hmmmmm ,,, if there is a collision ... take the line direction ... normlize it then now you have a unit direction .... multiply with your scaler speed you will have your vector speed .... nice and easy
Download Attachment: Sliding.zip 4.35 KB
regards |
VBBR |
Posted - Jul 18 2004 : 4:16:45 PM Uh, like when you run diagonally to a wall, when you hit it, instead of just stoping upon the encounter, you continue "sliding" along the wall. That means, in most of the cases, nullifying the movement component perpendicular to the surface and moving only in the parallell one (assuming there was a collision). |
game_maker |
Posted - Jul 18 2004 : 2:18:53 PM If vectorA perpendicular to vectorB then
A (dot) B = 0
Because the dot product definition is: A (dot) B = |A| |B| cost . And t = 90,270, hence cos90, 270 = 0 Therefore A (dot) B = 0
If vectorA || to VectorB then
A (Cross) B = 0
A (Cross) B = |A| |B| sint (normal vector). And t = 0,180 hence sin0,180 is = 0 .......
That's means A Cross A = 0
There are a lot of properties that's you should remember in order to use vector calculus
BTW: what do you mean by sliding! |
VBBR |
Posted - Jul 18 2004 : 1:11:30 PM That seems to be what I want, thanks. (see, the thing I'm trying to do is circle-line collision checking with sliding. I'm having trouble finding the component of the movement vector that is perpendicular to the line so I'm trying various things.)
OK, I think I've had enough trouble aready. Is sliding really needed? Did anyone create some code for sliding circle-line collision checking? |
Eric Coleman |
Posted - Jul 18 2004 : 11:45:13 AM I'm not sure what you mean by "direction vector."
If you subtract two vectors, such as A - B = C then the vector C is a vector in the direction from B to A. B - A would give you a vector from A towards B.
Here is an example. A = <1, 0> B = <1, 1> C = A - B = <1 - 1, 0 - 1> = <0, -1>
The vector C points down from B to A.
D = B - A = <1 - 1, 1 - 0> = <0, 1> The vector D points up. |
|
|