Post

 Resources 

Console

Home | Profile | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 VBGamer
 VBGamer
 Cross product = ? Direction vector...?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

VBBR
Moderator

Brazil
617 Posts

Posted - Jul 18 2004 :  09:52:47 AM  Show Profile  Reply with Quote
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?

Whatever. Who knows...

Eric Coleman
Gladiator

USA
811 Posts

Posted - Jul 18 2004 :  11:45:13 AM  Show Profile  Visit Eric Coleman's Homepage  Reply with Quote
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.

Go to Top of Page

VBBR
Moderator

Brazil
617 Posts

Posted - Jul 18 2004 :  1:11:30 PM  Show Profile  Reply with Quote
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?

Whatever. Who knows...

Edited by - VBBR on Jul 18 2004 1:14:49 PM
Go to Top of Page

game_maker
Knave

Saudi Arabia
83 Posts

Posted - Jul 18 2004 :  2:18:53 PM  Show Profile  Visit game_maker's Homepage  Reply with Quote
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!
Go to Top of Page

VBBR
Moderator

Brazil
617 Posts

Posted - Jul 18 2004 :  4:16:45 PM  Show Profile  Reply with Quote
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).

Whatever. Who knows...

Edited by - VBBR on Jul 18 2004 4:17:24 PM
Go to Top of Page

game_maker
Knave

Saudi Arabia
83 Posts

Posted - Jul 18 2004 :  6:03:06 PM  Show Profile  Visit game_maker's Homepage  Reply with Quote
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
Go to Top of Page

VBBR
Moderator

Brazil
617 Posts

Posted - Jul 18 2004 :  7:04:42 PM  Show Profile  Reply with Quote
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) '<-- Here  
          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) '<-- Now it's fixed  
          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.


Whatever. Who knows...

Edited by - VBBR on Jul 18 2004 7:15:51 PM
Go to Top of Page

VBBR
Moderator

Brazil
617 Posts

Posted - Jul 18 2004 :  7:41:21 PM  Show Profile  Reply with Quote
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

Whatever. Who knows...
Go to Top of Page

game_maker
Knave

Saudi Arabia
83 Posts

Posted - Jul 19 2004 :  1:31:32 PM  Show Profile  Visit game_maker's Homepage  Reply with Quote
nice

I have added "jump" physics/math to our code

Download Attachment: Sliding.zip
5.42 KB

regards
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
VBGamer © Go To Top Of Page
This page was generated in 0.25 seconds. Snitz Forums 2000

Copyright © 2002 - 2004 Eric Coleman, Peter Kuchnio , et. al.