mirror of
https://github.com/opensim/opensim.git
synced 2026-08-05 17:05:55 +08:00
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:
@@ -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)
|
||||
|
||||
@@ -60,6 +60,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
|
||||
LSL_String llBase64ToString(string str);
|
||||
void llBreakAllLinks();
|
||||
void llBreakLink(int linknum);
|
||||
LSL_List llCastRay(LSL_Vector start, LSL_Vector end, LSL_List options);
|
||||
LSL_Integer llCeil(double f);
|
||||
void llClearCameraParams();
|
||||
LSL_Integer llClearPrimMedia(LSL_Integer face);
|
||||
@@ -404,7 +405,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
|
||||
LSL_String llXorBase64StringsCorrect(string str1, string str2);
|
||||
void print(string str);
|
||||
|
||||
void SetPrimitiveParamsEx(LSL_Key prim, LSL_List rules);
|
||||
LSL_List GetLinkPrimitiveParamsEx(LSL_Key prim, LSL_List rules);
|
||||
void SetPrimitiveParamsEx(LSL_Key prim, LSL_List rules);
|
||||
LSL_List GetLinkPrimitiveParamsEx(LSL_Key prim, LSL_List rules);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -593,5 +593,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
|
||||
|
||||
public const string URL_REQUEST_GRANTED = "URL_REQUEST_GRANTED";
|
||||
public const string URL_REQUEST_DENIED = "URL_REQUEST_DENIED";
|
||||
|
||||
public static readonly LSLInteger RC_REJECT_TYPES = 2;
|
||||
public static readonly LSLInteger RC_DATA_FLAGS = 4;
|
||||
public static readonly LSLInteger RC_MAX_HITS = 8;
|
||||
public static readonly LSLInteger RC_DETECT_PHANTOM = 16;
|
||||
|
||||
public static readonly LSLInteger RC_REJECT_AGENTS = 2;
|
||||
public static readonly LSLInteger RC_REJECT_PHYSICAL = 4;
|
||||
public static readonly LSLInteger RC_REJECT_NONPHYSICAL = 8;
|
||||
public static readonly LSLInteger RC_REJECT_LAND = 16;
|
||||
|
||||
public static readonly LSLInteger RC_GET_NORMAL = 2;
|
||||
public static readonly LSLInteger RC_GET_ROOT_KEY = 4;
|
||||
public static readonly LSLInteger RC_GET_LINK_NUM = 8;
|
||||
|
||||
public static readonly LSLInteger RCERR_CAST_TIME_EXCEEDED = 1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user