Thanks to M. Igarashi and nlin for a patch that implements llGetCameraRot().

0.6.0-stable
Dahlia Trimble 2008-10-15 04:42:28 +00:00
parent b70a285373
commit 901acddbdd
3 changed files with 74 additions and 1 deletions

View File

@ -116,6 +116,60 @@ namespace OpenSim.Framework
# endregion
public static Quaternion Axes2Rot(Vector3 fwd, Vector3 left, Vector3 up)
{
float s;
float tr = (float) (fwd.X + left.Y + up.Z + 1.0);
if (tr >= 1.0)
{
s = (float) (0.5 / Math.Sqrt(tr));
return new Quaternion(
(left.Z - up.Y) * s,
(up.X - fwd.Z) * s,
(fwd.Y - left.X) * s,
(float) 0.25 / s);
}
else
{
float max = (left.Y > up.Z) ? left.Y : up.Z;
if (max < fwd.X)
{
s = (float) (Math.Sqrt(fwd.X - (left.Y + up.Z) + 1.0));
float x = (float) (s * 0.5);
s = (float) (0.5 / s);
return new Quaternion(
x,
(fwd.Y + left.X) * s,
(up.X + fwd.Z) * s,
(left.Z - up.Y) * s);
}
else if (max == left.Y)
{
s = (float) (Math.Sqrt(left.Y - (up.Z + fwd.X) + 1.0));
float y = (float) (s * 0.5);
s = (float) (0.5 / s);
return new Quaternion(
(fwd.Y + left.X) * s,
y,
(left.Z + up.Y) * s,
(up.X - fwd.Z) * s);
}
else
{
s = (float) (Math.Sqrt(up.Z - (fwd.X + left.Y) + 1.0));
float z = (float) (s * 0.5);
s = (float) (0.5 / s);
return new Quaternion(
(up.X + fwd.Z) * s,
(left.Z + up.Y) * s,
z,
(fwd.Y - left.X) * s);
}
}
}
public static Random RandomClass
{
get { return randomClass; }

View File

@ -252,6 +252,11 @@ namespace OpenSim.Region.Environment.Scenes
get { return m_CameraCenter; }
}
public Quaternion CameraRotation
{
get { return Util.Axes2Rot(m_CameraAtAxis, m_CameraLeftAxis, m_CameraUpAxis); }
}
public Vector3 Lookat
{
get

View File

@ -7531,7 +7531,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
public LSL_Rotation llGetCameraRot()
{
m_host.AddScriptLPS(1);
NotImplemented("llGetCameraRot");
UUID invItemID=InventorySelf();
if (invItemID == UUID.Zero)
return new LSL_Rotation();
if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero)
return new LSL_Rotation();
if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
{
ShoutError("No permissions to track the camera");
return new LSL_Rotation();
}
ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
if (presence != null)
{
return new LSL_Rotation(presence.CameraRotation.X, presence.CameraRotation.Y, presence.CameraRotation.Z, presence.CameraRotation.W);
}
return new LSL_Rotation();
}