implement osNpcGetRot() and osNpcSetRot()

Rotation works if done around the z axis.  Anything else leads to random results.
bulletsim
Justin Clark-Casey (justincc) 2011-08-11 23:28:14 +01:00
parent b1ae930c6b
commit a21e98ae1a
4 changed files with 67 additions and 5 deletions

View File

@ -369,7 +369,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
} }
// convert a LSL_Rotation to a Quaternion // convert a LSL_Rotation to a Quaternion
protected Quaternion Rot2Quaternion(LSL_Rotation r) public static Quaternion Rot2Quaternion(LSL_Rotation r)
{ {
Quaternion q = new Quaternion((float)r.x, (float)r.y, (float)r.z, (float)r.s); Quaternion q = new Quaternion((float)r.x, (float)r.y, (float)r.z, (float)r.s);
q.Normalize(); q.Normalize();
@ -2061,6 +2061,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{ {
return llGetRootRotation(); return llGetRootRotation();
} }
m_host.AddScriptLPS(1); m_host.AddScriptLPS(1);
Quaternion q = m_host.GetWorldRotation(); Quaternion q = m_host.GetWorldRotation();
return new LSL_Rotation(q.X, q.Y, q.Z, q.W); return new LSL_Rotation(q.X, q.Y, q.Z, q.W);

View File

@ -2186,9 +2186,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
if (npcModule != null) if (npcModule != null)
{ {
UUID npcId = new UUID(npc.m_string); UUID npcId;
if (!UUID.TryParse(npc.m_string, out npcId))
if (!npcModule.IsNPC(npcId, m_host.ParentGroup.Scene))
return; return;
string appearanceSerialized = LoadNotecard(notecardNameOrUuid); string appearanceSerialized = LoadNotecard(notecardNameOrUuid);
@ -2210,8 +2209,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
INPCModule module = World.RequestModuleInterface<INPCModule>(); INPCModule module = World.RequestModuleInterface<INPCModule>();
if (module != null) if (module != null)
{ {
UUID npcId;
if (!UUID.TryParse(npc.m_string, out npcId))
return;
Vector3 pos = new Vector3((float) position.x, (float) position.y, (float) position.z); Vector3 pos = new Vector3((float) position.x, (float) position.y, (float) position.z);
module.MoveToTarget(new UUID(npc.m_string), World, pos, false, true); module.MoveToTarget(npcId, World, pos, false, true);
} }
} }
@ -2222,6 +2225,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
INPCModule module = World.RequestModuleInterface<INPCModule>(); INPCModule module = World.RequestModuleInterface<INPCModule>();
if (module != null) if (module != null)
{ {
UUID npcId;
if (!UUID.TryParse(npc.m_string, out npcId))
return;
Vector3 pos = new Vector3((float)position.x, (float)position.y, (float)position.z); Vector3 pos = new Vector3((float)position.x, (float)position.y, (float)position.z);
module.MoveToTarget( module.MoveToTarget(
new UUID(npc.m_string), new UUID(npc.m_string),
@ -2232,6 +2239,48 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
} }
} }
public LSL_Rotation osNpcGetRot(LSL_Key npc)
{
CheckThreatLevel(ThreatLevel.High, "osNpcGetRot");
INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
if (npcModule != null)
{
UUID npcId;
if (!UUID.TryParse(npc.m_string, out npcId))
return new LSL_Rotation(Quaternion.Identity.X, Quaternion.Identity.Y, Quaternion.Identity.Z, Quaternion.Identity.W);
if (!npcModule.IsNPC(npcId, m_host.ParentGroup.Scene))
return new LSL_Rotation(Quaternion.Identity.X, Quaternion.Identity.Y, Quaternion.Identity.Z, Quaternion.Identity.W);
ScenePresence sp = World.GetScenePresence(npcId);
Quaternion rot = sp.Rotation;
return new LSL_Rotation(rot.X, rot.Y, rot.Z, rot.W);
}
return new LSL_Rotation(Quaternion.Identity.X, Quaternion.Identity.Y, Quaternion.Identity.Z, Quaternion.Identity.W);
}
public void osNpcSetRot(LSL_Key npc, LSL_Rotation rotation)
{
CheckThreatLevel(ThreatLevel.High, "osNpcSetRot");
INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
if (npcModule != null)
{
UUID npcId;
if (!UUID.TryParse(npc.m_string, out npcId))
return;
if (!npcModule.IsNPC(npcId, m_host.ParentGroup.Scene))
return;
ScenePresence sp = World.GetScenePresence(npcId);
sp.Rotation = LSL_Api.Rot2Quaternion(rotation);
}
}
public void osNpcStopMoveTo(LSL_Key npc) public void osNpcStopMoveTo(LSL_Key npc)
{ {
CheckThreatLevel(ThreatLevel.VeryLow, "osNpcStopMoveTo"); CheckThreatLevel(ThreatLevel.VeryLow, "osNpcStopMoveTo");

View File

@ -173,6 +173,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
void osNpcLoadAppearance(key npc, string notecardNameOrUuid); void osNpcLoadAppearance(key npc, string notecardNameOrUuid);
void osNpcMoveTo(key npc, vector position); void osNpcMoveTo(key npc, vector position);
void osNpcMoveToTarget(key npc, vector position, int options); void osNpcMoveToTarget(key npc, vector position, int options);
rotation osNpcGetRot(key npc);
void osNpcSetRot(LSL_Key npc, rotation rot);
void osNpcStopMoveTo(LSL_Key npc); void osNpcStopMoveTo(LSL_Key npc);
void osNpcSay(key npc, string message); void osNpcSay(key npc, string message);
void osNpcRemove(key npc); void osNpcRemove(key npc);

View File

@ -503,6 +503,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
m_OSSL_Functions.osNpcMoveToTarget(npc, position, options); m_OSSL_Functions.osNpcMoveToTarget(npc, position, options);
} }
public rotation osNpcGetRot(key npc)
{
return m_OSSL_Functions.osNpcGetRot(npc);
}
public void osNpcSetRot(key npc, rotation rot)
{
m_OSSL_Functions.osNpcSetRot(npc, rot);
}
public void osNpcStopMoveTo(LSL_Key npc) public void osNpcStopMoveTo(LSL_Key npc)
{ {
m_OSSL_Functions.osNpcStopMoveTo(npc); m_OSSL_Functions.osNpcStopMoveTo(npc);