Cross product = ? Direction vector...? | |

VBBR | 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? |

Eric Coleman | 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. |

VBBR | 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? |

game_maker | 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! [8)] |

VBBR | 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 | 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: [url="http://www.vbgamer.com/msgboard/uploaded/game_maker/200471818249_Sliding.zip"][img]icon_paperclip.gif[/img]Sliding.zip[/url]4.35 KB regards [:)] |

VBBR | Oh, I found a small bug. Here, this is part of the code for KeyDown. [code]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) '<-- Here Speed = Vector_Normlize(Speed) Speed = Vector_ConstProduct(Speed, S) C = Vector_VectorAdd(C, Speed) End If End If[/code] Now you put 1 instead of I there. The right would be [code]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) '<-- Now it's fixed Speed = Vector_Normlize(Speed) Speed = Vector_ConstProduct(Speed, S) C = Vector_VectorAdd(C, Speed) End If End If[/code] 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. |

VBBR | And here it is, all fixed! Just update the KeyDown event as follows: [code]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[/code] |

game_maker | nice [:)]
I have added "jump" physics/math to our code
Download Attachment: [url="http://www.vbgamer.com/msgboard/uploaded/game_maker/2004719132715_Sliding.zip"][img]icon_paperclip.gif[/img]Sliding.zip[/url]5.42 KB regards [:)] |