Vectors, Normals?

Blitz3D Forums/Blitz3D Beginners Area/Vectors, Normals?

Buggy(Posted 2006) [#1]
What are vectors and what are normals? I've googled and dictionaried and wikipedia-ed the terms, so don't tell me to look them up.

Can someone please explain how to use these commands like CollisionsNX# and AlignToVector? I really want to know, and neither manual helps.

Thanks in advance.


jfk EO-11110(Posted 2006) [#2]
The term "vector" is used for something that defines an alternation of a state, like a curve on a street. The vector contains the relative angle of the curve.
The word "vector" is also used for adresses of system interrupts in computer operating systems: it will redirect the program counter to a subroutine (kind of Gosub on the machine level).
In the command "AlignToVector" the source entities vector is used to rotate the target entity. Basicly this is pitch, yaw and roll of the source entity.

The term "normals" represents the pitch,yaw,roll angles of a triangle in space. so, when you pick an entity, pickedNX() etc. will tell you the angle of the picked point. This may be useful for preventing sliding down slopes etc.


Shambler(Posted 2006) [#3]
A vector is something which describes a direction and/or magnitude/speed.

Vectors are normally 2D 'x,y' or 3d 'x,y,z'.

The relative values of the x y and z components tell you which direction the vector is pointing in.

The absolute values of the x y and z components tell you the magnitude of the vector, how far or how fast in that direction?

So for example a vector of 1,1,1 means x+1,y+1,z+1.

A vector of 2,2,2 points in the same direction as 1,1,1 because the relative values are the same ( they are all equal ) but it is twice as large, so it would mean a movement twice as far or twice as fast.

A normal is 'usually' a 3D vector which describes the direction a triangle is facing and this is used to calculate how the face should be lit by hardware lighting or other lighting methods...in this case you are not interested in the magnitude of the vector, just its direction.

CollisionNX() etc. can be used to tell you the angle of the triangle that was involved in the collision.

You can use this to decide how to react to the collision, e.g. to bounce away from the collision by using the NX() NY() NZ() values to change the direction of whichever entity was invloved in the collision.

The list of what you can use the CollisionNX() etc. values for is endless and depends upon your specific needs.


Sir Gak(Posted 2006) [#4]
Great answers, guys!! I was wondering, myself.

So, maybe you can help with a follow-up question related to this point. I want to create a 3d object, a dodecahedron (a 20-sided die like those used in lots of role-playing games). Suppose, once I have my 3d dodecahedron, I want to select one of the sides (ie a pentagon shape). Then, I want to cause a cube or cone to be attached to that side. The default positions of CreateCube() and CreateCone() is at 0,0,0. How can I cause the new object to use the "flat" of the selected surface to be the default surface that the new object is to be attached to, thus the new object is of the same vector/normal as the surface being used as the base for the new object (ie perpendicular to the selected surface)? Is that making sense?


BlackJumper(Posted 2006) [#5]
do-dec = 2-10 i.e. a 12 sided polyhedron (this has pentagonal faces)

http://mathworld.wolfram.com/Dodecahedron.html

You are referring to an icosahedron (triangular faces)

http://mathworld.wolfram.com/Icosahedron.html

... as to the aligning/attaching problem - can't help atm... I'm sure someone will be along soon who knows this stuff.


Sir Gak(Posted 2006) [#6]
Thanks for the clarification. Quite right. But, the original question of aligning/attaching remains, whether I use a surface face of either a dodecahedron or icosahedron.


Stevie G(Posted 2006) [#7]
Well, you could use ...

camerapick ( camera, mousex(), mousey() )
if Picked = dodecahedron
positionentity attached, pickedx(), pickedy(), pickedz()
aligntovector attached, pickednx(), pickedny(), pickednz(), 3
endif

You might have to move the shape a bit on the z-axis depending on how you create the entity .. 'attached'.

As for centering 'attached' on the poly, use pickedtriangle, get the average position of each vertex in that triangle and tformpoint from dodecahedron space to world space to get the position.

Hope this helps.

Stevie


Buggy(Posted 2006) [#8]
I am still rather confused. If AlignToVector simply rotates an entity, why not use RotateEntity or TurnEntity?

What is "picking" an entity? I tend to be exceptionally slow with these concepts, so can you guys help?


Buggy(Posted 2006) [#9]
Can someone also explain the use of these commands in the ball rolling physics example by Jeppe Nielsen?


Stevie G(Posted 2006) [#10]
To use Rotateentity and turnentity you must know the angles first, with aligntovector no angle is necessary .. just a vector defining a direction on a specific axis. Also, aligntovector uses quarternions so avoids gimbal lock issues.

For picking, in terms of the example above, imagine a laser starting at the mouse coords and going off into the distance. If this line hits an entity it will return which entity has been hit. You can also extract the point on the entity which has been hit & the normals of the polygons which have been hit amongst other things. I'm sure someone can come up with a far better explanation.

Post a link to Jeppe's example and someone should be able to help.

Stevie


Buggy(Posted 2006) [#11]
Stevie G, you're the one who sent me the link to Jeppe's example in the first place! I don't know how to make a link, but here:

http://www.blitzbasic.com/codearcs/codearcs.php?code=856

And won't countCollisions tell you which entity got hit?


Stevie G(Posted 2006) [#12]
@ Buggy, I'm not your personal helper!! Considering the link to Jeppe's example is in a different thread, it's unlikely that others will search the code archives to find it and help.

Countcollisions, by definition, tells you how many collisions an entity was involved in. Look at the 'Entity Collision' category in the 3d manual for explanations of all the collision commands.

From what I can see you haven't thanked a single person in this thread for taking the time to answer your questions. Sometimes you need to help yourself!

Stevie


Buggy(Posted 2006) [#13]
Firstly, thank you.

I'm sorry if I angered you, Stevie G. You are in no way obliged to answer my posts.

Thank you very much for taking the time to answer my questions, everyone. Usually I say thank you, but I haven't really understood much of the replies here, and I'm not accustomed to saying, "Thank you oh so very much. I am still confused."

Apologies all around.


Buggy(Posted 2006) [#14]
By the way, do I understand correctly that the Pick commands find the closest entity to another entity?


Stevie G(Posted 2006) [#15]
No, like I said ... look at the manual ...

http://www.blitzbasic.com/b3ddocs/command.php?name=LinePick&ref=3d_a-z

Stevie


Buggy(Posted 2006) [#16]
I did! I think I'm just stupid...

I understand that Jeppe Nielson's ball code is good because it tests for collisions by making the ball bounce back with one set of code, instead of three for the three axes.

I just don't understand the specifics... ;)


octothorpe(Posted 2006) [#17]
A vector is a line in space. It has a direction and a magnitude (its length.) A common example of a vector's usage is in keeping track of the velocity of a physical body:



Note that in the above diagram, the vector's components (x and y separately) are shown. The actual vector can be found by adding its components. You'd end up with a line pointing in the exact direction the cannonball is moving, with the length of the line showing its exact speed.



Vectors are used for normals as well as velocities. A normal describes the "angle" of a flat surface by pointing directly away from it. The normal of your desk is a line pointing straight up. The normal of the hood of your car points up and forwards a little (assuming that your hood is closed and we only have to deal with one side of it.) Typically, the magnitude (length) of a normal is 1, because its magnitude is not important. A vector with a magnitude of 1 is considered "normalized."


Buggy(Posted 2006) [#18]
Good god! I actually understood that! Octothorpe, you are my hero! You can't understand how much that helps me! Thanks you so much!

Now do I just use AlignToVector to make an entity "snap" to another entity's vector?

Thank you so much, by the way.


sswift(Posted 2006) [#19]
Buggy:
Yes. Assuming your objects are pointing down the Z axis like the camera, then you would align the Z axis with the other entity's vector to point it in the same direction.


octothorpe(Posted 2006) [#20]
A Pick is like a laser range-finder. You define a point in space for the laser to start at and the direction it'll be shot in. The first thing the laser strikes is the result of your pick. You can now (for example) get the exact co-ordinates of the hit, grab the entity handle, and figure out the normal for the triangle that you hit.

An example usage would be to pick straight down from an ant to get the angle of the ground it's walking on. You might use this to align its mesh to the ground so that it looks like the ant's feet are touching the ground realistically when it walks over a hill.

Note that you must register the Pick "mode" for entities, or your picks will go right through them. See the docs.


OT: Sir Gak - thread hijacking is not cool. I almost didn't read this thread because it was cluttered up. Please start a new thread next time.


octothorpe(Posted 2006) [#21]
Now do I just use AlignToVector to make an entity "snap" to another entity's vector?


Eh? Entities don't have "vectors:" they have a rotation (pitch, yaw, and roll) and a position (technically, position is a vector, but I'm fairly certain that you don't mean to use one entity's direction-from-the-origin for aligning a second entity.)

I dont understand what you're trying to do. Please elaborate.

If you want to reset an entity's rotation to be the same as another entity's, you could RotateEntity(d, EntityPitch(s), EntityYaw(s), EntityRoll(s)), but I suspect there's a better solution to your specific problem - probably to do with parenting.


sswift(Posted 2006) [#22]
octo:
An entities face direction, the direction it's Z axis points can be thought of as a normal, which is a kind of vector, and you can point another entity down the same axis.


Buggy(Posted 2006) [#23]
I'm not really sure what I was trying to say, either, Octo.

Umm, how would I use AlignToVector if entities don'e have vectors?


Ross C(Posted 2006) [#24]
See this thread here and try out the code:

http://www.blitzbasic.com/Community/posts.php?topic=58243


Buggy(Posted 2006) [#25]
Thanks, Ross C. I think I sort of understand it enough to not use it, and to know I don't need it for now. But why did Jeppe Nielson use it?