public Ray3 GetGlobalRayForHmgnPointer(float aspectRatio, Vector2 hmgnPointerPos) { var frame = GetGlobalFrame(); var proj = GetProps().Projection; var halfHeight = proj.ZNear * MathHelper.Tan(proj.Fov / 2f); var halfWidth = halfHeight * aspectRatio; var worldPoint = frame.Eye + frame.Forward * proj.ZNear + frame.Right * halfWidth * hmgnPointerPos.X + frame.Up * halfHeight * hmgnPointerPos.Y; return(new Ray3(worldPoint, worldPoint - frame.Eye)); }
private void ResizeViewports() { var numRows = tableLayout.ViewportIndices.GetLength(0); var numCols = tableLayout.ViewportIndices.GetLength(1); var offsets = new Vector2[numRows + 1, numCols + 1]; var rowOffset = 0f; for (int r = 0; r < numRows + 1; r++) { var colOffset = 0f; for (int c = 0; c < numCols + 1; c++) { offsets[r, c] = new Vector2(colOffset, rowOffset); if (c < numCols) { colOffset += ToActualPixels(tableLayout.ColumnWidths[c], Width); } } if (r < numRows) { rowOffset += ToActualPixels(tableLayout.RowHeights[r], Height); } } for (int i = 0; i < Viewports.Count; i++) { var viewport = Viewports[i]; int startRow, endRow, startCol, endCol; if (TryGetViewportBorderCells(i, out startRow, out endRow, out startCol, out endCol)) { var topLeft = offsets[startRow, startCol]; var bottomRight = offsets[endRow + 1, endCol + 1]; var size = bottomRight - topLeft; viewport.OnResized(topLeft.X, topLeft.Y, size.X, size.Y); } else { viewport.OnResized(0, 0, 0, 0); } } }
private static Vector2 Hmgnize(Vector2 v) { return(new Vector2( v.X / Screen.width * 2f - 1f, 1f - v.Y * 2f / Screen.height)); }
private static Vector2 Normalize(Vector2 v) { return(new Vector2( 2f * (v.X - Screen.width / 2f) / Screen.height, 1f - v.Y * 2f / Screen.height)); }
private static IntVector2 Round(Vector2 v) => new IntVector2(Round(v.X), Round(v.Y));