如何解决当3D对象接近屏幕时反转比例
我正在尝试制作一个3D对象(以前从未从2D位置投影过),以根据其靠近屏幕的Z位置进行缩放。非投影使对象遵循线性路径,并且模糊到x,y和z位置,从而使其看起来像“标尺”,没有该标尺,因此在给定此输入的情况下
var ctx = new ModelDrawContext(_lookAtMatrix);
int windowWidth = 1920;
int windowHeight = 1080;
Vector4 screenPos = camera.projectionMatrix * camera.modelViewMatrix * new Vector4(Position.X,Position.Y,Position.Z,1);
screenPos.X /= screenPos.W;
screenPos.Y /= screenPos.W;
screenPos.Z /= screenPos.W;
int dx = (int)(windowWidth * (screenPos.X + 1) / 2);
int dy = (int)(windowHeight - windowHeight * (screenPos.Y + 1) / 2);
double dz = (1 - 1 * (screenPos.Z + 1) / 2.0);
var identity = Matrix4.Identity;
var Viewport = new Viewport(new Rectanglei(0,1920,1080));
var unprojected = Viewport.Unproject(new Vector3(dx,dy,0.01f),ctx.Projection.ToRaw(),ctx.View.ToRaw(),identity);
var coords3D = unprojected;
var modelTranslationMatrix =
System.Numerics.Matrix4x4.CreateTranslation((float)coords3D.X,(float)coords3D.Y,(float)coords3D.Z);
var sum = System.Numerics.Matrix4x4.CreateScale(0.008f) * System.Numerics.Matrix4x4.CreateRotationZ(0) * modelTranslationMatrix;
ctx.DrawModelInstance(_object,sum);
如何反转比例尺?当物体接近屏幕时,它会从大到小缩放,应该相反。
谢谢!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。