01-22-2024, 05:52 PM
In you want all the objects in the scene to preserve their site regarding of the distance to the camera, then you can use orthographic camera (camera.CameraType = BaseCamera.CameraTypes.OrthographicCamera).
If you want to use perspective projection but want to preserve the size of only some of the objects, you need to scale those objects so after the projection is applied, the size will remain the same.
This can be done the in the following way:
1) calculate the camera zoom factor:
2) get the distance of the object to the camera:
3) Calculate the per-object zoom factor:
Use objectScaleFactor in the ScaleTransform3D.
When also using Ab3d.DXEngine, then you can also use object instancing where you specify the object size in screen-space coordinates. This allows rendering millions of meshes (also spheres) with screen-space size. See the "Extreme performance / Screen-space scaled instancing" sample in the Ab3d.DXEngine samples (https://github.com/ab4d/Ab3d.DXEngine.Wpf.Samples)
If you want to use perspective projection but want to preserve the size of only some of the objects, you need to scale those objects so after the projection is applied, the size will remain the same.
This can be done the in the following way:
1) calculate the camera zoom factor:
Code:
var cameraZoomFactor = 1 / Math.Tan(SharpDX.MathUtil.DegreesToRadians((float)Camera1.FieldOfView));
Code:
var cameraPosition = Camera1.GetCameraPosition();
var distance = (objectCenterPosition - cameraPosition).Length;
Code:
var objectScaleFactor = distance / cameraZoomFactor;
Use objectScaleFactor in the ScaleTransform3D.
When also using Ab3d.DXEngine, then you can also use object instancing where you specify the object size in screen-space coordinates. This allows rendering millions of meshes (also spheres) with screen-space size. See the "Extreme performance / Screen-space scaled instancing" sample in the Ab3d.DXEngine samples (https://github.com/ab4d/Ab3d.DXEngine.Wpf.Samples)
Andrej Benedik