diff options
author | UbitUmarov | 2015-09-24 06:57:53 +0100 |
---|---|---|
committer | UbitUmarov | 2015-09-24 06:57:53 +0100 |
commit | 58daecfccb026be20fb3b124dee2c25d266e13b4 (patch) | |
tree | 312d7411ada8c1742601a6f2c3d45aab671bc166 /OpenSim/Region/Framework/Scenes | |
parent | add physics assistance on placement of a new object. This may help on mantis... (diff) | |
download | opensim-SC_OLD-58daecfccb026be20fb3b124dee2c25d266e13b4.zip opensim-SC_OLD-58daecfccb026be20fb3b124dee2c25d266e13b4.tar.gz opensim-SC_OLD-58daecfccb026be20fb3b124dee2c25d266e13b4.tar.bz2 opensim-SC_OLD-58daecfccb026be20fb3b124dee2c25d266e13b4.tar.xz |
don't mess ray direction..
Diffstat (limited to 'OpenSim/Region/Framework/Scenes')
-rwxr-xr-x | OpenSim/Region/Framework/Scenes/Scene.cs | 152 |
1 files changed, 78 insertions, 74 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index fced0cc..111b74d 100755 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs | |||
@@ -2305,106 +2305,110 @@ namespace OpenSim.Region.Framework.Scenes | |||
2305 | Vector3 rayEnd = RayEnd; | 2305 | Vector3 rayEnd = RayEnd; |
2306 | 2306 | ||
2307 | Vector3 dir = rayEnd - RayStart; | 2307 | Vector3 dir = rayEnd - RayStart; |
2308 | float dist = Vector3.Mag(dir) + 2.0f; | 2308 | float dist = dir.Length(); |
2309 | 2309 | if (dist != 0) | |
2310 | Vector3 direction = dir * (1 / dist); | ||
2311 | |||
2312 | if (SupportsRayCastFiltered()) | ||
2313 | { | 2310 | { |
2314 | RayFilterFlags rayfilter = RayFilterFlags.BackFaceCull; | 2311 | Vector3 direction = dir * (1 / dist); |
2315 | rayfilter |= RayFilterFlags.land; | ||
2316 | rayfilter |= RayFilterFlags.physical; | ||
2317 | rayfilter |= RayFilterFlags.nonphysical; | ||
2318 | rayfilter |= RayFilterFlags.LSLPhantom; // ubODE will only see volume detectors | ||
2319 | 2312 | ||
2320 | // get some more contacts ??? | 2313 | dist += 2.0f; |
2321 | int physcount = 4; | ||
2322 | 2314 | ||
2323 | List<ContactResult> physresults = | 2315 | if (SupportsRayCastFiltered()) |
2324 | (List<ContactResult>)RayCastFiltered(RayStart, direction, dist, physcount, rayfilter); | ||
2325 | if (physresults != null && physresults.Count > 0) | ||
2326 | { | 2316 | { |
2327 | if (physresults[0].ConsumerID == 0 || RayTargetID == UUID.Zero) | 2317 | RayFilterFlags rayfilter = RayFilterFlags.BackFaceCull; |
2328 | { | 2318 | rayfilter |= RayFilterFlags.land; |
2329 | // found something | 2319 | rayfilter |= RayFilterFlags.physical; |
2330 | pos = physresults[0].Normal * scale ; | 2320 | rayfilter |= RayFilterFlags.nonphysical; |
2331 | pos *= 0.5f; | 2321 | rayfilter |= RayFilterFlags.LSLPhantom; // ubODE will only see volume detectors |
2332 | pos = physresults[0].Pos +pos; | 2322 | |
2333 | return pos; | 2323 | // get some more contacts ??? |
2334 | } | 2324 | int physcount = 4; |
2335 | foreach (ContactResult r in physresults) | 2325 | |
2326 | List<ContactResult> physresults = | ||
2327 | (List<ContactResult>)RayCastFiltered(RayStart, direction, dist, physcount, rayfilter); | ||
2328 | if (physresults != null && physresults.Count > 0) | ||
2336 | { | 2329 | { |
2337 | SceneObjectPart part = GetSceneObjectPart(r.ConsumerID); | 2330 | if (physresults[0].ConsumerID == 0 || RayTargetID == UUID.Zero) |
2338 | if (part == null) | ||
2339 | continue; | ||
2340 | if (part.UUID == RayTargetID) | ||
2341 | { | 2331 | { |
2332 | // found something | ||
2342 | pos = physresults[0].Normal * scale; | 2333 | pos = physresults[0].Normal * scale; |
2343 | pos *= 0.5f; | 2334 | pos *= 0.5f; |
2344 | pos = physresults[0].Pos + pos; | 2335 | pos = physresults[0].Pos + pos; |
2345 | return pos; | 2336 | return pos; |
2346 | } | 2337 | } |
2338 | foreach (ContactResult r in physresults) | ||
2339 | { | ||
2340 | SceneObjectPart part = GetSceneObjectPart(r.ConsumerID); | ||
2341 | if (part == null) | ||
2342 | continue; | ||
2343 | if (part.UUID == RayTargetID) | ||
2344 | { | ||
2345 | pos = physresults[0].Normal * scale; | ||
2346 | pos *= 0.5f; | ||
2347 | pos = physresults[0].Pos + pos; | ||
2348 | return pos; | ||
2349 | } | ||
2350 | } | ||
2347 | } | 2351 | } |
2348 | } | ||
2349 | } | ||
2350 | if (RayTargetID != UUID.Zero) | ||
2351 | { | ||
2352 | SceneObjectPart target = GetSceneObjectPart(RayTargetID); | ||
2353 | 2352 | ||
2354 | Ray NewRay = new Ray(RayStart, direction); | 2353 | } |
2355 | 2354 | if (RayTargetID != UUID.Zero) | |
2356 | if (target != null) | ||
2357 | { | 2355 | { |
2358 | pos = target.AbsolutePosition; | 2356 | SceneObjectPart target = GetSceneObjectPart(RayTargetID); |
2359 | 2357 | ||
2360 | // Ray Trace against target here | 2358 | Ray NewRay = new Ray(RayStart, direction); |
2361 | EntityIntersection ei = target.TestIntersectionOBB(NewRay, Quaternion.Identity, frontFacesOnly, FaceCenter); | ||
2362 | 2359 | ||
2363 | // Un-comment out the following line to Get Raytrace results printed to the console. | 2360 | if (target != null) |
2364 | // m_log.Info("[RAYTRACERESULTS]: Hit:" + ei.HitTF.ToString() + " Point: " + ei.ipoint.ToString() + " Normal: " + ei.normal.ToString()); | ||
2365 | float ScaleOffset = 0.5f; | ||
2366 | |||
2367 | // If we hit something | ||
2368 | if (ei.HitTF) | ||
2369 | { | 2361 | { |
2370 | Vector3 scaleComponent = ei.AAfaceNormal; | 2362 | pos = target.AbsolutePosition; |
2371 | if (scaleComponent.X != 0) ScaleOffset = scale.X; | ||
2372 | if (scaleComponent.Y != 0) ScaleOffset = scale.Y; | ||
2373 | if (scaleComponent.Z != 0) ScaleOffset = scale.Z; | ||
2374 | ScaleOffset = Math.Abs(ScaleOffset); | ||
2375 | Vector3 intersectionpoint = ei.ipoint; | ||
2376 | Vector3 normal = ei.normal; | ||
2377 | // Set the position to the intersection point | ||
2378 | Vector3 offset = (normal * (ScaleOffset / 2f)); | ||
2379 | pos = (intersectionpoint + offset); | ||
2380 | |||
2381 | //Seems to make no sense to do this as this call is used for rezzing from inventory as well, and with inventory items their size is not always 0.5f | ||
2382 | //And in cases when we weren't rezzing from inventory we were re-adding the 0.25 straight after calling this method | ||
2383 | // Un-offset the prim (it gets offset later by the consumer method) | ||
2384 | //pos.Z -= 0.25F; | ||
2385 | 2363 | ||
2386 | } | 2364 | // Ray Trace against target here |
2387 | } | 2365 | EntityIntersection ei = target.TestIntersectionOBB(NewRay, Quaternion.Identity, frontFacesOnly, FaceCenter); |
2388 | else | ||
2389 | { | ||
2390 | // We don't have a target here, so we're going to raytrace all the objects in the scene. | ||
2391 | EntityIntersection ei = m_sceneGraph.GetClosestIntersectingPrim(NewRay, true, false); | ||
2392 | 2366 | ||
2393 | // Un-comment the following line to print the raytrace results to the console. | 2367 | // Un-comment out the following line to Get Raytrace results printed to the console. |
2394 | //m_log.Info("[RAYTRACERESULTS]: Hit:" + ei.HitTF.ToString() + " Point: " + ei.ipoint.ToString() + " Normal: " + ei.normal.ToString()); | 2368 | // m_log.Info("[RAYTRACERESULTS]: Hit:" + ei.HitTF.ToString() + " Point: " + ei.ipoint.ToString() + " Normal: " + ei.normal.ToString()); |
2369 | float ScaleOffset = 0.5f; | ||
2395 | 2370 | ||
2396 | if (ei.HitTF) | 2371 | // If we hit something |
2397 | { | 2372 | if (ei.HitTF) |
2398 | pos = new Vector3(ei.ipoint.X, ei.ipoint.Y, ei.ipoint.Z); | 2373 | { |
2374 | Vector3 scaleComponent = ei.AAfaceNormal; | ||
2375 | if (scaleComponent.X != 0) ScaleOffset = scale.X; | ||
2376 | if (scaleComponent.Y != 0) ScaleOffset = scale.Y; | ||
2377 | if (scaleComponent.Z != 0) ScaleOffset = scale.Z; | ||
2378 | ScaleOffset = Math.Abs(ScaleOffset); | ||
2379 | Vector3 intersectionpoint = ei.ipoint; | ||
2380 | Vector3 normal = ei.normal; | ||
2381 | // Set the position to the intersection point | ||
2382 | Vector3 offset = (normal * (ScaleOffset / 2f)); | ||
2383 | pos = (intersectionpoint + offset); | ||
2384 | |||
2385 | //Seems to make no sense to do this as this call is used for rezzing from inventory as well, and with inventory items their size is not always 0.5f | ||
2386 | //And in cases when we weren't rezzing from inventory we were re-adding the 0.25 straight after calling this method | ||
2387 | // Un-offset the prim (it gets offset later by the consumer method) | ||
2388 | //pos.Z -= 0.25F; | ||
2389 | |||
2390 | } | ||
2399 | } | 2391 | } |
2400 | else | 2392 | else |
2401 | { | 2393 | { |
2402 | // fall back to our stupid functionality | 2394 | // We don't have a target here, so we're going to raytrace all the objects in the scene. |
2403 | pos = RayEnd; | 2395 | EntityIntersection ei = m_sceneGraph.GetClosestIntersectingPrim(NewRay, true, false); |
2396 | |||
2397 | // Un-comment the following line to print the raytrace results to the console. | ||
2398 | //m_log.Info("[RAYTRACERESULTS]: Hit:" + ei.HitTF.ToString() + " Point: " + ei.ipoint.ToString() + " Normal: " + ei.normal.ToString()); | ||
2399 | |||
2400 | if (ei.HitTF) | ||
2401 | { | ||
2402 | pos = new Vector3(ei.ipoint.X, ei.ipoint.Y, ei.ipoint.Z); | ||
2403 | } | ||
2404 | else | ||
2405 | { | ||
2406 | // fall back to our stupid functionality | ||
2407 | pos = RayEnd; | ||
2408 | } | ||
2404 | } | 2409 | } |
2405 | } | 2410 | } |
2406 | } | 2411 | } |
2407 | |||
2408 | else | 2412 | else |
2409 | { | 2413 | { |
2410 | // fall back to our stupid functionality | 2414 | // fall back to our stupid functionality |