问题描述
我正在尝试制作一个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 (将#修改为@)