Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Artifical horizon indicator and rotations. Argh!

Talon Brown
Slacker Punk
Join date: 17 May 2006
Posts: 352
12-26-2007 01:06
So I have taken up flying aircraft in SL and have found it to be quite disorienting when I don't have any actual horizon or other points of reference to orient myself with. So I thought I'd create a simple artificial horizon HUD consisting of 1 square root prim that serves as the base (with the crosshairs) and behind that, a sphere textured half blue and half brown. (The sky and the ground, respectively.) So far so good. The problem is getting that sphere to rotate in a manner that matches my aircraft's pitch/yaw. Here is the script I have so far:

CODE

rotation inverse(rotation r)
{
r.z = -r.z;
return r;
}

default
{
state_entry()
{
llSetTimerEvent(0.2);
}

timer()
{
llSetRot(ZERO_ROTATION / (inverse(llGetRootRotation())));
}
}


That almost works but not quite. I had to invert the z-axis because the sphere was indicating the nose of the craft was pointed down when it was pointed up and vice versa. But even with that, it seems to get misaligned depending on which direction of the sim I am facing. I'm not explaining this very well, am I? Basically I have read the wiki info on rotation and quite frankly I don't understand half of it as math was never my strong point. I just want the sphere to rotate up/down and tilt from side to side to provide a visual indicator of my (and my aircraft's) rotation. Any help at all would be greatly appreciated.
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
12-26-2007 03:52
I remember playing with something similar to this as a compass bubble.

you could probabl invert the texture and eliminate the inversion of the z axis IIRC...

I believe you can also invert x and y instead so that they rotate opposite of the expected craft direction

I can't remember if I textured the inside or the outside though, may not matter but this is all by memory, and something to play with if nothing else
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Kage Seraph
I Dig Giant Mecha
Join date: 3 Nov 2004
Posts: 513
02-08-2008 12:50
Hi, Talon, I've coded up something like this in the past. if you're still looking, drop me a message.
_____________________
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
02-08-2008 14:43
I believe if you hollow the sphere, texture the inside, and make the outside completely transparent, you should be able to accomplish what you want with simply:

CODE

llSetRot(ZERO_ROTATION / llGetRot());


(Imagine you are inside a big sphere, and the ground and sky are painted on it. As you tilt, you want the sphere to maintain its orientation. The INSIDE of the sphere is the interesting bit; pretend the world is a big environment map. ;) )

The downside to this approach is that in mouselook, the orientation of your avatar will not be the same as the orientation of the plane. So ideally you'd actually want to have the plane communicate to the attachment what its rotation is (or communicate the key of the plane to the attachment and use llGetObjectDetails(), but this assumes the plane uses the default vehicle coordinate system: x is forward, y is left, z is up).