Join us in Outworldz at www.outworldz.com:9000 or follow us:

Search dozens of selected web sites for OpenSim and LSL script

New! Script Meta-Search will search thousands of scripts here and at other sites for LSL or Opensim scripts.
Loading

Want to add a script or a project? Upload it and a half million people will see it and your name here this year.

Home   Show All
Category: Contributor: Creator
Vehicles Attitude_Indicator_Artificial_Horiz  

Attitude_Indicator_Artificial_Horiz

DESCRIPTION: []::Attitude_Indicator_Artificial_Horizizon

Category: Vehicles
By : Timeless Prototype
Created: 2011-09-04 Edited: 2011-09-04
Worlds: Second Life

the Zip file

Download all files for Attitude_Indicator_Artificial_Horiz
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Attitude_Indicator_Artificial_Horiz_1.lsl
1 // myGetRoll(), myGetPitch(), myGetBearing(), mySetHorizonTexture()
2 // by Timeless Prototype
3 // Helps with attitude indicator (artificial horizon) display on a prim, plus a few other functions you will probably want for any flying vehicle instruments.
4 // Created 2009-12-01
5 // Please give credit to Timeless Prototype in documentation when using anything from this script.
6
7 key craftKey = NULL_KEY;
8
9 // Returns the roll relative to the horizon (0.0), ranging from 90.0 (right wing down) to -90.0 (left wing down). Assumes frame of reference is East-facing at zero rotation.
10 float myGetRoll(rotation rot)
11 {
12 vector vOffset = <0,1,0> * rot;
13 vector noX = <0.0, llVecMag(<0.0, vOffset.x, vOffset.y>), vOffset.z>;
14 float roll = llAtan2(noX.z, noX.y) * RAD_TO_DEG;
15 // However, this is the only indicator we're using to check if we're upside down.
16 // Therefore the only indicator we want to exceed the -90.0 and 90.0 thresholds.
17 vector upsideDownCheck = <0,0,1> * rot;
18 if(upsideDownCheck.z < 0.0)
19 {
20 if(roll < 0.0)
21 {
22 roll = -180.0 - roll;
23 }
24 else
25 {
26 roll = 180.0 - roll;
27 }
28 }
29 return roll * DEG_TO_RAD;
30 }
31
32
33 // Returns the pitch relative to the horizon (0.0), ranging from 90.0 (up) to -90.0 (down). Assumes frame of reference is East-facing at zero rotation.
34 float myGetPitch(rotation rot)
35 {
36 vector vOffset = <1,0,0> * rot;
37 vector noY = <llVecMag(<vOffset.x, vOffset.y, 0.0>), 0.0, vOffset.z>;
38 return llAtan2(noY.z, noY.x);
39 }
40
41 // Returns a compass bearing. Assumes frame of reference is East-facing at zero rotation.
42 float myGetBearing(rotation rot)
43 {
44 vector vOffset = <1,0,0> * rot;
45 float bearing = llAtan2(vOffset.x, vOffset.y) * RAD_TO_DEG;
46 if(bearing < 0.0)
47 {
48 bearing += 360.0;
49 }
50 return bearing * DEG_TO_RAD;
51 }
52
53
54 mySetHorizonTexture(rotation vehicleRotation, integer primFace) {
55 llSetPrimitiveParams([PRIM_TEXTURE, primFace, "973bb206-0812-89e6-21d3-a268f47dfa65", <0.3, 0.3, primFace>, <0.0, (myGetPitch(vehicleRotation)/6.39)-0.25, primFace>, myGetRoll(vehicleRotation)]);
56 }
57
58 default
59 {
61 {
62 llSetTimerEvent(0.0);
63 llListen(55, "", NULL_KEY, "");
64 }
65
66 attach(key id)
67 {
68 llSetTimerEvent(0.0);
69 }
70
71 listen(integer channel, string name, key id, string message)
72 {
73 if(llSubStringIndex(message, "cmd|hud|connect|") == 0)
74 {
75 key pilotId = (key)llGetSubString(message, 16, -1);
76 if(pilotId == llGetOwner())
77 {
78 craftKey = id;
79 llSetTimerEvent(0.5);
80 }
81 }
82 }
83
84 timer()
85 {
86 list details = llGetObjectDetails(craftKey, [OBJECT_NAME, OBJECT_POS, OBJECT_ROT" title="View Definition" class="tooltip">OBJECT_ROT, OBJECT_VELOCITY]);
87 if(llList2String(details, 2) == "")
88 {
89 llSetTimerEvent(0.0);
90 llOwnerSay("Vehicle has left the region. Please use autopilot features to control the vehicle.");
91 }
92 mySetHorizonTexture((rotation)llList2String(details, 2), 4);
93 }
94 }

Back to the Best Free Tools in Second Life and OpenSim.