Aligning a Mesh to a picked Surface Normal

BlitzMax Forums/MiniB3D Module/Aligning a Mesh to a picked Surface Normal

Krischan(Posted 2016) [#1]
I want to align a rover model to a polygon surface to drive around on a planet surface. Sounds easy but isn't in minib3d, in Blitz3D I solved this using the AligntoVector command. The planet is pickable and a vertical Linepick gets the surface normal below the rover. The vertical position is no problem but when it comes to the correct alignment of the rover all my algorithms fail and I could need some help here. The rover can move freely in all directions but should stay on the planet surface.

Here is a WIP screenshot


And here is an example code to play with. The cone should align with the quad according to its picked normal but stops suddenly and continues aligning a little bit later again. I have absolute no idea why. I have an example function "AlignToNormal" and included my Quaternion mini library and I assume the solution lies in using quaternions here. Oh, and I want to use vanilla miniB3D if this is possible with it.




KronosUK(Posted 2016) [#2]
I always found MadJacks code in the archive quite good for this. You can use linepicks instead to get vertical height of terrain although it does require 4 linepicks per calc.

Vehicle pitch and roll without child/pivot entities


Krischan(Posted 2016) [#3]
Kronos, that's an excellent idea. I've already implemented this in my sandbox and it works like a charme - the spotlight attached to the rover now points correct downwards the crater hill and the rover drives around like a dune buggy, cool :-) Thanks!



Here is the sandbox with the new "AligntoNormal" function which does the trick:


In my sandbox, the function is called like this (and the terrain below is set to Entitypickmode 2 = polygon)

' Rover Movement
moving = KeyDown(KEY_UP) - KeyDown(KEY_DOWN)
turning = KeyDown(KEY_LEFT) - KeyDown(KEY_RIGHT)
	
TurnEntity rover, 0, turning, 0
MoveEntity rover, 0, 0, moving
AlignToNormal(rover, 2.0)



Hezkore(Posted 2016) [#4]
I see you've already got it working, but is this perhaps of any help? - http://www.blitzbasic.com/codearcs/codearcs.php?code=2782
Or is it what you're basically doing already?