What is AlignToVector doing under the hood?

Blitz3D Forums/Blitz3D Programming/What is AlignToVector doing under the hood?

Gabriel(Posted 2005) [#1]
I'm sure I've used AlignToVector, but I have absolutely no idea what it's doing under the hood. I'm basically trying to emulate all the Blitz commands ( including some I rarely/never use ) and I've done all the TFormVector, TFormPoint, TFormNormal stuff, but AlignToVector is proving a problem, since I don't even know what it does really.


cash(Posted 2005) [#2]
All I know is this...

If I use a pick command for example to select a point on a surface, I can position something at this picked location.

So I pick a location press a button and a bullrthole appears at this location.

Problem is in my example the bullrthole will appear, but I cannot guarantee what its orientation will be. It may be at 90 degrees to the wall.

If I use the aligntovector command and use the pickednx(),pickedny(),pickednz()co-ordinates, then I can ensure the bullethole is rotated to the same orientation as the surface it has hit.

Now my bullethole is flat on the wall.

This is only one example of course. Shadows etc may be another use.

Any use ??
Or have I completely missed the question...


Beaker(Posted 2005) [#3]
It makes one of the axis of the entity align to a vector. A vector being 3 numbers that describe a direction (with a certain length).


Gabriel(Posted 2005) [#4]
Cash: Thanks, but I understand what it does for practical uses. I'm essentially looking for pseudo-code for how to go about doing that.

Beaker: Yep, I understand that. I just have no idea what process that would involve. TFormPoint, Vector and Normal were dead simple, because I could easily visualize a list of everything that's being done. Then I could just write the code to do it one step a time. I can't really get a grasp on the stages involved in AlignToVector though.

BTW I'm not interested in the smoothing parameter. I never use that, and I suspect most people are the same as Cash and myself, just using it for a one-off instant alignment.


big10p(Posted 2005) [#5]
All the Blitz3D geometry code is in the sticky at the top of this forum. Have you had a look through that for any clues?


Gabriel(Posted 2005) [#6]
Erm yeah, but I don't see anything related to this. It's just a bunch of maths classes for vector, quaternion and matrix, etc operations, most of which I already have one way or another. Maybe I'm missing something, but I don't see anything which helps me here.


Braincell(Posted 2005) [#7]
Well what i'd do is i'd get the normal of the picked triangle and then set the normal (facing) of the entity (ie bullethole to that normal).

How to get the normal of the triangle?
Get the triangles three verts, figure out a mathematical common plane theyre all on, figure out their clockwise orientation and make a normal in that direction. This should be doable using TFOrmPoints etc.

How to find out which triangle is picked?
Beats me

How to get the position once you have the orientation?
Not sure on the most efficient way but what i think you can do is make a sort of code for mathematically finding and intersection between a line and a triangle in 3d. Thats all maths pretty much. There is a number of approaches. You could look at the triangle from the lines point of view (if youre sure it has collided with the triangle) and determine how far it is from each vert in that perspective. Then multiply those distances to get the real distances depending on the angle of the triangle.... lol ... yeah basically :) Oh and when you get the distances from each vert you should be able to fing its exact position if you know any maths.

How to check if a line has collided with a triangle?
Thats all maths, figure it out yerself! :P


Gabriel(Posted 2005) [#8]
Erm.. thanks? But my question has nothing to do with normals, picks, triangles or bullets.


Jeppe Nielsen(Posted 2005) [#9]
This could be a start:
Function AlignEntity(entity,dx#,dy#,dz#,roll#=0)

	dist#=Sqr#((dx#*dx#)+(dz#*dz#))
	pitch#=ATan2(dy#,dist#)
	yaw#=ATan2(dx#,-dz#)
	
	RotateEntity entity,pitch#,yaw#,roll#

End Function