diff options
Diffstat (limited to 'OpenSim/Region/Framework')
-rw-r--r-- | OpenSim/Region/Framework/Scenes/ScenePresence.cs | 106 |
1 files changed, 61 insertions, 45 deletions
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index b6407d2..be3a39a 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs | |||
@@ -225,8 +225,6 @@ namespace OpenSim.Region.Framework.Scenes | |||
225 | /// </summary> | 225 | /// </summary> |
226 | public bool LandAtTarget { get; private set; } | 226 | public bool LandAtTarget { get; private set; } |
227 | 227 | ||
228 | private bool m_followCamAuto; | ||
229 | |||
230 | private int m_movementUpdateCount; | 228 | private int m_movementUpdateCount; |
231 | private const int NumMovementsBetweenRayCast = 5; | 229 | private const int NumMovementsBetweenRayCast = 5; |
232 | 230 | ||
@@ -355,6 +353,9 @@ namespace OpenSim.Region.Framework.Scenes | |||
355 | /// </summary> | 353 | /// </summary> |
356 | protected Vector3 m_lastCameraPosition; | 354 | protected Vector3 m_lastCameraPosition; |
357 | 355 | ||
356 | private Vector4 m_lastCameraCollisionPlane = new Vector4(0f, 0f, 0f, 1); | ||
357 | private bool m_doingCamRayCast = false; | ||
358 | |||
358 | public Vector3 CameraPosition { get; set; } | 359 | public Vector3 CameraPosition { get; set; } |
359 | 360 | ||
360 | public Quaternion CameraRotation | 361 | public Quaternion CameraRotation |
@@ -1405,36 +1406,43 @@ namespace OpenSim.Region.Framework.Scenes | |||
1405 | /// <param name="collisionPoint"></param> | 1406 | /// <param name="collisionPoint"></param> |
1406 | /// <param name="localid"></param> | 1407 | /// <param name="localid"></param> |
1407 | /// <param name="distance"></param> | 1408 | /// <param name="distance"></param> |
1409 | /// | ||
1410 | |||
1411 | private void UpdateCameraCollisionPlane(Vector4 plane) | ||
1412 | { | ||
1413 | if (m_lastCameraCollisionPlane != plane) | ||
1414 | { | ||
1415 | m_lastCameraCollisionPlane = plane; | ||
1416 | ControllingClient.SendCameraConstraint(plane); | ||
1417 | } | ||
1418 | } | ||
1419 | |||
1408 | public void RayCastCameraCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance, Vector3 pNormal) | 1420 | public void RayCastCameraCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance, Vector3 pNormal) |
1409 | { | 1421 | { |
1410 | const float POSITION_TOLERANCE = 0.02f; | 1422 | const float POSITION_TOLERANCE = 0.02f; |
1411 | const float VELOCITY_TOLERANCE = 0.02f; | ||
1412 | const float ROTATION_TOLERANCE = 0.02f; | 1423 | const float ROTATION_TOLERANCE = 0.02f; |
1413 | 1424 | ||
1414 | if (m_followCamAuto) | 1425 | m_doingCamRayCast = false; |
1426 | if (hitYN && localid != LocalId) | ||
1415 | { | 1427 | { |
1416 | if (hitYN && localid != LocalId) | 1428 | CameraConstraintActive = true; |
1417 | { | 1429 | pNormal.X = (float)Math.Round(pNormal.X, 2); |
1418 | 1430 | pNormal.Y = (float)Math.Round(pNormal.Y, 2); | |
1419 | CameraConstraintActive = true; | 1431 | pNormal.Z = (float)Math.Round(pNormal.Z, 2); |
1420 | //m_log.DebugFormat("[RAYCASTRESULT]: {0}, {1}, {2}, {3}", hitYN, collisionPoint, localid, distance); | 1432 | pNormal.Normalize(); |
1421 | 1433 | collisionPoint.X = (float)Math.Round(collisionPoint.X, 1); | |
1422 | Vector3 normal = Vector3.Normalize(new Vector3(0f, 0f, collisionPoint.Z) - collisionPoint); | 1434 | collisionPoint.Y = (float)Math.Round(collisionPoint.Y, 1); |
1423 | ControllingClient.SendCameraConstraint(new Vector4(normal.X, normal.Y, normal.Z, -1 * Vector3.Distance(new Vector3(0,0,collisionPoint.Z),collisionPoint))); | 1435 | collisionPoint.Z = (float)Math.Round(collisionPoint.Z, 1); |
1424 | } | 1436 | |
1425 | else | 1437 | Vector4 plane = new Vector4(pNormal.X, pNormal.Y, pNormal.Z, Vector3.Dot(collisionPoint, pNormal)); |
1426 | { | 1438 | UpdateCameraCollisionPlane(plane); |
1427 | if (!m_pos.ApproxEquals(m_lastPosition, POSITION_TOLERANCE) || | 1439 | } |
1428 | !Velocity.ApproxEquals(m_lastVelocity, VELOCITY_TOLERANCE) || | 1440 | else if (!m_pos.ApproxEquals(m_lastPosition, POSITION_TOLERANCE) || |
1429 | !Rotation.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE)) | 1441 | !Rotation.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE)) |
1430 | { | 1442 | { |
1431 | if (CameraConstraintActive) | 1443 | Vector4 plane = new Vector4(0.9f, 0.0f, 0.361f, -9000f); // not right... |
1432 | { | 1444 | UpdateCameraCollisionPlane(plane); |
1433 | ControllingClient.SendCameraConstraint(new Vector4(0f, 0.5f, 0.9f, -3000f)); | 1445 | CameraConstraintActive = false; |
1434 | CameraConstraintActive = false; | ||
1435 | } | ||
1436 | } | ||
1437 | } | ||
1438 | } | 1446 | } |
1439 | } | 1447 | } |
1440 | 1448 | ||
@@ -1509,12 +1517,6 @@ namespace OpenSim.Region.Framework.Scenes | |||
1509 | // DrawDistance = agentData.Far; | 1517 | // DrawDistance = agentData.Far; |
1510 | DrawDistance = Scene.DefaultDrawDistance; | 1518 | DrawDistance = Scene.DefaultDrawDistance; |
1511 | 1519 | ||
1512 | // Check if Client has camera in 'follow cam' or 'build' mode. | ||
1513 | Vector3 camdif = (Vector3.One * Rotation - Vector3.One * CameraRotation); | ||
1514 | |||
1515 | m_followCamAuto = ((CameraUpAxis.Z > 0.959f && CameraUpAxis.Z < 0.98f) | ||
1516 | && (Math.Abs(camdif.X) < 0.4f && Math.Abs(camdif.Y) < 0.4f)) ? true : false; | ||
1517 | |||
1518 | m_mouseLook = (flags & AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0; | 1520 | m_mouseLook = (flags & AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0; |
1519 | m_leftButtonDown = (flags & AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_DOWN) != 0; | 1521 | m_leftButtonDown = (flags & AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_DOWN) != 0; |
1520 | 1522 | ||
@@ -1534,24 +1536,38 @@ namespace OpenSim.Region.Framework.Scenes | |||
1534 | StandUp(); | 1536 | StandUp(); |
1535 | } | 1537 | } |
1536 | 1538 | ||
1537 | //m_log.DebugFormat("[FollowCam]: {0}", m_followCamAuto); | ||
1538 | // Raycast from the avatar's head to the camera to see if there's anything blocking the view | 1539 | // Raycast from the avatar's head to the camera to see if there's anything blocking the view |
1539 | if ((m_movementUpdateCount % NumMovementsBetweenRayCast) == 0 && m_scene.PhysicsScene.SupportsRayCast()) | 1540 | // this exclude checks may not be complete |
1541 | |||
1542 | if (m_movementUpdateCount % NumMovementsBetweenRayCast == 0 && m_scene.PhysicsScene.SupportsRayCast()) | ||
1540 | { | 1543 | { |
1541 | if (m_followCamAuto) | 1544 | if (!m_doingCamRayCast && !m_mouseLook && ParentID == 0) |
1542 | { | 1545 | { |
1543 | // Vector3 posAdjusted = m_pos + HEAD_ADJUSTMENT; | 1546 | Vector3 posAdjusted = AbsolutePosition; |
1544 | // m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(CameraPosition - posAdjusted), Vector3.Distance(CameraPosition, posAdjusted) + 0.3f, RayCastCameraCallback); | 1547 | // posAdjusted.Z += 0.5f * Appearance.AvatarSize.Z - 0.5f; |
1545 | 1548 | posAdjusted.Z += 1.0f; // viewer current camera focus point | |
1546 | Vector3 posAdjusted = AbsolutePosition + HEAD_ADJUSTMENT; | 1549 | Vector3 tocam = CameraPosition - posAdjusted; |
1547 | Vector3 distTocam = CameraPosition - posAdjusted; | 1550 | tocam.X = (float)Math.Round(tocam.X, 1); |
1548 | float distTocamlen = distTocam.Length(); | 1551 | tocam.Y = (float)Math.Round(tocam.Y, 1); |
1549 | if (distTocamlen > 0) | 1552 | tocam.Z = (float)Math.Round(tocam.Z, 1); |
1553 | |||
1554 | float distTocamlen = tocam.Length(); | ||
1555 | if (distTocamlen > 0.3f) | ||
1550 | { | 1556 | { |
1551 | distTocam *= 1.0f / distTocamlen; | 1557 | tocam *= (1.0f / distTocamlen); |
1552 | m_scene.PhysicsScene.RaycastWorld(posAdjusted, distTocam, distTocamlen + 0.3f, RayCastCameraCallback); | 1558 | posAdjusted.X = (float)Math.Round(posAdjusted.X, 1); |
1559 | posAdjusted.Y = (float)Math.Round(posAdjusted.Y, 1); | ||
1560 | posAdjusted.Z = (float)Math.Round(posAdjusted.Z, 1); | ||
1561 | |||
1562 | m_doingCamRayCast = true; | ||
1563 | m_scene.PhysicsScene.RaycastWorld(posAdjusted, tocam, distTocamlen + 1.0f, RayCastCameraCallback); | ||
1553 | } | 1564 | } |
1554 | 1565 | } | |
1566 | else if (CameraConstraintActive && (m_mouseLook || ParentID != 0)) | ||
1567 | { | ||
1568 | Vector4 plane = new Vector4(0.9f, 0.0f, 0.361f, -10000f); // not right... | ||
1569 | UpdateCameraCollisionPlane(plane); | ||
1570 | CameraConstraintActive = false; | ||
1555 | } | 1571 | } |
1556 | } | 1572 | } |
1557 | 1573 | ||