diff options
-rw-r--r-- | OpenSim/Region/Framework/Scenes/ScenePresence.cs | 108 | ||||
-rw-r--r-- | OpenSim/Region/Physics/UbitOdePlugin/ODERayCastRequestManager.cs | 41 |
2 files changed, 88 insertions, 61 deletions
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index 4504e18..5d0baf3 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs | |||
@@ -227,8 +227,6 @@ namespace OpenSim.Region.Framework.Scenes | |||
227 | /// </summary> | 227 | /// </summary> |
228 | public bool LandAtTarget { get; private set; } | 228 | public bool LandAtTarget { get; private set; } |
229 | 229 | ||
230 | private bool m_followCamAuto; | ||
231 | |||
232 | private int m_movementUpdateCount; | 230 | private int m_movementUpdateCount; |
233 | private const int NumMovementsBetweenRayCast = 5; | 231 | private const int NumMovementsBetweenRayCast = 5; |
234 | 232 | ||
@@ -357,6 +355,9 @@ namespace OpenSim.Region.Framework.Scenes | |||
357 | /// </summary> | 355 | /// </summary> |
358 | protected Vector3 m_lastCameraPosition; | 356 | protected Vector3 m_lastCameraPosition; |
359 | 357 | ||
358 | private Vector4 m_lastCameraCollisionPlane = new Vector4(0f, 0f, 0f, 1); | ||
359 | private bool m_doingCamRayCast = false; | ||
360 | |||
360 | public Vector3 CameraPosition { get; set; } | 361 | public Vector3 CameraPosition { get; set; } |
361 | 362 | ||
362 | public Quaternion CameraRotation | 363 | public Quaternion CameraRotation |
@@ -1407,36 +1408,40 @@ namespace OpenSim.Region.Framework.Scenes | |||
1407 | /// <param name="collisionPoint"></param> | 1408 | /// <param name="collisionPoint"></param> |
1408 | /// <param name="localid"></param> | 1409 | /// <param name="localid"></param> |
1409 | /// <param name="distance"></param> | 1410 | /// <param name="distance"></param> |
1410 | public void RayCastCameraCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance, Vector3 pNormal) | 1411 | /// |
1412 | |||
1413 | private void UpdateCameraCollisionPlane(Vector4 plane) | ||
1411 | { | 1414 | { |
1412 | const float POSITION_TOLERANCE = 0.02f; | 1415 | if (m_lastCameraCollisionPlane != plane) |
1413 | const float VELOCITY_TOLERANCE = 0.02f; | 1416 | { |
1414 | const float ROTATION_TOLERANCE = 0.02f; | 1417 | m_lastCameraCollisionPlane = plane; |
1418 | ControllingClient.SendCameraConstraint(plane); | ||
1419 | } | ||
1420 | } | ||
1415 | 1421 | ||
1416 | if (m_followCamAuto) | 1422 | public void RayCastCameraCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance, Vector3 pNormal) |
1423 | { | ||
1424 | m_doingCamRayCast = false; | ||
1425 | if (hitYN && localid != LocalId) | ||
1417 | { | 1426 | { |
1418 | if (hitYN && localid != LocalId) | 1427 | CameraConstraintActive = true; |
1419 | { | 1428 | pNormal.X = (float)Math.Round(pNormal.X, 2); |
1429 | pNormal.Y = (float)Math.Round(pNormal.Y, 2); | ||
1430 | pNormal.Z = (float)Math.Round(pNormal.Z, 2); | ||
1431 | pNormal.Normalize(); | ||
1432 | collisionPoint.X = (float)Math.Round(collisionPoint.X, 1); | ||
1433 | collisionPoint.Y = (float)Math.Round(collisionPoint.Y, 1); | ||
1434 | collisionPoint.Z = (float)Math.Round(collisionPoint.Z, 1); | ||
1435 | |||
1436 | Vector4 plane = new Vector4(pNormal.X, pNormal.Y, pNormal.Z, Vector3.Dot(collisionPoint, pNormal)); | ||
1437 | UpdateCameraCollisionPlane(plane); | ||
1438 | } | ||
1439 | else | ||
1440 | { | ||
1441 | Vector4 plane = new Vector4(0.9f, 0.0f, 0.361f, -9000f); // not right... | ||
1442 | UpdateCameraCollisionPlane(plane); | ||
1420 | 1443 | ||
1421 | CameraConstraintActive = true; | 1444 | CameraConstraintActive = false; |
1422 | //m_log.DebugFormat("[RAYCASTRESULT]: {0}, {1}, {2}, {3}", hitYN, collisionPoint, localid, distance); | ||
1423 | |||
1424 | Vector3 normal = Vector3.Normalize(new Vector3(0f, 0f, collisionPoint.Z) - collisionPoint); | ||
1425 | ControllingClient.SendCameraConstraint(new Vector4(normal.X, normal.Y, normal.Z, -1 * Vector3.Distance(new Vector3(0,0,collisionPoint.Z),collisionPoint))); | ||
1426 | } | ||
1427 | else | ||
1428 | { | ||
1429 | if (!m_pos.ApproxEquals(m_lastPosition, POSITION_TOLERANCE) || | ||
1430 | !Velocity.ApproxEquals(m_lastVelocity, VELOCITY_TOLERANCE) || | ||
1431 | !Rotation.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE)) | ||
1432 | { | ||
1433 | if (CameraConstraintActive) | ||
1434 | { | ||
1435 | ControllingClient.SendCameraConstraint(new Vector4(0f, 0.5f, 0.9f, -3000f)); | ||
1436 | CameraConstraintActive = false; | ||
1437 | } | ||
1438 | } | ||
1439 | } | ||
1440 | } | 1445 | } |
1441 | } | 1446 | } |
1442 | 1447 | ||
@@ -1511,12 +1516,6 @@ namespace OpenSim.Region.Framework.Scenes | |||
1511 | // DrawDistance = agentData.Far; | 1516 | // DrawDistance = agentData.Far; |
1512 | DrawDistance = Scene.DefaultDrawDistance; | 1517 | DrawDistance = Scene.DefaultDrawDistance; |
1513 | 1518 | ||
1514 | // Check if Client has camera in 'follow cam' or 'build' mode. | ||
1515 | Vector3 camdif = (Vector3.One * Rotation - Vector3.One * CameraRotation); | ||
1516 | |||
1517 | m_followCamAuto = ((CameraUpAxis.Z > 0.959f && CameraUpAxis.Z < 0.98f) | ||
1518 | && (Math.Abs(camdif.X) < 0.4f && Math.Abs(camdif.Y) < 0.4f)) ? true : false; | ||
1519 | |||
1520 | m_mouseLook = (flags & AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0; | 1519 | m_mouseLook = (flags & AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0; |
1521 | m_leftButtonDown = (flags & AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_DOWN) != 0; | 1520 | m_leftButtonDown = (flags & AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_DOWN) != 0; |
1522 | 1521 | ||
@@ -1536,26 +1535,37 @@ namespace OpenSim.Region.Framework.Scenes | |||
1536 | StandUp(); | 1535 | StandUp(); |
1537 | } | 1536 | } |
1538 | 1537 | ||
1539 | //m_log.DebugFormat("[FollowCam]: {0}", m_followCamAuto); | ||
1540 | // Raycast from the avatar's head to the camera to see if there's anything blocking the view | 1538 | // Raycast from the avatar's head to the camera to see if there's anything blocking the view |
1541 | if ((m_movementUpdateCount % NumMovementsBetweenRayCast) == 0 && m_scene.PhysicsScene.SupportsRayCast()) | 1539 | // this exclude checks may not be complete |
1540 | |||
1541 | if (!m_doingCamRayCast && !m_mouseLook && m_scene.PhysicsScene.SupportsRayCast() && ParentID == 0) | ||
1542 | { | 1542 | { |
1543 | if (m_followCamAuto) | 1543 | Vector3 posAdjusted = AbsolutePosition; |
1544 | posAdjusted.Z += 0.5f * Appearance.AvatarSize.Z - 0.5f; | ||
1545 | |||
1546 | Vector3 tocam = CameraPosition - posAdjusted; | ||
1547 | tocam.X = (float)Math.Round(tocam.X, 1); | ||
1548 | tocam.Y = (float)Math.Round(tocam.Y, 1); | ||
1549 | tocam.Z = (float)Math.Round(tocam.Z, 1); | ||
1550 | |||
1551 | float distTocamlen = tocam.Length(); | ||
1552 | if (distTocamlen > 0.3f) | ||
1544 | { | 1553 | { |
1545 | // Vector3 posAdjusted = m_pos + HEAD_ADJUSTMENT; | 1554 | tocam *= (1.0f / distTocamlen); |
1546 | // m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(CameraPosition - posAdjusted), Vector3.Distance(CameraPosition, posAdjusted) + 0.3f, RayCastCameraCallback); | 1555 | posAdjusted.X = (float)Math.Round(posAdjusted.X, 1); |
1547 | 1556 | posAdjusted.Y = (float)Math.Round(posAdjusted.Y, 1); | |
1548 | Vector3 posAdjusted = AbsolutePosition + HEAD_ADJUSTMENT; | 1557 | posAdjusted.Z = (float)Math.Round(posAdjusted.Z, 1); |
1549 | Vector3 distTocam = CameraPosition - posAdjusted; | 1558 | |
1550 | float distTocamlen = distTocam.Length(); | 1559 | m_doingCamRayCast = true; |
1551 | if (distTocamlen > 0) | 1560 | m_scene.PhysicsScene.RaycastWorld(posAdjusted, tocam, distTocamlen + 1.0f, RayCastCameraCallback); |
1552 | { | ||
1553 | distTocam *= 1.0f / distTocamlen; | ||
1554 | m_scene.PhysicsScene.RaycastWorld(posAdjusted, distTocam, distTocamlen + 0.3f, RayCastCameraCallback); | ||
1555 | } | ||
1556 | |||
1557 | } | 1561 | } |
1558 | } | 1562 | } |
1563 | else if (CameraConstraintActive && (m_mouseLook || ParentID != 0) ) | ||
1564 | { | ||
1565 | Vector4 plane = new Vector4(0.9f, 0.0f, 0.361f, -10000f); // not right... | ||
1566 | UpdateCameraCollisionPlane(plane); | ||
1567 | CameraConstraintActive = false; | ||
1568 | } | ||
1559 | 1569 | ||
1560 | uint flagsForScripts = (uint)flags; | 1570 | uint flagsForScripts = (uint)flags; |
1561 | flags = RemoveIgnoredControls(flags, IgnoredControls); | 1571 | flags = RemoveIgnoredControls(flags, IgnoredControls); |
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/ODERayCastRequestManager.cs b/OpenSim/Region/Physics/UbitOdePlugin/ODERayCastRequestManager.cs index 6e9281b..7fe3109 100644 --- a/OpenSim/Region/Physics/UbitOdePlugin/ODERayCastRequestManager.cs +++ b/OpenSim/Region/Physics/UbitOdePlugin/ODERayCastRequestManager.cs | |||
@@ -173,8 +173,13 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
173 | d.GeomRaySetClosestHit(ray, closestHit); | 173 | d.GeomRaySetClosestHit(ray, closestHit); |
174 | 174 | ||
175 | if (req.callbackMethod is RaycastCallback) | 175 | if (req.callbackMethod is RaycastCallback) |
176 | { | ||
176 | // if we only want one get only one per Collision pair saving memory | 177 | // if we only want one get only one per Collision pair saving memory |
177 | CurrentRayFilter |= RayFilterFlags.ClosestHit; | 178 | CurrentRayFilter |= RayFilterFlags.ClosestHit; |
179 | d.GeomRaySetClosestHit(ray, 1); | ||
180 | } | ||
181 | else | ||
182 | d.GeomRaySetClosestHit(ray, closestHit); | ||
178 | } | 183 | } |
179 | 184 | ||
180 | if ((CurrentRayFilter & RayFilterFlags.ContactsUnImportant) != 0) | 185 | if ((CurrentRayFilter & RayFilterFlags.ContactsUnImportant) != 0) |
@@ -555,10 +560,13 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
555 | 560 | ||
556 | ContactResult collisionresult = new ContactResult(); | 561 | ContactResult collisionresult = new ContactResult(); |
557 | collisionresult.ConsumerID = ID; | 562 | collisionresult.ConsumerID = ID; |
558 | collisionresult.Pos = new Vector3(curcontact.pos.X, curcontact.pos.Y, curcontact.pos.Z); | 563 | collisionresult.Pos.X = curcontact.pos.X; |
564 | collisionresult.Pos.Y = curcontact.pos.Y; | ||
565 | collisionresult.Pos.Z = curcontact.pos.Z; | ||
559 | collisionresult.Depth = curcontact.depth; | 566 | collisionresult.Depth = curcontact.depth; |
560 | collisionresult.Normal = new Vector3(curcontact.normal.X, curcontact.normal.Y, | 567 | collisionresult.Normal.X = curcontact.normal.X; |
561 | curcontact.normal.Z); | 568 | collisionresult.Normal.Y = curcontact.normal.Y; |
569 | collisionresult.Normal.Z = curcontact.normal.Z; | ||
562 | lock (m_contactResults) | 570 | lock (m_contactResults) |
563 | { | 571 | { |
564 | m_contactResults.Add(collisionresult); | 572 | m_contactResults.Add(collisionresult); |
@@ -581,10 +589,13 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
581 | 589 | ||
582 | if (curcontact.depth < collisionresult.Depth) | 590 | if (curcontact.depth < collisionresult.Depth) |
583 | { | 591 | { |
584 | collisionresult.Pos = new Vector3(curcontact.pos.X, curcontact.pos.Y, curcontact.pos.Z); | 592 | collisionresult.Pos.X = curcontact.pos.X; |
593 | collisionresult.Pos.Y = curcontact.pos.Y; | ||
594 | collisionresult.Pos.Z = curcontact.pos.Z; | ||
585 | collisionresult.Depth = curcontact.depth; | 595 | collisionresult.Depth = curcontact.depth; |
586 | collisionresult.Normal = new Vector3(curcontact.normal.X, curcontact.normal.Y, | 596 | collisionresult.Normal.X = curcontact.normal.X; |
587 | curcontact.normal.Z); | 597 | collisionresult.Normal.Y = curcontact.normal.Y; |
598 | collisionresult.Normal.Z = curcontact.normal.Z; | ||
588 | } | 599 | } |
589 | } | 600 | } |
590 | 601 | ||
@@ -699,10 +710,13 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
699 | 710 | ||
700 | ContactResult collisionresult = new ContactResult(); | 711 | ContactResult collisionresult = new ContactResult(); |
701 | collisionresult.ConsumerID = ID; | 712 | collisionresult.ConsumerID = ID; |
702 | collisionresult.Pos = new Vector3(curcontact.pos.X, curcontact.pos.Y, curcontact.pos.Z); | 713 | collisionresult.Pos.X = curcontact.pos.X; |
714 | collisionresult.Pos.Y = curcontact.pos.Y; | ||
715 | collisionresult.Pos.Z = curcontact.pos.Z; | ||
703 | collisionresult.Depth = curcontact.depth; | 716 | collisionresult.Depth = curcontact.depth; |
704 | collisionresult.Normal = new Vector3(curcontact.normal.X, curcontact.normal.Y, | 717 | collisionresult.Normal.X = curcontact.normal.X; |
705 | curcontact.normal.Z); | 718 | collisionresult.Normal.Y = curcontact.normal.Y; |
719 | collisionresult.Normal.Z = curcontact.normal.Z; | ||
706 | lock (m_contactResults) | 720 | lock (m_contactResults) |
707 | { | 721 | { |
708 | m_contactResults.Add(collisionresult); | 722 | m_contactResults.Add(collisionresult); |
@@ -725,10 +739,13 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
725 | 739 | ||
726 | if (curcontact.depth < collisionresult.Depth) | 740 | if (curcontact.depth < collisionresult.Depth) |
727 | { | 741 | { |
728 | collisionresult.Pos = new Vector3(curcontact.pos.X, curcontact.pos.Y, curcontact.pos.Z); | 742 | collisionresult.Pos.X = curcontact.pos.X; |
743 | collisionresult.Pos.Y = curcontact.pos.Y; | ||
744 | collisionresult.Pos.Z = curcontact.pos.Z; | ||
729 | collisionresult.Depth = curcontact.depth; | 745 | collisionresult.Depth = curcontact.depth; |
730 | collisionresult.Normal = new Vector3(curcontact.normal.X, curcontact.normal.Y, | 746 | collisionresult.Normal.X = curcontact.normal.X; |
731 | curcontact.normal.Z); | 747 | collisionresult.Normal.Y = curcontact.normal.Y; |
748 | collisionresult.Normal.Z = curcontact.normal.Z; | ||
732 | } | 749 | } |
733 | } | 750 | } |
734 | 751 | ||