private void UpdateNode(Node node, Point p0, Point p1, Point a) { node.Visible = true; if (FrustumCullingEnabled && ViewFrustum.Contains(GetBoundingBox(node)) == ContainmentType.Disjoint) { node.Visible = false; return; } Point p = GetMidpoint(p0, p1); int width = Math.Abs(p0.X - p1.X) + Math.Abs(p0.Y - p1.Y); float distanceSquared = (CameraPosition - new Vector3(p.X, GetHeight(p) * Bumpiness, -p.Y)).LengthSquared(); bool split = SplitCheck(node, width, distanceSquared); if (!node.Split && split) { SplitNode(node); vertexCounter++; } else if (node.Split && !split && CanMerge(node) && CanMerge(node.BaseNeighbor)) { MergeNode(node); MergeNode(node.BaseNeighbor); vertexCounter--; } if (node.Split && node.LeftChild != null) { UpdateNode(node.LeftChild, a, p0, p); UpdateNode(node.RightChild, p1, a, p); } }
protected virtual void UpdateMatrices() { ViewMatrix = CreateViewMatrix(); YViewMatrix = CreateYViewMatrix(); ProjectionMatrix = CreateProjectionMatrix(); ViewFrustum.UpdateFrustum(ViewMatrix * ProjectionMatrix); }
/// <summary> /// 更新照相机 /// </summary> /// <param name="device"></param> public virtual void Update(Device device) { viewPort = device.Viewport; Point3d p = Quaternion4d.QuaternionToEuler(m_Orientation); if (!double.IsNaN(p.Y)) { this._latitude.Radians = p.Y; } if (!double.IsNaN(p.X)) { this._longitude.Radians = p.X; } if (!double.IsNaN(p.Z)) { this._heading.Radians = p.Z; } ComputeProjectionMatrix(viewPort); ComputeViewMatrix(); device.Transform.Projection = m_ProjectionMatrix; device.Transform.View = m_ViewMatrix; device.Transform.World = m_WorldMatrix; ViewFrustum.Update( Matrix.Multiply(m_absoluteWorldMatrix, Matrix.Multiply(m_absoluteViewMatrix, m_absoluteProjectionMatrix))); // Old view range (used in quadtile logic) double factor = (this._altitude) / this._worldRadius; if (factor > 1) { viewRange = Angle.FromRadians(Math.PI); } else { viewRange = Angle.FromRadians(Math.Abs(Math.Asin((this._altitude) / this._worldRadius)) * 2); } // True view range if (factor < 1) { trueViewRange = Angle.FromRadians(Math.Abs(Math.Asin((this._distance) / this._worldRadius)) * 2); } else { trueViewRange = Angle.FromRadians(Math.PI); } World.Settings.cameraAltitudeMeters = Altitude; World.Settings.cameraLatitude = _latitude; World.Settings.cameraLongitude = _longitude; World.Settings.cameraHeading = _heading; World.Settings.cameraTilt = _tilt; }
public void SetWorldAndLoadRenderers(ClientWorld world) { _world = world; _camera = _client.Camera; _cameraTransform = _camera.transform; _frustum = new ViewFrustum(renderDistance: 3); _chunkRenderDispatcher = new ChunkRenderDispatcher(world); }
public void DeviceAttached(Device dev) { Game.GameManager.GraphicsThread.GraphicsManager.Device.SetTransform(TransformState.Projection, mMatProjection); mDevice.SetTransform(TransformState.View, Matrix.LookAtLH(mPosition, mTarget, mUp)); ShaderCollection.CameraChanged(this); Game.GameManager.WorldManager.Update(this); ViewFrustum.BuildViewFrustum(mDevice.GetTransform(TransformState.View), mDevice.GetTransform(TransformState.Projection)); Game.GameManager.InformPropertyChanged(Game.GameProperties.CameraPosition); }
public void UpdateCamera(Device dev, TimeSpan diff) { if (Input.InputManager.Input.HasFocus == false) { return; } bool changed = false; var inp = Input.InputManager.Input; float sensitivity = Game.GameManager.GameWindow.PropertyPanel.CameraSensitivity; if (inp[Keys.W]) { mPosition += (float)diff.TotalSeconds * 50.0f * Vector3.UnitX; mTarget += (float)diff.TotalSeconds * 50.0f * Vector3.UnitX; changed = true; } if (inp[Keys.S]) { mPosition -= (float)diff.TotalSeconds * 50.0f * Vector3.UnitX; mTarget -= (float)diff.TotalSeconds * 50.0f * Vector3.UnitX; changed = true; } if (inp[Keys.D]) { var change = (float)diff.TotalSeconds * 50.0f * Vector3.UnitY; mPosition += change; mTarget += change; changed = true; } if (inp[Keys.A]) { var change = (float)diff.TotalSeconds * 50.0f * Vector3.UnitY; mPosition -= change; mTarget -= change; changed = true; } if (inp[Keys.Q]) { MouseWheelTurned(127); } if (inp[Keys.E]) { MouseWheelTurned(-127); } if (changed) { dev.SetTransform(TransformState.View, Matrix.LookAtLH(mPosition, mTarget, mUp)); ShaderCollection.CameraChanged(this); Game.GameManager.WorldManager.Update(this); ViewFrustum.BuildViewFrustum(dev.GetTransform(TransformState.View), dev.GetTransform(TransformState.Projection)); Game.GameManager.InformPropertyChanged(Game.GameProperties.CameraPosition); } }
public void CopyFrom(Camera fromOther) { AspectRatio = fromOther.AspectRatio; WindowSize = fromOther.WindowSize; Location = fromOther.Location; Pitch = fromOther.Pitch; Yaw = fromOther.Yaw; ProjectionMatrix = fromOther.ProjectionMatrix; CameraViewMatrix = fromOther.CameraViewMatrix; ViewProjectionMatrix = fromOther.ViewProjectionMatrix; ViewFrustum.Update(ViewProjectionMatrix); }
public void SetPosition(Vector3 position, bool nonUpdate = false) { mPosition = position; mTarget = mPosition + mFront; mDevice.SetTransform(TransformState.View, Matrix.LookAtLH(mPosition, mTarget, mUp)); ShaderCollection.CameraChanged(this); if (nonUpdate == false) { Game.GameManager.WorldManager.Update(this); ViewFrustum.BuildViewFrustum(mDevice.GetTransform(TransformState.View), mDevice.GetTransform(TransformState.Projection)); Game.GameManager.InformPropertyChanged(Game.GameProperties.CameraPosition); } }
void MouseWheelTurned(int delta) { if (Game.GameManager.GraphicsThread.GraphicsManager.IsIn2D == false) { return; } int realTurn = delta / 127; float newZoom = mZoomFactor + realTurn * 0.01f; if (newZoom < 0.1f) { newZoom = 0.1f; } if (newZoom > 1.0f) { newZoom = 1.0f; } mZoomFactor = newZoom; float aspect = (float)Game.GameManager.GraphicsThread.GraphicsManager.RenderWindow.ClientSize.Width / (float)Game.GameManager.GraphicsThread.GraphicsManager.RenderWindow.ClientSize.Height; mMatProjection = Matrix.OrthoOffCenterLH( -(Utils.Metrics.Tilesize * mZoomFactor * aspect / 2.0f), Utils.Metrics.Tilesize * mZoomFactor * aspect / 2.0f, -(Utils.Metrics.Tilesize * mZoomFactor / 2.0f), Utils.Metrics.Tilesize * mZoomFactor / 2.0f, 0.1f, 10000.0f ); Game.GameManager.GraphicsThread.GraphicsManager.Device.SetTransform(TransformState.Projection, mMatProjection); var dev = Game.GameManager.GraphicsThread.GraphicsManager.Device; dev.SetTransform(TransformState.View, Matrix.LookAtLH(mPosition, mTarget, mUp)); ShaderCollection.CameraChanged(this); Game.GameManager.WorldManager.Update(this); Game.GameManager.InformPropertyChanged(Game.GameProperties.CameraPosition); ViewFrustum.BuildViewFrustum(dev.GetTransform(TransformState.View), mMatProjection); }
private void UpdateNode(Point p, int size, bool frustumCulling) { UpdateBlending(p, size); if (!IsEnabled(p)) { return; } if (GeomorphEnabled) { UpdateMidpointBlending(p, size); } Quadtree[p.X, p.Y].Visible = true; if (frustumCulling) { ContainmentType result = ViewFrustum.Contains(GetBoundingBox(p, size)); if (result == ContainmentType.Disjoint) { Quadtree[p.X, p.Y].Visible = false; } else if (result == ContainmentType.Contains) { frustumCulling = false; } } if (size == 3 || !IsVisible(p)) { return; } Point[] children = GetChildren(p, size); for (int i = 0; i < 4; i++) { UpdateNode(children[i], size / 2 + 1, frustumCulling); } }
private void UpdateNode(Node node, bool frustumCulling, GameTime gameTime) { node.Visible = true; if (frustumCulling) { ContainmentType result = ViewFrustum.Contains(GetBoundingBox(node)); if (result == ContainmentType.Disjoint) { node.Visible = false; } else if (result == ContainmentType.Contains) { frustumCulling = false; } } if (!node.Visible) { return; } if (node.Children != null) { foreach (Node child in node.Children) { UpdateNode(child, frustumCulling, gameTime); } } if (node.Block != null) { node.Block.Update(gameTime); } }
private void irrlichtPanel_MouseClick(object sender, MouseEventArgs e) { // need to have a click plus the ctrl key down if (pickKeyDown) { ViewFrustum f = smgr.ActiveCamera.ViewFrustum; Vector3Df farLeftUp = f.FarLeftUp; Vector3Df lefttoright = f.FarRightUp - farLeftUp; Vector3Df uptodown = f.FarLeftDown - farLeftUp; float dx = e.X / (float)viewPort.Width; float dy = e.Y / (float)viewPort.Height; Line3Df ray = new Line3Df(f.CameraPosition, farLeftUp + (lefttoright * dx) + (uptodown * dy)); SceneNode pickedNode = smgr.SceneCollisionManager.GetSceneNodeFromRayBB(ray); if (pickedNode != null) { RenderMessage message = new RenderMessage(MessageType.HIGHLIGHT_NODE, pickedNode); commandQueue.Enqueue(message); propertiesDlg.SetProperties(pickedNode); if (!propertiesDlg.Visible) { propertiesDlg.Show(this); } if (backgroundSearcher.IsBusy) { backgroundSearcher.CancelAsync(); } backgroundSearcher.RunWorkerAsync(pickedNode.ID); } } }
private void RecalculateMatrices() { CameraViewMatrix = Matrix4x4.CreateScale(Scale) * Matrix4x4.CreateLookAt(Location, Location + GetForwardVector(), Vector3.UnitZ); ViewProjectionMatrix = CameraViewMatrix * ProjectionMatrix; ViewFrustum.Update(ViewProjectionMatrix); }
/// <summary> /// Check to see if a bounding volume is within the bounds of the view frustum /// </summary> /// <param name="sphere">BoundingSphere to be checked</param> /// <returns>Result</returns> public bool IsInView(BoundingSphere sphere) { return(ViewFrustum.Contains(sphere) != ContainmentType.Disjoint); }
/// <summary> /// Check to see if a bounding volume is within the bounds of the view frustum /// </summary> /// <param name="box">BoundingBox to be checked</param> /// <returns>Result</returns> public bool IsInView(BoundingBox box) { return(ViewFrustum.Contains(box) != ContainmentType.Disjoint); }
public void UpdateCamera(Device dev, TimeSpan diff) { if (Input.InputManager.Input.HasFocus == false) { return; } bool changed = false; var inp = Input.InputManager.Input; float sensitivity = Game.GameManager.GameWindow.PropertyPanel.CameraSensitivity; if (inp[Keys.W]) { mPosition += (float)diff.TotalSeconds * mFront * 50; mTarget += (float)diff.TotalSeconds * mFront * 50; changed = true; } if (inp[Keys.S]) { mPosition -= (float)diff.TotalSeconds * mFront * 50; mTarget -= (float)diff.TotalSeconds * mFront * 50; changed = true; } if (inp[Keys.D]) { var change = (float)diff.TotalSeconds * mRight * 50; mPosition += change; mTarget += change; changed = true; } if (inp[Keys.A]) { var change = (float)diff.TotalSeconds * mRight * 50; mPosition -= change; mTarget -= change; changed = true; } if (inp[Keys.Q]) { var change = (float)diff.TotalSeconds * Vector3.UnitZ * 50; mPosition += change; mTarget += change; changed = true; } if (inp[Keys.E]) { var change = (float)diff.TotalSeconds * Vector3.UnitZ * 50; mPosition -= change; mTarget -= change; changed = true; } var state = Input.InputManager.Input.Mouse.State; if (state.IsPressed((int)SlimDX.DirectInput.MouseObject.Button2) && Game.GameManager.SelectionManager.IsModelMovement == false) { if (state.X != 0 || state.Y != 0) { if (state.X != 0) { int fac = (state.X < 0) ? -1 : 1; Matrix rot = Matrix.RotationZ(state.X * 0.005f * sensitivity); mFront = Vector3.TransformCoordinate(mFront, rot); mFront.Normalize(); mTarget = mPosition + mFront; mRight = Vector3.TransformCoordinate(mRight, rot); mRight.Normalize(); mUp = Vector3.TransformCoordinate(mUp, rot); mUp.Normalize(); changed = true; } if (state.Y != 0) { int fac = (state.Y < 0) ? -1 : 1; Matrix rot = Matrix.RotationAxis(mRight, state.Y * 0.005f * sensitivity); mFront = Vector3.TransformCoordinate(mFront, rot); mFront.Normalize(); mTarget = mPosition + mFront; mUp = Vector3.TransformCoordinate(mUp, rot); mUp.Normalize(); changed = true; } } } if (changed) { dev.SetTransform(TransformState.View, Matrix.LookAtLH(mPosition, mTarget, mUp)); ShaderCollection.CameraChanged(this); Game.GameManager.WorldManager.Update(this); ViewFrustum.BuildViewFrustum(dev.GetTransform(TransformState.View), dev.GetTransform(TransformState.Projection)); Game.GameManager.InformPropertyChanged(Game.GameProperties.CameraPosition); } }