Vector Help

Blitz3D Forums/Blitz3D Programming/Vector Help

Knight #51(Posted 2008) [#1]
What is a vector? Please, if you can, explain it in low-level-detail.


Gabriel(Posted 2008) [#2]
It's a geometric entity with both length and a direction. It's usually visualized as a straight line with an arrow on the end.

http://en.wikipedia.org/wiki/Euclidean_vector


Knight #51(Posted 2008) [#3]
Ok, thanks. So what's the deal with align to vector then? Could you give me an example?


Knight #51(Posted 2008) [#4]
Better yet.....could you just explain this part of the 'driver' demo.




Gabriel(Posted 2008) [#5]
Essentially, that is using the position of each of the wheels to calculate a vector which runs from one wheel to another. It then aligns the body of the car so that it matches that vector. Or in even simpler terms, it finds out where the wheels are and lines the body up so that it "fits" on top of them.


Ross C(Posted 2008) [#6]
Vectors can be used for, a basic example, asteroids, or more complicated, a collision.

In the game asteroids, the ship has a speed, and a direction it's going in.

A vector can be normalised because 0 and 1. You can obtain something like a vector, be plugging an angle value (the direction your space craft is travelling), into SIN and COS

eg,

speed = 2
angle = 25

x_move = cos(angle) * speed
y_move = sin(angle) * speed

x_pos = x_pos + x_move
y_pos = y_pos + y_move

oval x_pos, y_pos, 2, 2

will draw an oval, travelling at an angle of 25, and moving at a speed of 2. It will basically move 2 pixels per frame. That would be a basic example of a vector.


Knight #51(Posted 2008) [#7]
Cool Ross C. So gabriel, when you said
that is using the position of each of the wheels to calculate a vector which runs from one wheel to another.
What does zx,zy,and zz mean? (what is their abbreviation), and possibly could you explain the parameters of AlignToVector in detail?


Ross C(Posted 2008) [#8]
Please answer that one, because i'm still unsure about what that does too.


Nate the Great(Posted 2008) [#9]
Aligntovector has the x y and z of the first point and the x y and z of the second point so remember a little arrow between those two points. Then imagin the shape and its x axis if you make the last parmenter 1 (i think) it will align the x axis and the shape to the line I told you to remember.

hope this helped :)


Knight #51(Posted 2008) [#10]
I think it helped :| So with the
zx#=(EntityX( wheels[2],True )+EntityX( wheels[4],True ))/2
zx=zx-(EntityX( wheels[1],True )+EntityX( wheels[3],True ))/2


AlignToVector stores that calculation/proceedure and uses it to make a vector?


big10p(Posted 2008) [#11]
zx,zy,zz is a vector.


Knight #51(Posted 2008) [#12]
Oh. Thanks big10p.


Gabriel(Posted 2008) [#13]
In each step, Mark totals the X, Y and Z positions of two wheels and divides by two. In other words, he finds the average position of two wheels. He does this because there are two sets of wheels on a car.

For example, let's do the tilting from left to right. You have the front axis, which has the left-front and right-front wheels on it. But you also have the back axis. You can't really align the car to only one - the back wheels would be off the ground if you align it to the front wheels - so in order to find the best alignment, you calculate the average between the two.

Each component is calculated separately. I have no idea why he prefixes everything with z, but zx, zy and zz are the x, y and z components of the vector.

Now you also asked to explain precisely what the AlignToVector command does? It takes the axis you specify in the fourth parameter ( x, y or z ) and orients the entity so that the axis you specify is pointing along the line of the vector you pass as the first three parameters.

Again, an example. Let's suppose you have a missile, and it's modelled such that it points down the Z axis. If you now say

AlignToVector(1,0,0,3)

Your vector is (1,0,0) so it points to the right. Your axis is the z axis. It now aligns your missile so that the z axis points along that vector, which is also equivalent to the xaxis. So now your missile, which was pointing down the z axis ( into the screen ) is now pointing along the x axis ( to the right. )

That's as well as I can explain it without pictures.


Ross C(Posted 2008) [#14]
Nice one :o)


Knight #51(Posted 2008) [#15]
Thanks :)


Pongo(Posted 2008) [#16]
here is another simple example of aligning car wheels. hopefully it does not add confusion.




Knight #51(Posted 2008) [#17]
Ok, it's starting to help ALOT =)