Phil Jones' pitch and roll example

Blitz3D Forums/Blitz3D Programming/Phil Jones' pitch and roll example

I'm using his Pitch and Roll example from the code archives and I was wondering, if instead of using a terrain if I could use a different entity?

I would like to use this technique on a plane that I have set up with waves and stuff. I'd like it to roll with the waves and etc and I really like his example.

So, I guess my question is, how can I reconfigure this small bit of code so it works with my plane instead of a terrain?

anglenew# = yaw -90  ; what must be added to yaw to calculate front of vehicle's global x,z co-ords
xnew# = x+Cos(anglenew)*carlength
znew# = z+Sin(anglenew)*carlength
frontheight# = TerrainY(terrain,xnew,y,znew); get the height at new x,y,z
PositionEntity pfront,xnew,frontheight,znew ; a visual marker only - not neccessary for calculations

anglenew# = yaw +90 ; what must be added to yaw to calculate back of vehicle's global x,z co-ords
xnew# = x+Cos(anglenew)*carlength
znew# = z+Sin(anglenew)*carlength
backheight = TerrainY(terrain,xnew,y,znew)
PositionEntity pback,xnew,backheight,znew

anglenew# = yaw  ; what must be added to yaw to calculate midleft of vehicle's global x,z co-ords
xnew# = x+Cos(anglenew)*carwidth
znew# = z+Sin(anglenew)*carwidth
Leftheight = TerrainY(terrain,xnew,y,znew)
PositionEntity pleft,xnew,leftheight,znew

anglenew# = yaw + 180 ; what must be added to yaw to calculate midright of vehicle's global x,z co-ords
xnew# = x+Cos(anglenew)*carwidth
znew# = z+Sin(anglenew)*carwidth
rightheight = TerrainY(terrain,xnew,y,znew)
PositionEntity pright,xnew,rightheight,znew

pitchx# = carlength*2 ; need complete length of car for x
pitchy# = (backheight - frontheight); the height dif between the front and rear of car
pitch = ATan2(pitchx,pitchy); atan2 will return the angle from 0,0 to x,y

rollx# = carwidth*2
rolly# = (rightheight - leftheight) ; the height dif between the left and right of car
roll# = ATan2(rollx,rolly); atan2 will return the angle from 0,0 to x,y

RotateEntity car, pitch-90,yaw,roll-90 ; rotate car with offsets to adjust Atan2's calculation

th=(frontheight+backheight+leftheight+rightheight)/4; get average of terrain heights for cars overall height
PositionEntity car,x,th,z ; adjust car height 
MoveEntity car,0,0,speed

PositionEntity pop,x,th,z ; this is just a central axis 'pole' to help see rotation angles 
RotateEntity pop,pitch-90,yaw,roll-90