internal void VRenderDiagnostics(Cv_CameraNode camera, Cv_Renderer renderer) { if (camera == null) { return; } GamePhysics.VRenderDiagnostics(camera, renderer); }
public Cv_PlayerView(Cv_Player player, Vector2?size, Vector2 startPos, SpriteBatch spriteBatch = null) { m_ID = Cv_GameViewID.INVALID_GAMEVIEW; GameState = Cv_GameState.Initializing; RegisterEventListeners(); PlayerIdx = player; ScreenElements = new List <Cv_ScreenElement>(); m_bAreSoundsPaused = false; Renderer = new Cv_Renderer(spriteBatch); if (size == null) { Renderer.ScreenSizePercent = new Vector2(1, 1); Renderer.ScreenWidth = CaravelApp.Instance.Graphics.PreferredBackBufferWidth; Renderer.ScreenHeight = CaravelApp.Instance.Graphics.PreferredBackBufferHeight; } else { Renderer.ScreenSizePercent = size.Value; Renderer.ScreenWidth = (int)(size.Value.X * CaravelApp.Instance.Graphics.PreferredBackBufferWidth); Renderer.ScreenHeight = (int)(size.Value.Y * CaravelApp.Instance.Graphics.PreferredBackBufferHeight); } Renderer.ScreenOriginPercent = startPos; Renderer.VirtualWidth = Renderer.ScreenWidth; Renderer.VirtualHeight = Renderer.ScreenHeight; Renderer.StartX = (int)(startPos.X * CaravelApp.Instance.Graphics.PreferredBackBufferWidth); Renderer.StartY = (int)(startPos.Y * CaravelApp.Instance.Graphics.PreferredBackBufferHeight); Renderer.Initialize(); Cv_DrawUtils.Initialize(); ListenerEntity = null; Scene = CaravelApp.Instance.Scene; }
public abstract void VOnPostRender(Cv_Renderer renderer);
public abstract void VOnRender(float time, float elapsedTime, Cv_Renderer renderer);
public bool Pick(Cv_Renderer renderer, Vector2 screenPosition, List <Cv_EntityID> entities) { var camMatrix = renderer.CamMatrix; var worldTransform = CaravelApp.Instance.Scene.Transform; var pos = new Vector2(worldTransform.Position.X, worldTransform.Position.Y); var rot = worldTransform.Rotation; var scale = worldTransform.Scale; Vector3 tmpScale; Quaternion tmpQuat; //We don't care about these but we need them for compatibility with older .NET versions Vector3 camPos; camMatrix.Decompose(out tmpScale, out tmpQuat, out camPos); if (Parallax != 1) { var zoomFactor = ((1 + (((tmpScale.X / renderer.Transform.Scale.X) - 1) * Parallax)) / (tmpScale.X / renderer.Transform.Scale.X)); scale = scale * zoomFactor; //Magic formula pos += ((Parallax - 1) * new Vector2(camPos.X, camPos.Y)); pos += ((new Vector2(worldTransform.Position.X, worldTransform.Position.Y)) * (1 - zoomFactor) * (Parallax - 1)); } var transformedVertices = new List <Vector2>(); var point1 = new Vector2(-(worldTransform.Origin.X * Width * scale.X), -(worldTransform.Origin.Y * Height * scale.Y)); var point2 = new Vector2(point1.X + (Width * scale.X), point1.Y); var point3 = new Vector2(point2.X, point1.Y + (Height * scale.Y)); var point4 = new Vector2(point1.X, point3.Y); Matrix rotMat = Matrix.CreateRotationZ(rot); point1 = Vector2.Transform(point1, rotMat); point2 = Vector2.Transform(point2, rotMat); point3 = Vector2.Transform(point3, rotMat); point4 = Vector2.Transform(point4, rotMat); point1 += pos; point2 += pos; point3 += pos; point4 += pos; transformedVertices.Add(point1); transformedVertices.Add(point2); transformedVertices.Add(point3); transformedVertices.Add(point4); var invertedTransform = Matrix.Invert(camMatrix); var worldPoint = Vector2.Transform(screenPosition, invertedTransform); if (Cv_DrawUtils.PointInPolygon(worldPoint, transformedVertices)) { entities.Add(Owner.ID); return(true); } else { return(false); } }
public void DrawSelectionHighlight(Cv_Renderer renderer) { var scene = CaravelApp.Instance.Scene; var pos = scene.Transform.Position; var rot = scene.Transform.Rotation; var scale = scene.Transform.Scale; //Draws the yellow contour when an entity is selected in the editor if (scene.Caravel.EditorRunning && scene.EditorSelectedEntity == Owner.ID) { var camTransf = scene.Camera.GetViewTransform(renderer.VirtualWidth, renderer.VirtualHeight, Cv_Transform.Identity); if (Parallax != 1 && Parallax > 0) { var zoomFactor = ((1 + ((scene.Camera.Zoom - 1) * Parallax)) / scene.Camera.Zoom); scale = scale * zoomFactor; //Magic formula pos += ((Parallax - 1) * new Vector3(camTransf.Position.X, camTransf.Position.Y, 0)); pos += ((new Vector3(scene.Transform.Position.X, scene.Transform.Position.Y, 0)) * (1 - zoomFactor) * (Parallax - 1)); } var noCamera = Parallax == 0; var rotMatrixZ = Matrix.CreateRotationZ(rot); Vector2 point1; Vector2 point2; List <Vector2> points = new List <Vector2>(); var width = Width * scale.X; var height = Height * scale.Y; points.Add(new Vector2(0, 0)); points.Add(new Vector2(width, 0)); points.Add(new Vector2(width, height)); points.Add(new Vector2(0, height)); for (int i = 0, j = 1; i < points.Count; i++, j++) { if (j >= points.Count) { j = 0; } point1 = new Vector2(points[i].X, points[i].Y); point2 = new Vector2(points[j].X, points[j].Y); point1 -= new Vector2(scene.Transform.Origin.X * width, scene.Transform.Origin.Y * height); point2 -= new Vector2(scene.Transform.Origin.X * width, scene.Transform.Origin.Y * height); point1 = Vector2.Transform(point1, rotMatrixZ); point2 = Vector2.Transform(point2, rotMatrixZ); point1 += new Vector2(pos.X, pos.Y); point2 += new Vector2(pos.X, pos.Y); var thickness = (int)Math.Ceiling(3 / scene.Camera.Zoom); if (thickness <= 0) { thickness = 1; } Cv_DrawUtils.DrawLine(renderer, point1, point2, thickness, Cv_Renderer.MaxLayers - 1, Color.Yellow, noCamera); } } }
// Debugging public abstract void VRenderDiagnostics(Cv_CameraNode camera, Cv_Renderer renderer);