Rotate Object Parallel to Underlying Surface?

Blitz3D Forums/Blitz3D Programming/Rotate Object Parallel to Underlying Surface?

Gabriel(Posted 2004) [#1]
The best example I can think of is aligning a car to a mesh. If the car doesn't rotate ( yaw ) then I could just retrieve the angles from the Atan of the normals ( at least I think I could ) but that won't work when you change the yaw of the car.

Note : I need to actually retrieve the angles, not just rotate the object ( I'm thinking AlignToVector could do that but I don't want to rotate the object. ) I just want to retrieve the pitch and roll that I *would* use if I was going to align the car to the mesh.


BlitzSupport(Posted 2004) [#2]
When you say 'surface', I assume you mean a triangle (since a surface can contain triangles pointing in all sorts of directions)...?

If so, this might help you on your way...

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

(Bear in mind you could just AlignToVector a pivot and use the results from that -- the speed hit will be trivial.)


Gabriel(Posted 2004) [#3]
Yeah, I've tried AlignToVector with a pivot. I think it's right except that it points the car parallel with the normal rather than parallel with the surface. I'm not sure how to get from one to the other ( considering the car can have any Yaw. )

I'm not very good at reading other people's code, and though Richard's code clearly does the job, I can't see how it works. I think the pivot would work if I could figure out the conversion from parallel with normal to parallel with triangle.


Gabriel(Posted 2004) [#4]
Ok, I've got it started, but I can't get it finished right.

Here's the code so far.

; LINEPICK DOWNWARD

baseent=LinePick (EntityX#(Player\entityhandle,True),EntityY#(Player\entityhandle,True),EntityZ#(Player\entityhandle,True),0,-2,0)

nx#=PickedNX#()
ny#=PickedNY#()
nz#=PickedNZ#()


temppiv=CreatePivot()
AlignToVector temppiv,nx#,ny#,nz#,1
AlignToVector temppiv,nx#,ny#,nz#,3
TurnEntity temppiv,90,0,0

Player\TargetPitch#=EntityPitch#(temppiv)
FreeEntity temppiv


That works fine if the player yaw remains zero. But I need to be able to account for whatever the yaw can be because it could be anything.

I've uploaded a diagram to show what I mean.





The player is on a downward slope, the normal is the big arrow. If the yaw is zero ( we're looking side on ) then I need to rotate 90 degrees to get the right pitch. But if the yaw is 180 degrees ( pointing back up the slope ) then i need to rotate -90 degrees to get the right pitch. In both cases the roll will be zero, but if the yaw is 90 or 270 then the pitch will be zero and the roll will be 90 or -90 instead. And all the angles inbetween obviously.

What am I missing to make it work for all yaw values?


Gabriel(Posted 2004) [#5]
Sorry for the broken link. For some reason the file just vanished from my webspace.