光线拾取 - 从俯仰和偏航获取方向
我试图从屏幕中心投射光线并检查与物体的碰撞。
渲染时,我使用这些调用来设置相机:
GL11.glRotated(mPitch, 1, 0, 0);
GL11.glRotated(mYaw, 0, 1, 0);
GL11.glTranslated(mPositionX, mPositionY, mPositionZ);
但是,我在创建光线时遇到了问题。这是我到目前为止的代码:
ray.origin = new Vector(mPositionX, mPositionY, mPositionZ);
ray.direction = new Vector(?, ?, ?);
我的问题是:我应该在问号点中放入什么?即如何从俯仰和滚动创建射线方向?
I am attempting to cast a ray from the center of the screen and check for collisions with objects.
When rendering, I use these calls to set up the camera:
GL11.glRotated(mPitch, 1, 0, 0);
GL11.glRotated(mYaw, 0, 1, 0);
GL11.glTranslated(mPositionX, mPositionY, mPositionZ);
I am having trouble creating the ray, however. This is the code I have so far:
ray.origin = new Vector(mPositionX, mPositionY, mPositionZ);
ray.direction = new Vector(?, ?, ?);
My question is: what should I put in the question mark spots? I.e. how can I create the ray direction from the pitch and roll?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最近回答了一个与你的问题不同的问题。所以我建议你阅读以下内容:点和角度的 3d 坐标
这也适用于你的问题,只是你不想要一个点,而是一条射线。好吧,请记住,可以假设一个点是从原点开始的位移向量,并且射线定义为
在您的情况下,
s
是相机位置,v
将是相对于相机位置的点。剩下的你自己算(或者如果事情还不清楚的话就问)。I answered a question not unlike your's just recently. So I suggest you read this: 3d coordinate from point and angles
This applies to your question as well, only that you don't want just a point, but a ray. Well, remember that a point can be assumed a displacement-from-origin vector and that a ray is defined as
In your case,
s
is the camera position, andv
would be a point relative to the camera's position. You figure the rest (or ask, if things are still unclear).