Port implementation of llCastRay() from Aurora.

I haven't been able to test this since the viewer won't parse the llCastRay() function.  Maybe some activation cap is missing.  Could wait until it is activated by default in the viewer.
This commit is contained in:
Justin Clark-Casey (justincc)
2011-07-12 22:13:15 +01:00
parent d31e0a67f7
commit 3e456163dd
6 changed files with 299 additions and 34 deletions

View File

@@ -10309,51 +10309,191 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
return rq.ToString();
}
public LSL_List llCastRay(LSL_Vector start, LSL_Vector end, LSL_List options)
{
m_host.AddScriptLPS(1);
Vector3 dir = new Vector3((float)(end-start).x, (float)(end-start).y, (float)(end-start).z);
Vector3 startvector = new Vector3((float)start.x, (float)start.y, (float)start.z);
Vector3 endvector = new Vector3((float)end.x, (float)end.y, (float)end.z);
int count = 0;
// int detectPhantom = 0;
int dataFlags = 0;
int rejectTypes = 0;
for (int i = 0; i < options.Length; i += 2)
{
if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_MAX_HITS)
{
count = options.GetLSLIntegerItem(i + 1);
}
// else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DETECT_PHANTOM)
// {
// detectPhantom = options.GetLSLIntegerItem(i + 1);
// }
else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DATA_FLAGS)
{
dataFlags = options.GetLSLIntegerItem(i + 1);
}
else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_REJECT_TYPES)
{
rejectTypes = options.GetLSLIntegerItem(i + 1);
}
}
LSL_List list = new LSL_List();
List<ContactResult> results = World.PhysicsScene.RaycastWorld(startvector, dir, dir.Length(), count);
double distance = Util.GetDistanceTo(startvector, endvector);
if (distance == 0)
distance = 0.001;
Vector3 posToCheck = startvector;
ITerrainChannel channel = World.RequestModuleInterface<ITerrainChannel>();
bool checkTerrain = !((rejectTypes & ScriptBaseClass.RC_REJECT_LAND) == ScriptBaseClass.RC_REJECT_LAND);
bool checkAgents = !((rejectTypes & ScriptBaseClass.RC_REJECT_AGENTS) == ScriptBaseClass.RC_REJECT_AGENTS);
bool checkNonPhysical = !((rejectTypes & ScriptBaseClass.RC_REJECT_NONPHYSICAL) == ScriptBaseClass.RC_REJECT_NONPHYSICAL);
bool checkPhysical = !((rejectTypes & ScriptBaseClass.RC_REJECT_PHYSICAL) == ScriptBaseClass.RC_REJECT_PHYSICAL);
for (float i = 0; i <= distance; i += 0.1f)
{
posToCheck = startvector + (dir * (i / (float)distance));
if (checkTerrain && channel[(int)(posToCheck.X + startvector.X), (int)(posToCheck.Y + startvector.Y)] < posToCheck.Z)
{
ContactResult result = new ContactResult();
result.ConsumerID = 0;
result.Depth = 0;
result.Normal = Vector3.Zero;
result.Pos = posToCheck;
results.Add(result);
checkTerrain = false;
}
if (checkAgents)
{
World.ForEachScenePresence(delegate(ScenePresence sp)
{
if (sp.AbsolutePosition.ApproxEquals(posToCheck, sp.PhysicsActor.Size.X))
{
ContactResult result = new ContactResult ();
result.ConsumerID = sp.LocalId;
result.Depth = 0;
result.Normal = Vector3.Zero;
result.Pos = posToCheck;
results.Add(result);
}
});
}
}
int refcount = 0;
foreach (ContactResult result in results)
{
if ((rejectTypes & ScriptBaseClass.RC_REJECT_LAND)
== ScriptBaseClass.RC_REJECT_LAND && result.ConsumerID == 0)
continue;
ISceneEntity entity = World.GetSceneObjectPart(result.ConsumerID);
if (entity == null && (rejectTypes & ScriptBaseClass.RC_REJECT_AGENTS) != ScriptBaseClass.RC_REJECT_AGENTS)
entity = World.GetScenePresence(result.ConsumerID); //Only check if we should be looking for agents
if (entity == null)
{
list.Add(UUID.Zero);
if ((dataFlags & ScriptBaseClass.RC_GET_LINK_NUM) == ScriptBaseClass.RC_GET_LINK_NUM)
list.Add(0);
list.Add(result.Pos);
if ((dataFlags & ScriptBaseClass.RC_GET_NORMAL) == ScriptBaseClass.RC_GET_NORMAL)
list.Add(result.Normal);
continue; //Can't find it, so add UUID.Zero
}
/*if (detectPhantom == 0 && intersection.obj is ISceneChildEntity &&
((ISceneChildEntity)intersection.obj).PhysActor == null)
continue;*/ //Can't do this ATM, physics engine knows only of non phantom objects
if (entity is SceneObjectPart)
{
if (((SceneObjectPart)entity).PhysActor != null && ((SceneObjectPart)entity).PhysActor.IsPhysical)
{
if (!checkPhysical)
continue;
}
else
{
if (!checkNonPhysical)
continue;
}
}
refcount++;
if ((dataFlags & ScriptBaseClass.RC_GET_ROOT_KEY) == ScriptBaseClass.RC_GET_ROOT_KEY && entity is SceneObjectPart)
list.Add(((SceneObjectPart)entity).ParentGroup.UUID);
else
list.Add(entity.UUID);
if ((dataFlags & ScriptBaseClass.RC_GET_LINK_NUM) == ScriptBaseClass.RC_GET_LINK_NUM)
{
if (entity is SceneObjectPart)
list.Add(((SceneObjectPart)entity).LinkNum);
else
list.Add(0);
}
list.Add(result.Pos);
if ((dataFlags & ScriptBaseClass.RC_GET_NORMAL) == ScriptBaseClass.RC_GET_NORMAL)
list.Add(result.Normal);
}
list.Add(refcount); //The status code, either the # of contacts, RCERR_SIM_PERF_LOW, or RCERR_CAST_TIME_EXCEEDED
return list;
}
#region Not Implemented
//
// Listing the unimplemented lsl functions here, please move
// them from this region as they are completed
//
public void llCastRay(LSL_Vector start, LSL_Vector end, LSL_List options)
{
m_host.AddScriptLPS(1);
NotImplemented("llCastRay");
}
public void llGetEnv(LSL_String name)
{
m_host.AddScriptLPS(1);
NotImplemented("llGetEnv");
}
public void llGetSPMaxMemory()
{
m_host.AddScriptLPS(1);
NotImplemented("llGetSPMaxMemory");
}
public void llGetUsedMemory()
{
m_host.AddScriptLPS(1);
NotImplemented("llGetUsedMemory");
}
public void llRegionSayTo( LSL_Key target, LSL_Integer channel, LSL_String msg )
public void llRegionSayTo(LSL_Key target, LSL_Integer channel, LSL_String msg)
{
m_host.AddScriptLPS(1);
NotImplemented("llRegionSayTo");
}
public void llScriptProfiler( LSL_Integer flags )
public void llScriptProfiler(LSL_Integer flags)
{
m_host.AddScriptLPS(1);
NotImplemented("llScriptProfiler");
}
public void llSetSoundQueueing(int queue)