protected override void LoadContent() { _spriteBatch = new SpriteBatch(GraphicsDevice); _bitmapFont = Content.Load <BitmapFont>("Fonts/montserrat-32"); var viewportAdapter = new BoxingViewportAdapter(Window, GraphicsDevice, 800, 480); _camera = new OrthographicCamera(viewportAdapter) { Zoom = 2.0f }; _sceneGraph = new SceneGraph(); var carHullTexture = Content.Load <Texture2D>("Textures/car-hull"); var carHullSprite = new Sprite(carHullTexture); var carWheelTexture = Content.Load <Texture2D>("Textures/car-wheel"); var carWheelSprite = new Sprite(carWheelTexture); _carNode = new SceneNode("car-hull", viewportAdapter.Center.ToVector2()); _carNode.Entities.Add(new SpriteEntity(carHullSprite)); _leftWheelNode = new SceneNode("left-wheel", new Vector2(-29, 17)); _leftWheelNode.Entities.Add(new SpriteEntity(carWheelSprite)); _rightWheelNode = new SceneNode("right-wheel", new Vector2(40, 17)); _rightWheelNode.Entities.Add(new SpriteEntity(carWheelSprite)); _carNode.Children.Add(_rightWheelNode); _carNode.Children.Add(_leftWheelNode); _sceneGraph.RootNode.Children.Add(_carNode); }
protected override void Initialize() { _gui = new Gui(_desktop); base.Initialize(); foreach (Blocks name in Enum.GetValues(typeof(Blocks))) { Materials.Add(name, Content.Load <Texture2D>(name.ToString())); } _virtualWidth = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width; _virtualHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height; var viewportAdapter = new BoxingViewportAdapter(Window, GraphicsDevice, _virtualWidth, _virtualHeight); _world = new World(); Player1 = new Player(0, 0, _world); _cam = new OrthographicCamera(viewportAdapter); _cam.LookAt(new Vector2(Player.X, Player.Y)); _cam.Zoom = IRestrictions.Zoom; _spriteBatch = new SpriteBatch(GraphicsDevice); _playerMouse = new PlayerMouse(Content, _spriteBatch, _cam); _inputController = new InputController(_cam, _spriteBatch, Content, this, _world, Player1, _playerMouse); WorldRenderer = new WorldRenderer(_playerMouse, _inputController, _spriteBatch, this, _world); }
/// <summary> /// Get the projection matrix from an orthographic camera. /// </summary> /// <param name="camera">The camera we want the projection matrix of.</param> /// <param name="aspectRatio">The aspect ratio of the image or window.</param> /// <returns>Returns the projection matrix.</returns> private static Matrix3D GetProjectionMatrix(OrthographicCamera camera, double aspectRatio) { Debug.Assert(camera != null, "Caller needs to ensure camera is non-null."); // This math is identical to what you find documented for // D3DXMatrixOrthoRH with the exception that in WPF only // the camera's width is specified. Height is calculated // from width and the aspect ratio. double w = camera.Width; double h = w / aspectRatio; double zn = camera.NearPlaneDistance; double zf = camera.FarPlaneDistance; double m33 = 1 / (zn - zf); double m43 = zn * m33; return(new Matrix3D( 2 / w, 0, 0, 0, 0, 2 / h, 0, 0, 0, 0, m33, 0, 0, 0, m43, 1)); }
protected override void DragMove(MapViewport viewport, OrthographicCamera camera, ViewportEvent e) { if (e.Button != MouseButtons.Left) { return; } if (CurrentDraggable == null || !_lastDragPoint.HasValue) { return; } var point = camera.Flatten(camera.ScreenToWorld(e.X, e.Y)); var last = _lastDragPoint.Value; OnDraggableDragMoving(viewport, camera, e, last, point, CurrentDraggable); if (!e.Handled) { CurrentDraggable.Drag(viewport, camera, e, last, point); } if (!e.Handled) { OnDraggableDragMoved(viewport, camera, e, last, point, CurrentDraggable); } _lastDragPoint = point; _lastDragMoveEvent = e; Invalidate(); }
protected override void MouseMove(MapDocument document, MapViewport vp, OrthographicCamera camera, ViewportEvent e) { var viewport = vp; var point = SnapIfNeeded(camera.ScreenToWorld(e.X, e.Y)); var st = GetStateAtPoint(e.X, e.Y, camera); if (_state == ClipState.Drawing) { _state = ClipState.MovingPoint2; _clipPlanePoint1 = _drawingPoint; _clipPlanePoint2 = point; _clipPlanePoint3 = _clipPlanePoint1 + SnapIfNeeded(camera.GetUnusedCoordinate(new Vector3(128, 128, 128))); } else if (_state == ClipState.MovingPoint1) { // Move point 1 var cp1 = camera.GetUnusedCoordinate(_clipPlanePoint1.Value) + point; if (KeyboardState.Ctrl) { var diff = _clipPlanePoint1 - cp1; _clipPlanePoint2 -= diff; _clipPlanePoint3 -= diff; } _clipPlanePoint1 = cp1; } else if (_state == ClipState.MovingPoint2) { // Move point 2 var cp2 = camera.GetUnusedCoordinate(_clipPlanePoint2.Value) + point; if (KeyboardState.Ctrl) { var diff = _clipPlanePoint2 - cp2; _clipPlanePoint1 -= diff; _clipPlanePoint3 -= diff; } _clipPlanePoint2 = cp2; } else if (_state == ClipState.MovingPoint3) { // Move point 3 var cp3 = camera.GetUnusedCoordinate(_clipPlanePoint3.Value) + point; if (KeyboardState.Ctrl) { var diff = _clipPlanePoint3 - cp3; _clipPlanePoint1 -= diff; _clipPlanePoint2 -= diff; } _clipPlanePoint3 = cp3; } if (st != ClipState.None || _state != ClipState.None && _state != ClipState.Drawn) { viewport.Control.Cursor = Cursors.Cross; } else { viewport.Control.Cursor = Cursors.Default; } }
protected override void MouseDown(MapViewport viewport, OrthographicCamera camera, ViewportEvent e) { // Get the first element that intersects with the box, selecting or deselecting as needed var closestObject = SelectionTest(camera, e) as Solid; SelectObject(closestObject); }
public SpriteRenderer(Sprite sprite, OrthographicCamera camera, ShaderProgram customShader) { this.Sprite = sprite; this.Camera = camera; this.CustomShader = customShader; this.Priority = 0; }
/// <summary> /// Computes the effective projection matrix for the given /// camera. /// </summary> public static Matrix3D GetProjectionMatrix(Camera camera, double aspectRatio) { if (camera == null) { throw new ArgumentNullException("camera"); } PerspectiveCamera perspectiveCamera = camera as PerspectiveCamera; if (perspectiveCamera != null) { return(GetProjectionMatrix(perspectiveCamera, aspectRatio)); } OrthographicCamera orthographicCamera = camera as OrthographicCamera; if (orthographicCamera != null) { return(GetProjectionMatrix(orthographicCamera, aspectRatio)); } MatrixCamera matrixCamera = camera as MatrixCamera; if (matrixCamera != null) { return(matrixCamera.ProjectionMatrix); } throw new ArgumentException(String.Format("Unsupported camera type '{0}'.", camera.GetType().FullName), "camera"); }
public HelixView3D() { // The Viewport3D must be created here since the Children collection is attached directly viewport = new Viewport3D { IsHitTestVisible = this.IsHitTestVisible, ClipToBounds = this.ClipToBounds }; // headlight lights = new Model3DGroup(); viewport.Children.Add(new ModelVisual3D { Content = lights }); perspectiveCamera = new PerspectiveCamera(); CameraHelper.Reset(perspectiveCamera); orthographicCamera = new OrthographicCamera(); CameraHelper.Reset(orthographicCamera); // perspectiveCamera.Changed += Camera_Changed; // orthographicCamera.Changed += Camera_Changed; // Set the current camera OnOrthographicChanged(); // http://blogs.msdn.com/wpfsdk/archive/2007/01/15/maximizing-wpf-3d-performance-on-tier-2-hardware.aspx // RenderOptions.EdgeMode? // start a watch for FPS calculations fpsWatch.Start(); // Using the rendering event to calculate FPS // todo: is this giving correct numbers?? CompositionTarget.Rendering += CompositionTarget_Rendering; Loaded += HelixView3D_Loaded; }
public override void Render(IViewport viewport, OrthographicCamera camera, Vector3 worldMin, Vector3 worldMax, Graphics graphics) { if (HighlightedViewport != viewport) { return; } var b = GetRectangle(camera); var start = camera.WorldToScreen(camera.Expand(b.Start)); var end = camera.WorldToScreen(camera.Expand(b.End)); graphics.SmoothingMode = SmoothingMode.HighQuality; using (var br = new SolidBrush(State.FillColour)) { graphics.FillRectangle(br, start.X, end.Y, end.X - start.X, start.Y - end.Y); } if (Handle == ResizeHandle.Center && SnappedMoveOrigin != null) { const int size = 4; var orig = camera.WorldToScreen(camera.Expand(SnappedMoveOrigin.Value)); graphics.DrawLine(Pens.Yellow, orig.X - size, orig.Y - size, orig.X + size, orig.Y + size); graphics.DrawLine(Pens.Yellow, orig.X + size, orig.Y - size, orig.X - size, orig.Y + size); } graphics.SmoothingMode = SmoothingMode.Default; }
private static Ray3D RayFromOrthographicCameraPoint(OrthographicCamera camera, Point point, Size viewSize) { Point3D position = camera.Position; Vector3D lookDirection = camera.LookDirection; Vector3D upDirection = camera.UpDirection; Transform3D transform = camera.Transform; double nearPlaneDistance = camera.NearPlaneDistance; double farPlaneDistance = camera.FarPlaneDistance; double width = camera.Width; Point normalizedPoint = CameraRayHelpers.GetNormalizedPoint(point, viewSize); double aspectRatio = CameraRayHelpers.GetAspectRatio(viewSize); double num1 = width; double num2 = num1 / aspectRatio; Point3D point1 = new Point3D(normalizedPoint.X * (num1 / 2.0), normalizedPoint.Y * (num2 / 2.0), -nearPlaneDistance); Vector3D vector = new Vector3D(0.0, 0.0, -1.0); Matrix3D viewMatrix = CameraRayHelpers.CreateViewMatrix((Transform3D)null, ref position, ref lookDirection, ref upDirection); viewMatrix.Invert(); Point3D point3D = viewMatrix.Transform(point1); Vector3D vector3D = viewMatrix.Transform(vector); if (transform != null && transform != Transform3D.Identity) { point3D = transform.Transform(point3D); vector3D = transform.Transform(vector3D); } return(new Ray3D(point3D, vector3D)); }
protected virtual Vector3 GetResizeOrigin(MapViewport viewport, OrthographicCamera camera, Vector3 position) { var st = camera.Flatten(BoxState.Start); var ed = camera.Flatten(BoxState.End); return((st + ed) / 2); }
public RendererSystem(GameApp gameApp) : base(Aspect .All(typeof(RenderFormComponent), typeof(Transform2D))) { _gameApp = gameApp; _sb = new SpriteBatch(_gameApp.GraphicsDevice); _camera = gameApp.Services.GetService <OrthographicCamera>(); }
public override void EndDrag(MapViewport viewport, OrthographicCamera camera, ViewportEvent e, Vector3 position) { BoxState.FixBounds(); BoxState.Action = BoxAction.Drawn; MoveOrigin = SnappedMoveOrigin = null; base.EndDrag(viewport, camera, e, position); }
protected override void LoadContent() { const int mapSize = 100; var texturesManager = new TexturesManager(Content); var entityBuilder = new EntityBuilder(texturesManager); var tileOccupationManager = new TileOccupationManager(mapSize, mapSize); _spriteBatch = new SpriteBatch(GraphicsDevice); _camera = new OrthographicCamera(GraphicsDevice); _world = new WorldBuilder() .AddSystem(new ControlSystem()) .AddSystem(new CameraSystem()) .AddSystem(new SpatialTilePositionSystem(tileOccupationManager)) .AddSystem(new UnitPlacementSystem(entityBuilder, _camera, tileOccupationManager)) .AddSystem(new MinerProcessingSystem(tileOccupationManager, entityBuilder)) .AddSystem(new MineableResourceSystem()) .AddSystem(new ProductionUnitOutputSystem(tileOccupationManager)) .AddSystem(new TransporterTransportSystem(tileOccupationManager)) .AddSystem(new TransportableMovementSystem(tileOccupationManager)) .AddSystem(new AlignableSpritePickingSystem(texturesManager)) .AddSystem(new TileRenderSystem(_spriteBatch, _camera, new DepthHelper((mapSize, mapSize)))) .AddSystem(new MapRenderSystem(_spriteBatch, _camera, mapSize)) .Build(); var mapBuilder = new MapBuilder(_world, entityBuilder, mapSize); texturesManager.LoadTextures(); mapBuilder.BuildMap(); var gameCamera = entityBuilder.BuildGameCamera(_world.CreateEntity(), _camera, new Vector2(50, 50)); // TODO: use this.Content to load your game content here }
private RectangleF GetValidatedBounds(OrthographicCamera camera, int padding) { var vmin = camera.Flatten(camera.ScreenToWorld(new Vector3(-padding, camera.Height + padding, 0))); var vmax = camera.Flatten(camera.ScreenToWorld(new Vector3(camera.Width + padding, -padding, 0))); return(new RectangleF(vmin.X, vmin.Y, vmax.X - vmin.X, vmax.Y - vmin.Y)); }
public static SceneDescription AreaLight(bool secondLight) { var lightTransform = Transform.LookAt(new Point3 <float>(0.5f, 0.75f, -0.5f), new Point3 <float>(0, 0, 0), new Vector3 <float>(0, 1, 0)).Inverse(); var lightShape = new Disk(lightTransform, 0.75f); var light = new DiffuseAreaLight(lightTransform, new Spectrum(5), lightShape, 1, true); var lightTransform2 = Transform.LookAt(new Point3 <float>(-1, -1.5f, -1f), new Point3 <float>(0, 0, 0), new Vector3 <float>(0, 1, 0)).Inverse(); var lightShape2 = new Disk(lightTransform2, 3); var light2 = new DiffuseAreaLight(lightTransform2, new Spectrum(1, 0.07f, 0.57f), lightShape2, 1, true); var primitives = new List <Primitive>() { new GeometricPrimitive(new Sphere(Transform.Translate(0, 0, 0), 0.5f), new MatteMaterial(new Spectrum(1), 0)), //new GeometricPrimitive(new Disk(Transform.Translate(0, -1f, 0), 2), new MatteMaterial(new Spectrum(1), 0)), new GeometricPrimitive(lightShape, new MatteMaterial(new Spectrum(1), 0), light) }; if (secondLight) { primitives.Add(new GeometricPrimitive(lightShape2, new MatteMaterial(new Spectrum(1), 0), light2)); } var lights = new List <Light>() { light }; if (secondLight) { lights.Add(light2); } return(new SceneDescription(new PrimitiveList(primitives), lights, OrthographicCamera.Create(new Point3 <float>(0, 0, -5)))); }
public static double UnitsPerPixel(Viewport3D viewport, Point3D targetPoint) { double num1 = 1.0; ProjectionCamera projectionCamera = viewport.Camera as ProjectionCamera; if (projectionCamera == null) { return(1.0); } Vector3D vector3D = targetPoint - projectionCamera.Position; PerspectiveCamera perspectiveCamera = projectionCamera as PerspectiveCamera; OrthographicCamera orthographicCamera = projectionCamera as OrthographicCamera; if (perspectiveCamera != null) { double fieldOfView = perspectiveCamera.FieldOfView; num1 = 2.0 * vector3D.Length * Math.Tan(Math.PI / 180.0 * (fieldOfView / 2.0)); } else if (orthographicCamera != null) { num1 = orthographicCamera.Width; } double num2 = num1; if (viewport.ActualWidth > 0.0) { num2 /= viewport.ActualWidth; } return(num2); }
public static SceneDescription SpheresReflection(float roughness = 0.01f) { var primitives = new List <Primitive>() { new GeometricPrimitive(new Sphere(Transform.Identity, 0.5f), new PlasticMaterial(new Spectrum(1), new Spectrum(1), roughness)), new GeometricPrimitive(new Sphere(Transform.Translate(1, 0, 0), 0.25f), new MatteMaterial(new Spectrum(1, 0, 0), 0)), new GeometricPrimitive(new Sphere(Transform.Translate(-1, 0, 0), 0.25f), new MatteMaterial(new Spectrum(0, 1, 0), 0)), new GeometricPrimitive(new Sphere(Transform.Translate(0, 0.75f, 0), 0.25f), new MatteMaterial(new Spectrum(0, 0, 10), 0)), new GeometricPrimitive(new Sphere(Transform.Translate(0, -1, 0), 0.25f), new MatteMaterial(new Spectrum(1, 1, 0), 0)), new GeometricPrimitive(new Sphere(Transform.Translate(-0.7f, 0.7f, 0), 0.25f), new MirrorMaterial(new Spectrum(1))), new GeometricPrimitive(new Sphere(Transform.Translate(0.7f, 0.7f, 0), 0.25f), new MirrorMaterial(new Spectrum(1))), new GeometricPrimitive(new Sphere(Transform.Translate(-0.7f, -0.7f, 0), 0.25f), new MirrorMaterial(new Spectrum(1))), new GeometricPrimitive(new Sphere(Transform.Translate(0.7f, -0.7f, 0), 0.25f), new MirrorMaterial(new Spectrum(1))), }; var lights = new List <Light>() { new PointLight(Transform.Translate(1, 1, -5), new Spectrum(25)), new PointLight(Transform.Translate(-3, -3, 3), new Spectrum(10)), }; return(new SceneDescription(new PrimitiveList(primitives), lights, OrthographicCamera.Create(new Point3 <float>(0, 0, -5)))); }
protected override void MouseDown(MapViewport viewport, OrthographicCamera camera, ViewportEvent e) { var vp = viewport; if (vp == null) { return; } var gs = Document.Map.Data.GetOne <GridData>()?.Grid?.Spacing ?? 64; _state = GetStateAtPoint(e.X, e.Y, camera, out _stateCamera); if (_state == State.None && KeyboardState.Shift) { var p = SnapIfNeeded(camera.ScreenToWorld(e.X, e.Y)); _stateCamera = new Camera { EyePosition = p, LookPosition = p + Vector3.UnitX * 1.5f * gs }; Document.Map.Data.Add(_stateCamera); _state = State.MovingLook; } if (_stateCamera != null) { SetViewportCamera(_stateCamera.EyePosition, _stateCamera.LookPosition); GetDocumentCameras().ForEach(x => x.IsActive = false); _stateCamera.IsActive = true; } }
private ClipState GetStateAtPoint(int x, int y, OrthographicCamera camera) { if (_clipPlanePoint1 == null || _clipPlanePoint2 == null || _clipPlanePoint3 == null) { return(ClipState.None); } var p = camera.Flatten(camera.ScreenToWorld(new Vector3(x, y, 0))); var p1 = camera.Flatten(_clipPlanePoint1.Value); var p2 = camera.Flatten(_clipPlanePoint2.Value); var p3 = camera.Flatten(_clipPlanePoint3.Value); var d = 5 / camera.Zoom; if (p.X >= p1.X - d && p.X <= p1.X + d && p.Y >= p1.Y - d && p.Y <= p1.Y + d) { return(ClipState.MovingPoint1); } if (p.X >= p2.X - d && p.X <= p2.X + d && p.Y >= p2.Y - d && p.Y <= p2.Y + d) { return(ClipState.MovingPoint2); } if (p.X >= p3.X - d && p.X <= p3.X + d && p.Y >= p3.Y - d && p.Y <= p3.Y + d) { return(ClipState.MovingPoint3); } return(ClipState.None); }
public override void StartDrag(MapDocument document, MapViewport viewport, OrthographicCamera camera, ViewportEvent e, Vector3 position) { _skewStart = _skewEnd = position; base.StartDrag(document, viewport, camera, e, position); }
public static void RotateCamera(this OrthographicCamera TheCamera, double angleX, double angleY) { TheCamera.Rotate(new Vector3D(0, 1, 0), -angleX * 2); Vector3D rightDirection = TheCamera.LookDirection.Cross(TheCamera.UpDirection); TheCamera.Rotate(rightDirection, 2 * angleY); }
public World(MainGame game, BoxingViewportAdapter viewport) { _game = game; _camera = new OrthographicCamera(viewport); _cameraScale = 4f; _camera.ZoomIn(_cameraScale); }
private void move(OrthographicCamera camera, GameTime gameTime) { float deltaTime = gameTime.GetElapsedSeconds(); KeyboardState keyboardState = Keyboard.GetState(); if (keyboardState.IsKeyDown(Keys.Up)) { camera.Move(new Vector2(0, -speed) * deltaTime); } if (keyboardState.IsKeyDown(Keys.Down)) { camera.Move(new Vector2(0, +speed) * deltaTime); } if (keyboardState.IsKeyDown(Keys.Left)) { camera.Move(new Vector2(-speed, 0) * deltaTime); } if (keyboardState.IsKeyDown(Keys.Right)) { camera.Move(new Vector2(+speed, 0) * deltaTime); } }
protected override void RegisterDependencies(ContainerBuilder builder) { _camera = new OrthographicCamera(GraphicsDevice); builder.RegisterInstance(new SpriteBatch(GraphicsDevice)); builder.RegisterInstance(_camera); }
//protected override void Initialize() //{ // base.Initialize(); // _graphicsDeviceManager.IsFullScreen = true; // _graphicsDeviceManager.PreferredBackBufferWidth = GraphicsDevice.DisplayMode.Width; // _graphicsDeviceManager.PreferredBackBufferHeight = GraphicsDevice.DisplayMode.Height; // _graphicsDeviceManager.ApplyChanges(); //} protected override void LoadContent() { _viewportAdapter = new BoxingViewportAdapter(Window, GraphicsDevice, 800, 480); _font = Content.Load <BitmapFont>("Fonts/montserrat-32"); _camera = new OrthographicCamera(_viewportAdapter); //_explosionAnimations = Content.Load<SpriteSheetAnimationFactory>("explosion-animations"); _spriteBatch = new SpriteBatch(GraphicsDevice); _backgroundTexture = Content.Load <Texture2D>("black"); var bulletTexture = Content.Load <Texture2D>("laserBlue03"); var bulletRegion = new TextureRegion2D(bulletTexture); _bulletFactory = new BulletFactory(_entityManager, bulletRegion); SpawnPlayer(_bulletFactory); _meteorFactory = new MeteorFactory(_entityManager, Content); for (var i = 0; i < 13; i++) { _meteorFactory.SpawnNewMeteor(_player.Position); } }
private void EndPointDrag(OrthographicCamera camera, ViewportEvent viewportEvent, Vector3 endLocation) { var delta = camera.ZeroUnusedCoordinate(endLocation) - _pointDragStart; if (KeyboardState.Shift && !KeyboardState.Alt) { delta -= _pointDragGridOffset; } var selected = GetVisiblePoints().Where(x => x.IsSelected).ToList(); selected.ForEach(x => x.IsDragging = false); // Update positions var pts = selected.SelectMany(x => x.GetStandardPointList()).Distinct().ToList(); foreach (var point in pts) { point.Move(delta); } // Merge points if required if (AutomaticallyMerge()) { CheckMergedVertices(); } else if (CanMerge() && ConfirmMerge()) { CheckMergedVertices(); } UpdateSolids(pts.Select(x => x.Solid).Distinct().ToList()); }
public CameraMotion2D(OrthographicCamera camera) { On <EngineUpdateEvent>(Update); On <BeginFrameEvent>(e => _velocity = Vector2.Zero); On <CameraLockEvent>(e => _locked = true); On <CameraUnlockEvent>(e => _locked = false); On <CameraJumpEvent>(e => { var map = Resolve <IMapManager>().Current; if (map == null) { return; } _position = new Vector2(e.X * map.TileSize.X + 0.1f, e.Y * map.TileSize.Y + 0.1f); _camera.Position = new Vector3(_position, map.BaseCameraHeight); }); On <CameraMoveEvent>(e => { var map = Resolve <IMapManager>().Current; if (map == null) { return; } _velocity += new Vector2(e.X * map.TileSize.X, e.Y * map.TileSize.Y); }); _camera = camera; }
public void Draw(OrthographicCamera camera, SpriteBatch spriteBatch) { var viewMatrix = camera.GetViewMatrix(); mapRenderer.Draw(viewMatrix); entities.ForEach(entity => { entity.Draw(spriteBatch); }); }
public void OrthographicCamera_4Arg_Constructor_Creates_New_Object() { var position = new Point(150.0f, 200.0f, -100.0f); var lookAt = new Point(0.0f, 0.0f, 0.0f); var width = 640u; var height = 480u; var camera = new OrthographicCamera(position, lookAt, width, height); Assert.IsNotNull(camera); }
private void checkDecorations(OrthographicCamera c) { float cameraX = (float) (c.position.x - (c.viewportWidth * .5)); float cameraY = (float) (c.position.y - (c.viewportHeight * .5)); if (mostLeftSprite.getX() + _tileBuffer > cameraX) moveLeft(); if (mostRightSprite.getX() - _tileBuffer < c.viewportWidth + cameraX) moveRight(); if (mostUpSprite.getY() + _tileBuffer > cameraY) moveUp(); if ((mostDownSprite.getY() + 64) - _tileBuffer < c.viewportHeight + cameraY) moveDown(); }
public void OrthographicCamera_5Arg_Constructor_With_Non_Perpendicular_Vectors_Recalculates_From_Up() { var position = new Point(150.0f, 200.0f, -100.0f); var up = new Vector(1.0f, 1.0f, 0.0f); var right = new Vector(0.0f, -1.0f, 0.0f); var width = 640u; var height = 480u; var camera = new OrthographicCamera(position, up, right, width, height); Assert.AreEqual(0.707106769f, camera.Up.X, EPSILON); Assert.AreEqual(0.707106769f, camera.Up.Y, EPSILON); Assert.AreEqual(0.0f, camera.Up.Z, EPSILON); Assert.AreEqual(0.707106769f, camera.Right.X, EPSILON); Assert.AreEqual(-0.707106769f, camera.Right.Y, EPSILON); Assert.AreEqual(0.0, camera.Right.Z, EPSILON); }
public void OrthographicCamera_5Arg_Constructor_With_Non_Normalised_Vectors_Normalises_Vectors() { var position = new Point(150.0f, 200.0f, -100.0f); var up = new Vector(0.0f, 1.0f, 1.0f); var right = new Vector(2.0f, 0.0f, 0.0f); var width = 640u; var height = 480u; var camera = new OrthographicCamera(position, up, right, width, height); Assert.AreEqual(0.0f, camera.Up.X, EPSILON); Assert.AreEqual(0.707106769f, camera.Up.Y, EPSILON); Assert.AreEqual(0.707106769f, camera.Up.Z, EPSILON); Assert.AreEqual(1.0f, camera.Right.X, EPSILON); Assert.AreEqual(0.0, camera.Right.Y, EPSILON); Assert.AreEqual(0.0, camera.Right.Z, EPSILON); }
public void OrthographicCamera_GetRay_zeros_give_bottom_left_corner() { var position = new Point(10.0f, 20.0f, -100.0f); var up = new Vector(0.0f, 1.0f, 0.0f); var right = new Vector(1.0f, 0.0f, 0.0f); var width = 10u; var height = 10u; var camera = new OrthographicCamera(position, up, right, width, height); var ray = camera.GetRay(0.0f, 0.0f); Assert.AreEqual(new Point(5.0f, 15.0f, -100.0f), ray.Start); Assert.AreEqual(new Vector(0.0f, 0.0f, 1.0f), ray.Direction); }
public void OrthographicCamera_GetRay_center_gives_camera_position() { var position = new Point(10.0f, 20.0f, -100.0f); var up = new Vector(0.0f, 1.0f, 0.0f); var right = new Vector(1.0f, 0.0f, 0.0f); var width = 10u; var height = 10u; var camera = new OrthographicCamera(position, up, right, width, height); var ray = camera.GetRay(5.0f, 5.0f); Assert.AreEqual(position, ray.Start); Assert.AreEqual(new Vector(0.0f, 0.0f, 1.0f), ray.Direction); }
public void OrthographicCamera_GetRay_throws_given_too_large_x() { var position = new Point(10.0f, 20.0f, -100.0f); var up = new Vector(0.0f, 1.0f, 0.0f); var right = new Vector(1.0f, 0.0f, 0.0f); var width = 10u; var height = 10u; var camera = new OrthographicCamera(position, up, right, width, height); camera.GetRay(10.0f, 5.0f); }
internal void add(OrthographicCamera cameraOrtho) { throw new NotImplementedException(); }
internal void render(Scene sceneTmp, OrthographicCamera cameraOrtho, object target, bool p) { throw new NotImplementedException(); }
public override void Render(RenderContext context) { if (!this.renderHost.IsShadowMapEnabled) { return; } /// --- set rasterizes state here with proper shadow-bias, as depth-bias and slope-bias in the rasterizer this.device.ImmediateContext.Rasterizer.SetViewports(new Viewport(0, 0, width, height, 0.0f, 1.0f)); this.device.ImmediateContext.OutputMerger.SetTargets(depthViewSM); this.device.ImmediateContext.ClearDepthStencilView(depthViewSM, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0); var root = context.Canvas.Renderable.Items; foreach (var item in root) { var light = item as Light3D; if (light != null) { Camera lightCamera = null; //if (light is PointLightBase3D) //{ // var plight = (PointLightBase3D)light; // lightCamera = new PerspectiveCamera() // { // Position = plight.Position, // LookDirection = plight.Direction, // UpDirection = Vector3.UnitY.ToVector3D(), // }; //} // else if (light is DirectionalLight3D) { var dlight = (DirectionalLight3D)light; var dir = light.Direction.Normalized(); var pos = -50 * light.Direction; //lightCamera = new PerspectiveCamera() //{ // LookDirection = dir.ToVector3D(), // Position = (System.Windows.Media.Media3D.Point3D)(pos.ToVector3D()), // UpDirection = Vector3.UnitZ.ToVector3D(), // NearPlaneDistance = 1, // FarPlaneDistance = 100, // FieldOfView = 10, //}; lightCamera = new OrthographicCamera() { LookDirection = dir.ToVector3D(), Position = (System.Windows.Media.Media3D.Point3D)(pos.ToVector3D()), UpDirection = Vector3.UnitZ.ToVector3D(), Width = 100, NearPlaneDistance = 10, FarPlaneDistance = 500, }; } if (lightCamera != null) { var sceneCamera = context.Camera; light.LightViewMatrix = CameraExtensions.GetViewMatrix(lightCamera); light.LightProjectionMatrix = CameraExtensions.GetProjectionMatrix(lightCamera, context.Canvas.ActualWidth / context.Canvas.ActualHeight); this.shadowPassContext.IsShadowPass = true; this.shadowPassContext.Camera = lightCamera; foreach (var e in root) { var model = e as Element3D; if (model != null) { var smodel = model as IThrowingShadow; if (smodel != null) { if (smodel.IsThrowingShadow) { model.Render(this.shadowPassContext); } } } } context.Camera = sceneCamera; } } } this.texShadowMapVariable.SetResource(this.texShadowMapView); //this.texShadowMapVariable.SetResource(this.texColorMapView); this.vShadowMapInfoVariable.Set(new Vector4((float)this.Intensity, (float)this.FactorPCF, (float)this.Bias, 0)); this.vShadowMapSizeVariable.Set(new Vector2(width, height)); //System.Console.WriteLine("ShadowMap rendered!"); context.Canvas.SetDefaultRenderTargets(); }
/// <summary> /// Initializes a new instance of the <see cref="Viewport3DX" /> class. /// </summary> public Viewport3DX() { this.perspectiveCamera = new PerspectiveCamera(); this.orthographicCamera = new OrthographicCamera(); this.perspectiveCamera.Reset(); this.orthographicCamera.Reset(); this.Camera = this.Orthographic ? (ProjectionCamera)this.orthographicCamera : this.perspectiveCamera; //this.Children = new Element3DCollection(); this.rotateHandler = new RotateHandler(this); this.panHandler = new PanHandler(this); this.zoomHandler = new ZoomHandler(this); this.changeFieldOfViewHandler = new ZoomHandler(this, true); this.zoomRectangleHandler = new ZoomRectangleHandler(this); this.CommandBindings.Add(new CommandBinding(ViewportCommands.ZoomExtents, this.ZoomExtentsHandler)); this.CommandBindings.Add(new CommandBinding(ViewportCommands.SetTarget, this.SetTargetHandler)); this.CommandBindings.Add(new CommandBinding(ViewportCommands.Reset, this.ResetHandler)); this.CommandBindings.Add(new CommandBinding(ViewportCommands.Zoom, this.zoomHandler.Execute)); this.CommandBindings.Add(new CommandBinding(ViewportCommands.Pan, this.panHandler.Execute)); this.CommandBindings.Add(new CommandBinding(ViewportCommands.Rotate, this.rotateHandler.Execute)); this.CommandBindings.Add( new CommandBinding(ViewportCommands.ChangeFieldOfView, this.changeFieldOfViewHandler.Execute)); this.CommandBindings.Add( new CommandBinding(ViewportCommands.ZoomRectangle, this.zoomRectangleHandler.Execute)); this.CommandBindings.Add(new CommandBinding(ViewportCommands.BottomView, this.BottomViewHandler)); this.CommandBindings.Add(new CommandBinding(ViewportCommands.TopView, this.TopViewHandler)); this.CommandBindings.Add(new CommandBinding(ViewportCommands.FrontView, this.FrontViewHandler)); this.CommandBindings.Add(new CommandBinding(ViewportCommands.BackView, this.BackViewHandler)); this.CommandBindings.Add(new CommandBinding(ViewportCommands.LeftView, this.LeftViewHandler)); this.CommandBindings.Add(new CommandBinding(ViewportCommands.RightView, this.RightViewHandler)); this.SetDefaultGestures(); this.fpsWatch.Start(); this.renderingEventListener = new RenderingEventListener(this.OnCompositionTargetRendering); this.Loaded += this.ControlLoaded; this.Unloaded += this.ControlUnloaded; }
public void logic(OrthographicCamera camera) { if (_decorsLoaded) checkDecorations(camera); }