// ========================================================================== /// <summary> /// Update the camera. The coordinate system from the EntityCamera is LL's /// (Z up). We have to convert the rotation and position to Ogre coords /// (Y up). /// </summary> /// <param name="cam"></param> // private bool haveAttachedCamera = false; public void UpdateCamera(CameraControl cam) { /* Historical Note: This is part of code to attach the camera to the avatar. When this was written * the avatar code was not in place so the actual scene node to attach the camera too is problematic. * Fix this when there is an avatar. if (!haveAttachedCamera && cam.AssociatedAgent != null && cam.AssociatedAgent.AssociatedAvatar != null) { m_log.Log(LogLevel.DVIEWDETAIL, "OnAgentUpdate: Attaching camera with {0}", cam.AssociatedAgent.AssociatedAvatar.Name); haveAttachedCamera = Ogr.AttachCamera(cam.AssociatedAgent.AssociatedAvatar.Name.Name, 1.0f, 0.0f, 1.0f, 0f, 0f, 0f, 1f); } */ // OMV.Quaternion orient = new OMV.Quaternion(OMV.Vector3.UnitX, -Constants.PI / 2) // * new OMV.Quaternion(OMV.Vector3.UnitZ, -Constants.PI / 2) // * cam.Direction; // we need to rotate the camera 90 to make it work out in Ogre. Not sure why. // OMV.Quaternion orient = cam.Heading * OMV.Quaternion.CreateFromAxisAngle(OMV.Vector3.UnitZ, -Constants.PI / 2); OMV.Quaternion orient = OMV.Quaternion.CreateFromAxisAngle(OMV.Vector3.UnitZ, -Constants.PI / 2) * cam.Heading; // OMV.Quaternion orient = cam.Heading; orient.Normalize(); m_lastCameraPosition = cam.GlobalPosition; m_lastCameraOrientation = orient; // note the conversion from LL coordinates (Z up) to Ogre coordinates (Y up) OMV.Vector3d pos = cam.GlobalPosition * m_sceneMagnification; Ogr.UpdateCameraBF(pos.X, pos.Z, -pos.Y, orient.W, orient.X, orient.Z, -orient.Y, 1.0f, (float)cam.Far*m_sceneMagnification, 1.0f); // m_log.Log(LogLevel.DRENDERDETAIL, "UpdateCamera: Camera to p={0}, r={1}", pos, orient); return; }
// called when the camera changes position or orientation private void CameraControl_OnCameraUpdate(CameraControl cam) { // m_log.Log(LogLevel.DVIEWDETAIL, "OnCameraUpdate: "); if (m_trackedAgent != null) { // tell the agent the camera moved if it cares // This is an outgoing message that tells the world where the camera is // pointing so the server can do interest management m_trackedAgent.UpdateCamera(cam.GlobalPosition, cam.Heading, cam.Far); } }
// tell the renderer about the camera position public void UpdateCamera(CameraControl cam) { return; }
public override bool AfterAllModulesLoaded() { m_log.Log(LogLevel.DINIT, "entered AfterAllModulesLoaded()"); Renderer = (IRenderProvider)ModuleManager.Instance.Module(ModuleParams.ParamString(m_moduleName + ".Renderer.Name")); if (Renderer == null) { m_log.Log(LogLevel.DBADERROR, "UNABLE TO FIND RENDERER!!!! "); return false; } m_cameraSpeed = ModuleParams.ParamFloat(m_moduleName + ".Camera.Speed"); m_cameraRotationSpeed = ModuleParams.ParamFloat(m_moduleName + ".Camera.RotationSpeed"); m_agentCameraBehind = ModuleParams.ParamFloat(m_moduleName + ".Camera.BehindAgent"); m_agentCameraAbove = ModuleParams.ParamFloat(m_moduleName + ".Camera.AboveAgent"); m_mainCamera = new CameraControl(); m_mainCamera.GlobalPosition = new OMV.Vector3d(1000d, 1000d, 40d); // World coordinates (Z up) // camera starts pointing down Y axis m_mainCamera.Heading = new OMV.Quaternion(OMV.Vector3.UnitZ, Constants.PI/2); m_mainCamera.Zoom = 1.0f; m_mainCamera.Far = ModuleParams.ParamFloat(m_moduleName + ".Camera.ServerFar"); m_cameraMode = CameraMode.TrackingAgent; m_cameraLookAt = new OMV.Vector3d(0d, 0d, 0d); // connect me to the world so I can know when things change in the world TheWorld.OnWorldRegionNew += new WorldRegionNewCallback(World_OnRegionNew); TheWorld.OnWorldRegionUpdated += new WorldRegionUpdatedCallback(World_OnRegionUpdated); TheWorld.OnWorldRegionRemoved += new WorldRegionRemovedCallback(World_OnRegionRemoved); TheWorld.OnWorldEntityNew += new WorldEntityNewCallback(World_OnEntityNew); TheWorld.OnWorldEntityUpdate += new WorldEntityUpdateCallback(World_OnEntityUpdate); TheWorld.OnWorldEntityRemoved += new WorldEntityRemovedCallback(World_OnEntityRemoved); TheWorld.OnAgentNew += new WorldAgentNewCallback(World_OnAgentNew); TheWorld.OnAgentUpdate += new WorldAgentUpdateCallback(World_OnAgentUpdate); TheWorld.OnAgentRemoved += new WorldAgentRemovedCallback(World_OnAgentRemoved); m_log.Log(LogLevel.DINIT, "exiting AfterAllModulesLoaded()"); return true; }
// tell the renderer about the camera position public void UpdateCamera(CameraControl cam) { if (m_focusRegion != null) { OMV.Vector3 newPos = new OMV.Vector3(); newPos.X = (float)(cam.GlobalPosition.X - m_focusRegion.GlobalPosition.X); newPos.Y = (float)(cam.GlobalPosition.Y - m_focusRegion.GlobalPosition.Y); // another kludge camera offset. Pairs with position kludge in Viewer. newPos.Z = (float)(cam.GlobalPosition.Z - m_focusRegion.GlobalPosition.Z) + 10f; m_log.Log(LogLevel.DRENDERDETAIL, "UpdateCamera: g={0}, f={1}, n={2}", cam.GlobalPosition.ToString(), m_focusRegion.GlobalPosition.ToString(), newPos.ToString()); Camera.Position = newPos; OMV.Vector3 dir = new OMV.Vector3(1f, 0f, 0f); Camera.FocalPoint = (dir * cam.Heading) + Camera.Position; } return; }