[SetUp] public void Init() { iCamera = GetCameraMock (); iCamera.Moved ().Returns (true); iCamera.NotNullLookTarget ().Returns (true); fCController = GetControllerMock (iCamera); }
/// <summary> /// <see cref="ISceneRenderer.Render"/> /// </summary> public void Render(ICameraController cam, Dictionary<Node, List<Mesh>> visibleMeshesByNode, bool visibleSetChanged, bool texturesChanged, RenderFlags flags, Renderer renderer) { GL.Disable(EnableCap.Texture2D); GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest); GL.Enable(EnableCap.DepthTest); GL.FrontFace(FrontFaceDirection.Ccw); if (flags.HasFlag(RenderFlags.Wireframe)) { GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line); } // If textures changed, we may need to upload some of them to VRAM. if (texturesChanged) { UploadTextures(); } GL.MatrixMode(MatrixMode.Modelview); var view = cam == null ? Matrix4.LookAt(0, 10, 5, 0, 0, 0, 0, 1, 0) : cam.GetView(); GL.MatrixMode(MatrixMode.Modelview); GL.LoadMatrix(ref view); var tmp = InitposeMax.X - InitposeMin.X; tmp = Math.Max(InitposeMax.Y - InitposeMin.Y, tmp); tmp = Math.Max(InitposeMax.Z - InitposeMin.Z, tmp); tmp = 2.0f / tmp; var world = Matrix4.Scale(tmp); world *= Matrix4.CreateTranslation(-(InitposeMin + InitposeMax) * 0.5f); PushWorld(ref world); // var animated = Owner.SceneAnimator.IsAnimationActive; var needAlpha = RecursiveRender(Owner.Raw.RootNode, visibleMeshesByNode, flags, animated); if (flags.HasFlag(RenderFlags.ShowSkeleton) || flags.HasFlag(RenderFlags.ShowNormals)) { //RecursiveRenderNoScale(Owner.Raw.RootNode, visibleMeshesByNode, flags, 1.0f / tmp, animated); } if (needAlpha) { // handle semi-transparent geometry RecursiveRenderWithAlpha(Owner.Raw.RootNode, visibleMeshesByNode, flags, animated); } PopWorld(); // always switch back to FILL GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill); GL.Disable(EnableCap.DepthTest); GL.Disable(EnableCap.Texture2D); GL.Disable(EnableCap.Lighting); }
public MainPresenter(IPlanetFactory planetFactory, ICamera camera, ICameraController cameraController, IWindowManager windowManager, Statistics statistics, ISettings settings) { _planetFactory = planetFactory; _camera = camera; _cameraController = cameraController; _windowManager = windowManager; _statistics = statistics; _settings = settings; _settings.ShouldUpdate = true; }
public CameraPageViewModel(ICameraController cameraController, IModuleConfiguration moduleConfiguration, ICommands moduleCommands) { controller = cameraController; configuration = moduleConfiguration; commands = moduleCommands; configuration.StreamingValueChanged += OnStreamingChanged; UpdateStreamingButtons(configuration.Streaming); Window.Current.VisibilityChanged += OnVisibilityChanged; }
public VideoStreamingService(ICameraController cameraController, IImageEncoder imageEncoder, IModuleConfiguration moduleConfiguration, IWebClient webClient) { encoder = imageEncoder; SendImage += OnSendImage; client = webClient; controller = cameraController; configuration = moduleConfiguration; configuration.StreamingValueChanged += OnStreamingValueChanged; configuration.CurrentVideoSizeChanged += OnCurrentVideoSizeChanged; }
/// <summary> /// 通过当前的场景信息够着渲染对象 /// </summary> /// <param name="scene"></param> public RayCastedGlobe(Scene scene) { this.Shape = scene.Ellipsoid; this._camera = scene.Camera; }
public Scene(float width, float height) { _width = width; _height = height; _camera = new MyCameraController2(width, height); }
/// <summary> /// <see cref="ISceneRenderer.Render"/> /// </summary> public void Render(ICameraController cam, Dictionary<Node, List<Mesh>> visibleMeshesByNode, bool visibleSetChanged, bool texturesChanged, RenderFlags flags, Renderer renderer) { GL.Disable(EnableCap.Texture2D); GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest); GL.Enable(EnableCap.DepthTest); // set fixed-function lighting parameters GL.ShadeModel(ShadingModel.Smooth); GL.LightModel(LightModelParameter.LightModelAmbient, new[] { 0.3f, 0.3f, 0.3f, 1 }); GL.Enable(EnableCap.Lighting); GL.Enable(EnableCap.Light0); if (flags.HasFlag(RenderFlags.Wireframe)) { GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line); } var tmp = InitposeMax.X - InitposeMin.X; tmp = Math.Max(InitposeMax.Y - InitposeMin.Y, tmp); tmp = Math.Max(InitposeMax.Z - InitposeMin.Z, tmp); var scale = 2.0f / tmp; // TODO: migrate general scale and this snippet to camcontroller code if (cam != null) { cam.SetPivot(Owner.Pivot * (float)scale); } var view = cam == null ? Matrix4.LookAt(0, 10, 5, 0, 0, 0, 0, 1, 0) : cam.GetView(); GL.MatrixMode(MatrixMode.Modelview); GL.LoadMatrix(ref view); // light direction var dir = new Vector3(1, 1, 0); var mat = renderer.LightRotation; Vector3.TransformNormal(ref dir, ref mat, out dir); GL.Light(LightName.Light0, LightParameter.Position, new float[] { dir.X, dir.Y, dir.Z, 0 }); // light color var col = new Vector3(1, 1, 1); col *= (0.25f + 1.5f * GraphicsSettings.Default.OutputBrightness / 100.0f) * 1.5f; GL.Light(LightName.Light0, LightParameter.Diffuse, new float[] { col.X, col.Y, col.Z, 1 }); GL.Light(LightName.Light0, LightParameter.Specular, new float[] { col.X, col.Y, col.Z, 1 }); if (flags.HasFlag(RenderFlags.Shaded)) { OverlayLightSource.DrawLightSource(dir); } GL.Scale(scale, scale, scale); // If textures changed, we may need to upload some of them to VRAM. // it is important this happens here and not accidentially while // compiling a displist. if (texturesChanged) { UploadTextures(); } GL.PushMatrix(); // Build and cache Gl displaylists and update only when the scene changes. // when the scene is being animated, this is bad because it changes every // frame anyway. In this case we don't use a displist. var animated = Owner.SceneAnimator.IsAnimationActive; if (_displayList == 0 || visibleSetChanged || texturesChanged || flags != _lastFlags || animated) { _lastFlags = flags; // handle opaque geometry if (!animated) { if (_displayList == 0) { _displayList = GL.GenLists(1); } GL.NewList(_displayList, ListMode.Compile); } var needAlpha = RecursiveRender(Owner.Raw.RootNode, visibleMeshesByNode, flags, animated); if (flags.HasFlag(RenderFlags.ShowSkeleton)) { RecursiveRenderNoScale(Owner.Raw.RootNode, visibleMeshesByNode, flags, 1.0f / scale, animated); } if (flags.HasFlag(RenderFlags.ShowNormals)) { RecursiveRenderNormals(Owner.Raw.RootNode, visibleMeshesByNode, flags, 1.0f / scale, animated, Matrix4.Identity); } if (!animated) { GL.EndList(); } if (needAlpha) { // handle semi-transparent geometry if (!animated) { if (_displayListAlpha == 0) { _displayListAlpha = GL.GenLists(1); } GL.NewList(_displayListAlpha, ListMode.Compile); } RecursiveRenderWithAlpha(Owner.Raw.RootNode, visibleMeshesByNode, flags, animated); if (!animated) { GL.EndList(); } } else if (_displayListAlpha != 0) { GL.DeleteLists(_displayListAlpha, 1); _displayListAlpha = 0; } } if (!animated) { GL.CallList(_displayList); if (_displayListAlpha != 0) { GL.CallList(_displayListAlpha); } } GL.PopMatrix(); // always switch back to FILL GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill); GL.Disable(EnableCap.DepthTest); #if TEST GL.Enable(EnableCap.ColorMaterial); // TEST CODE to visualize mid point (pivot) and origin GL.LoadMatrix(ref view); GL.Begin(BeginMode.Lines); GL.Vertex3((InitposeMin + InitposeMax) * 0.5f * (float)scale); GL.Color3(0.0f, 1.0f, 0.0f); GL.Vertex3(0,0,0); GL.Color3(0.0f, 1.0f, 0.0f); GL.Vertex3((InitposeMin + InitposeMax) * 0.5f * (float)scale); GL.Color3(0.0f, 1.0f, 0.0f); GL.Vertex3(10, 10, 10); GL.Color3(0.0f, 1.0f, 0.0f); GL.End(); #endif GL.Disable(EnableCap.Texture2D); GL.Disable(EnableCap.Lighting); }
/// <summary> /// Call once per frame to render the scene to the current viewport. /// </summary> public void Render(UiState state, ICameraController cam, Renderer target) { RenderFlags flags = 0; if (state.ShowNormals) { flags |= RenderFlags.ShowNormals; } if (state.ShowBBs) { flags |= RenderFlags.ShowBoundingBoxes; } if (state.ShowSkeleton || _overrideSkeleton) { flags |= RenderFlags.ShowSkeleton; } if (state.RenderLit) { flags |= RenderFlags.Shaded; } if (state.RenderTextured) { flags |= RenderFlags.Textured; } if (state.RenderWireframe) { flags |= RenderFlags.Wireframe; } flags |= RenderFlags.ShowGhosts; _wantSetTexturesChanged = false; _renderer.Render(cam, _meshesToShow, _nodesToShowChanged, _texturesChanged, flags, target); lock (_texChangeLock) { if (!_wantSetTexturesChanged) { _texturesChanged = false; } } _nodesToShowChanged = false; }
public void SetCameraController(ICameraController cameraController) { this.cameraController = cameraController; }
private void DrawScene(Scene scene, ICameraController view) { Debug.Assert(scene != null); scene.Render(Window.UiState, view, this); }
/// <summary> /// Draw a scene to a viewport using an ICameraController to specify the camera. /// </summary> /// <param name="view">Active cam controller for this viewport</param> /// <param name="activeTab">Scene to be drawn</param> /// <param name="xs">X-axis starting point of the viewport in range [0,1]</param> /// <param name="ys">Y-axis starting point of the viewport in range [0,1]</param> /// <param name="xe">X-axis end point of the viewport in range [0,1]</param> /// <param name="ye">X-axis end point of the viewport in range [0,1]</param> /// <param name="active"></param> private void DrawViewport(ICameraController view, Tab activeTab, double xs, double ys, double xe, double ye, bool active = false) { // update viewport var w = (double) RenderResolution.Width; var h = (double) RenderResolution.Height; var vw = (int) ((xe - xs)*w); var vh = (int) ((ye - ys)*h); GL.Viewport((int) (xs*w), (int) (ys*h), (int) ((xe - xs)*w), (int) ((ye - ys)*h)); DrawViewportColorsPre(active); var aspectRatio = (float)vw/vh; // set a proper perspective matrix for rendering Matrix4 perspective = Matrix4.CreatePerspectiveFieldOfView(MathHelper.PiOver4, aspectRatio, 0.001f, 100.0f); GL.MatrixMode(MatrixMode.Projection); GL.LoadMatrix(ref perspective); if (activeTab.ActiveScene != null) { DrawScene(activeTab.ActiveScene, view); } }
public void Start() { CameraController = GetInterfaceComponent<ICameraController>(); }
public ZoomCommand(ICameraController camera, Vector3 amount) { _amount = amount; _camera = camera; }
private FollowCameraController GetControllerMock(ICameraController iCamera) { var fCController = Substitute.For<FollowCameraController> (); fCController.SetCameraController (iCamera); return fCController; }
/// <summary> /// <see cref="ISceneRenderer.Render"/> /// </summary> public void Render(ICameraController cam, Dictionary <Node, List <Mesh> > visibleMeshesByNode, bool visibleSetChanged, bool texturesChanged, RenderFlags flags, Renderer renderer) { GL.Disable(EnableCap.Texture2D); GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest); GL.Enable(EnableCap.DepthTest); // set fixed-function lighting parameters GL.ShadeModel(ShadingModel.Smooth); GL.LightModel(LightModelParameter.LightModelAmbient, new[] { 0.3f, 0.3f, 0.3f, 1 }); GL.Enable(EnableCap.Lighting); GL.Enable(EnableCap.Light0); if (flags.HasFlag(RenderFlags.Wireframe)) { GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line); } var tmp = InitposeMax.X - InitposeMin.X; tmp = Math.Max(InitposeMax.Y - InitposeMin.Y, tmp); tmp = Math.Max(InitposeMax.Z - InitposeMin.Z, tmp); var scale = 2.0f / tmp; // TODO: migrate general scale and this snippet to camcontroller code if (cam != null) { cam.SetPivot(Owner.Pivot * (float)scale); } var view = cam == null?Matrix4.LookAt(0, 10, 5, 0, 0, 0, 0, 1, 0) : cam.GetView(); GL.MatrixMode(MatrixMode.Modelview); GL.LoadMatrix(ref view); // light direction var dir = new Vector3(1, 1, 0); var mat = renderer.LightRotation; Vector3.TransformNormal(ref dir, ref mat, out dir); GL.Light(LightName.Light0, LightParameter.Position, new float[] { dir.X, dir.Y, dir.Z, 0 }); // light color var col = new Vector3(1, 1, 1); col *= (0.25f + 1.5f * GraphicsSettings.Default.OutputBrightness / 100.0f) * 1.5f; GL.Light(LightName.Light0, LightParameter.Diffuse, new float[] { col.X, col.Y, col.Z, 1 }); GL.Light(LightName.Light0, LightParameter.Specular, new float[] { col.X, col.Y, col.Z, 1 }); if (flags.HasFlag(RenderFlags.Shaded)) { OverlayLightSource.DrawLightSource(dir); } GL.Scale(scale, scale, scale); // If textures changed, we may need to upload some of them to VRAM. // it is important this happens here and not accidentially while // compiling a displist. if (texturesChanged) { UploadTextures(); } GL.PushMatrix(); // Build and cache Gl displaylists and update only when the scene changes. // when the scene is being animated, this is bad because it changes every // frame anyway. In this case we don't use a displist. var animated = Owner.SceneAnimator.IsAnimationActive; if (_displayList == 0 || visibleSetChanged || texturesChanged || flags != _lastFlags || animated) { _lastFlags = flags; // handle opaque geometry if (!animated) { if (_displayList == 0) { _displayList = GL.GenLists(1); } GL.NewList(_displayList, ListMode.Compile); } var needAlpha = RecursiveRender(Owner.Raw.RootNode, visibleMeshesByNode, flags, animated); if (flags.HasFlag(RenderFlags.ShowSkeleton)) { RecursiveRenderNoScale(Owner.Raw.RootNode, visibleMeshesByNode, flags, 1.0f / scale, animated); } if (flags.HasFlag(RenderFlags.ShowNormals)) { RecursiveRenderNormals(Owner.Raw.RootNode, visibleMeshesByNode, flags, 1.0f / scale, animated, Matrix4.Identity); } if (!animated) { GL.EndList(); } if (needAlpha) { // handle semi-transparent geometry if (!animated) { if (_displayListAlpha == 0) { _displayListAlpha = GL.GenLists(1); } GL.NewList(_displayListAlpha, ListMode.Compile); } RecursiveRenderWithAlpha(Owner.Raw.RootNode, visibleMeshesByNode, flags, animated); if (!animated) { GL.EndList(); } } else if (_displayListAlpha != 0) { GL.DeleteLists(_displayListAlpha, 1); _displayListAlpha = 0; } } if (!animated) { GL.CallList(_displayList); if (_displayListAlpha != 0) { GL.CallList(_displayListAlpha); } } GL.PopMatrix(); // always switch back to FILL GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill); GL.Disable(EnableCap.DepthTest); #if TEST GL.Enable(EnableCap.ColorMaterial); // TEST CODE to visualize mid point (pivot) and origin GL.LoadMatrix(ref view); GL.Begin(BeginMode.Lines); GL.Vertex3((InitposeMin + InitposeMax) * 0.5f * (float)scale); GL.Color3(0.0f, 1.0f, 0.0f); GL.Vertex3(0, 0, 0); GL.Color3(0.0f, 1.0f, 0.0f); GL.Vertex3((InitposeMin + InitposeMax) * 0.5f * (float)scale); GL.Color3(0.0f, 1.0f, 0.0f); GL.Vertex3(10, 10, 10); GL.Color3(0.0f, 1.0f, 0.0f); GL.End(); #endif GL.Disable(EnableCap.Texture2D); GL.Disable(EnableCap.Lighting); }
void ICmpRenderer.Draw(IDrawDevice device) { Canvas canvas = new Canvas(); canvas.Begin(device); Vector2 screenSize = device.TargetSize; ICameraController activeController = this.mainCameraObj.GetComponent <ICameraController>(); VelocityTracker camTracker = this.mainCameraObj.GetComponent <VelocityTracker>(); Transform camTransform = this.mainCameraObj.Transform; Transform targetTransform = this.targetObj.Transform; float camDist = (camTransform.Pos.Xy - targetTransform.Pos.Xy).Length; string activeControllerName = activeController != null?activeController.GetType().Name : "None"; activeControllerName = activeControllerName.Replace("CameraController", ""); // Draw the screen center, so we know what exactly our camera controller is pointing at canvas.State.ColorTint = ColorRgba.Green.WithAlpha(0.5f); canvas.FillCircle(screenSize.X * 0.5f, screenSize.Y * 0.5f, 8.0f); // Draw the camera distance around the screen center canvas.State.ColorTint = ColorRgba.Green.WithAlpha(0.25f); canvas.DrawCircle(screenSize.X * 0.5f, screenSize.Y * 0.5f, camDist); // Draw the camera velocity (movement per second) around the screen center canvas.State.ColorTint = ColorRgba.Green.WithAlpha(0.5f); canvas.DrawLine( screenSize.X * 0.5f, screenSize.Y * 0.5f, screenSize.X * 0.5f + camTracker.Vel.X / Time.SecondsPerFrame, screenSize.Y * 0.5f + camTracker.Vel.Y / Time.SecondsPerFrame); // Draw some info text if (this.infoText == null) { this.infoText = new FormattedText(); this.infoText.MaxWidth = 350; } this.infoText.SourceText = string.Format( "Camera Controller Sample/n/n" + "Use /c44AAFFFFarrow keys/cFFFFFFFF // /c44AAFFFFleft thumbstick/cFFFFFFFF to move./n" + "Use /c44AAFFFFnumber keys 1, 2/cFFFFFFFF // /c44AAFFFFbuttons A, B/cFFFFFFFF to select a Camera Controller./n" + "Use the /c44AAFFFFM key/cFFFFFFFF // /c44AAFFFFbutton X/cFFFFFFFF to toggle movement history./n/n" + "Active Camera Controller:/n/cFF8800FF{0}/cFFFFFFFF", activeControllerName); canvas.State.ColorTint = ColorRgba.White; canvas.DrawText(this.infoText, 10, 10, 0.0f, null, Alignment.TopLeft, true); // Draw state information on the current camera controller if (this.stateText == null) { this.stateText = new FormattedText(); } this.stateText.SourceText = string.Format( "Camera Distance: {0:F}/n" + "Camera Velocity: {1:F}, {2:F}", camDist, camTracker.Vel.X, camTracker.Vel.Y); canvas.State.ColorTint = ColorRgba.White; canvas.DrawText(this.stateText, 10, screenSize.Y - 10, 0.0f, null, Alignment.BottomLeft, true); canvas.End(); }
public override void Clear() { Instance = null; }
private void Awake() { cameraController = GetComponent <ICameraController> (); }
void ICmpUpdatable.OnUpdate() { // Prepare a list of camera controllers, if we don't already have one if (this.cameraControllers == null) { this.cameraControllers = new List <ICameraController>(); // Use Reflection to get a list of all ICameraController classes TypeInfo[] availableCameraControllerTypes = DualityApp.GetAvailDualityTypes(typeof(ICameraController)).ToArray(); foreach (TypeInfo camControllerType in availableCameraControllerTypes) { // Create an instance of each class ICameraController camController = camControllerType.CreateInstanceOf() as ICameraController; if (camController != null) { this.cameraControllers.Add(camController); } } } // Allow the user to select which camera controller to use if (DualityApp.Keyboard.KeyHit(Key.Number1)) { this.ActiveCameraController--; } if (DualityApp.Keyboard.KeyHit(Key.Number2)) { this.ActiveCameraController++; } if (DualityApp.Keyboard.KeyHit(Key.M)) { this.movementHistoryActive = !this.movementHistoryActive; } // Is there a Gamepad we can use? GamepadInput gamepad = DualityApp.Gamepads.FirstOrDefault(g => g.IsAvailable); if (gamepad != null) { if (gamepad.ButtonHit(GamepadButton.A)) { this.ActiveCameraController--; } if (gamepad.ButtonHit(GamepadButton.B)) { this.ActiveCameraController++; } if (gamepad.ButtonHit(GamepadButton.X)) { this.movementHistoryActive = !this.movementHistoryActive; } } // Every 100 ms, draw one visual log entry to document movement if (this.movementHistoryActive) { this.movementHistoryTimer += Time.MillisecondsPerFrame * Time.TimeMult; if (this.movementHistoryTimer > 100.0f) { this.movementHistoryTimer -= 100.0f; Vector2 targetPos = this.targetObj.Transform.Pos.Xy; Vector2 cameraPos = this.mainCameraObj.Transform.Pos.Xy; VisualLogs.Default.DrawPoint( targetPos.X, targetPos.Y, 0.0f) .WithColor(new ColorRgba(255, 128, 0)) .KeepAlive(3000.0f); VisualLogs.Default.DrawPoint( cameraPos.X, cameraPos.Y, 0.0f) .WithColor(new ColorRgba(0, 255, 0)) .KeepAlive(3000.0f); } } }
public virtual void SetCameraController(ICameraController cameraController) { // do nothing }
public SummerReportMatrixBinder(Control control) { _control = control; this._cameraController = new MouseControlCameraController(control); this._projectionController=new BasicProjectionController(control); }
private static void ConfigureCameraDefaults(IMapManager mapManager, IFactionManager factionManger, ICameraController cameraController) { cameraController.ConfigureBounds(0, mapManager.Width, 0, mapManager.Height); cameraController.MoveToPosition(new Vector3(mapManager.Width / 2, 0, mapManager.Height / 2)); }