// public abstract RenderingView3D FromSource(RenderingSource3D source); public static RenderingView3D FromSource(RenderingSource3D source) { // set view to see all scene with current FOV float radius = source.Bounds.radius * 1.15f; float distance = (float)(radius / (Math.Tan(Math.PI / 4) * 0.5));// +zoom; Vector3 cameraDir = Vector3.Normalize(source.Bounds.max); Vector3 CameraPos = (cameraDir * distance); Matrix view = Matrix.LookAtLH(CameraPos, new Vector3()/*source.Origin*/, new Vector3(0, 1, 0)); Matrix world = Matrix.Translation(-source.Origin); RenderingView3DPer per = new RenderingView3DPer(view, world); per.CameraPos = CameraPos; per.near = distance - radius; if (per.near <= 0) per.near = 0.01f; per.far = distance + radius; per.centre = distance; return per; }
// public abstract RenderingView3D FromSource(RenderingSource3D source); public static RenderingView3D FromSource(RenderingSource3D source) { // set view to see all scene with current FOV float radius = source.Bounds.radius * 1.15f; float distance = (float)(radius / (Math.Tan(Math.PI / 4) * 0.5));// +zoom; Vector3 cameraDir = Vector3.Normalize(source.Bounds.max); Vector3 CameraPos = (cameraDir * distance); Matrix view = Matrix.LookAtLH(CameraPos, new Vector3() /*source.Origin*/, new Vector3(0, 1, 0)); Matrix world = Matrix.Translation(-source.Origin); RenderingView3DPer per = new RenderingView3DPer(view, world); per.CameraPos = CameraPos; per.near = distance - radius; if (per.near <= 0) { per.near = 0.01f; } per.far = distance + radius; per.centre = distance; return(per); }