Advertisement
Guest User

KOS Attempt at vectors and angles

a guest
Feb 11th, 2015
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. sas off.
  2. rcs off.
  3. clearscreen.
  4.  
  5. //finds local port.
  6. set pm1 to ship:modulesnamed("ModuleDockingNode").
  7. for portmod in pm1 {set myPort to portmod:part.}.
  8. lock myportposition to myport:position.
  9.  
  10. //find target ship's port.
  11. set pm2 to target:modulesnamed("ModuleDockingNode").
  12. for portmod in pm2 {set targetPort to portmod:part.}.
  13. lock targetportposition to targetPort:position.
  14.  
  15. // Find axis of rotation, and angle around that axis, to rotate from my ship:facing to my myPort:PORTFACING.
  16. set rotAngle to VANG( SHIP:FACING:VECTOR, myPort:PORTFACING:VECTOR ).
  17. set rotAxis to VCRS( SHIP:FACING:VECTOR, myPort:PORTFACING:VECTOR ).
  18. set rotAxis to rotAxis:NORMALIZED.
  19.  
  20. // Splitting the rotAxis into its 3 component parts, in a reference frame that is oriented
  21. // to match my ship:facing:
  22. set rotAxisX to VDOT( rotAxis, SHIP:FACING:STARVECTOR ).
  23. set rotAxisY to VDOT( rotAxis, SHIP:FACING:TOPVECTOR ).
  24. set rotAxisZ to VDOT( rotAxis, SHIP:FACING:FOREVECTOR ).
  25.  
  26. Set runmode to 1.
  27.  
  28. until runmode = 0 {
  29.  
  30. //finds the angle of the other port (we're using targetPort to make this simple)
  31. set otherPortRot to targetPort:PORTFACING.
  32. set otherPortInverseRot to ANGLEAXIS(180,otherPortRot:TOPVECTOR)*targetPort:PORTFACING.
  33.  
  34. //should set the correct angle for lock steering
  35. set otherPortInverseRotAxis to otherPortInverseRot*V( rotAxisX, rotAxisY, rotAxisZ ).
  36. set myPortRotRelToOther to ANGLEAXIS(-rotAngle,otherPortInverseRotAxis)*otherPortInverseRot.
  37.  
  38. //lock steering to lookdirup(target:facing:vector,myPortRotRelToOther:vector).
  39. lock steering to myPortRotRelToOther.
  40.  
  41. //This is trying to set a vector from myport:facing to the target port position, then finding the angles.
  42. lock myporttotargetport to (myport:facing*targetportposition).
  43. lock myporttotargetangleZangle to vang(myport:facing:vector,myporttotargetport).
  44. lock myporttotargetangleXangle to vang(myport:facing:starvector, myporttotargetport).
  45. lock myporttotargetangleYangle to vang(myport:facing:upvector, myporttotargetport).
  46.  
  47. //This is displaying those vectors above.
  48. set aa1 to vecdrawargs (myportposition, (myport:facing:starvector)*20, green, "X-STAR-axis", 1, true). //starboard of port
  49. set aa2 to vecdrawargs (myportposition, (myport:facing:upvector)*20, blue, "Y-UP-axis", 1, true). //up of port.
  50. set aa3 to vecdrawargs (myportposition, (myPort:facing:vector)*20, red, "Z-FOR-axis", 1, true). //port facing.
  51. set aa4 to vecdrawargs (targetportposition, (targetPort:portfacing:vector)*20, purple, "axis-of-target port facing", 1, true). //port facing.
  52. set aa5 to vecdrawargs (myport:position, targetportposition, RGB(1,0.5,0), "Vector from my port to target", 1, true). //port facing to target.
  53.  
  54. //This is printing those angles, I'm not sure if the X Y Z are correct.
  55. print "Zangle " + round(myporttotargetangleZangle,3) at (5,6).
  56. print "Xangle " + round(myporttotargetangleXangle,3) at (5,7).
  57. print "Yangle " + round(myporttotargetangleYangle,3) at (5,8).
  58.  
  59.  
  60. } //end runmode, or when runmode = 0.
  61. sas on.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement