3D 图形中没有填充的球体

发布于 2024-12-02 01:03:21 字数 485 浏览 1 评论 0原文

我想画一个立方体和像这样的圆形(没有填充的球体)。我正在使用 OpenTK

http://farm7.static.flickr.com/6074/6097051938_cb0b798ce0_z。 jpg

我一直遇到如下问题: 我尝试在立方体的顶部画一个圆圈。但是当我们旋转立方体和圆时,圆就变成了椭圆。

我尝试画球体而不是圆。但无法做到如上图所示。 有人有解决办法吗?提前致谢!

这是我的 http://farm7.static.flickr.com/6061/6096573967_22d56b2c2a_z.jpg

I want to draw a cube and circles like this (sphere without fill). I'm using OpenTK

http://farm7.static.flickr.com/6074/6097051938_cb0b798ce0_z.jpg

I've been having issue as below:
I've try to draw a circle at the top of Cube. But when we rotate Oy the cube and the circle, the circle become Ellipse.

I've try to draw sphere instead circle. But can not make it like the image above.
Anybody have the solution? Thanks in advance!

And this is mine
http://farm7.static.flickr.com/6061/6096573967_22d56b2c2a_z.jpg

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浸婚纱 2024-12-09 01:03:21

画一个始终面向相机的圆,画圆很容易。只需创建一个顶点环并使用 GL_LINE_STRIP 来绘制它。
创建一个始终看着相机的变换矩阵有点复杂。这是执行此操作的代码。只需将其设置为您的世界矩阵即可。

Matrix4 createBillbordMatrix(Vector3 position, Vector3 cameraPosition, vector3 up)
{
   Vector3 Z = Vector3.Normalize(direction - cameraPosition);
   Vector3 X = Vector3.Normalize(Vector3.Cross(up, Zaxis));
   Vector3 Y = Vector3.Cross(ZAxis, XAxis);
   Vector3 T = cameraPosition;

   return new Matrix4(X.X, X.Y, X.Z, 0,
                      Y.X, Y.Y, Y.Z, 0,
                      Z.X, Z.Y, Z.Z, 0, 
                      T.X, T.Y, T.Z, 1);  
}

如果您知道矩阵是如何工作的,您应该能够弄清楚它是如何工作的;)。否则不用担心,实施它应该不会有问题。

Draw a circle that always faces the camera, drawing a circle is easy. Just create a ring of vertices and use GL_LINE_STRIP to draw it.
Creating a transformation matrix that always looks at the camera is a bit involved. Here is the code that does this. Simply set this one as your world matrix.

Matrix4 createBillbordMatrix(Vector3 position, Vector3 cameraPosition, vector3 up)
{
   Vector3 Z = Vector3.Normalize(direction - cameraPosition);
   Vector3 X = Vector3.Normalize(Vector3.Cross(up, Zaxis));
   Vector3 Y = Vector3.Cross(ZAxis, XAxis);
   Vector3 T = cameraPosition;

   return new Matrix4(X.X, X.Y, X.Z, 0,
                      Y.X, Y.Y, Y.Z, 0,
                      Z.X, Z.Y, Z.Z, 0, 
                      T.X, T.Y, T.Z, 1);  
}

If you know how matricies work, you should be able to figure it how it works ;). Otherwise don't worry about it, you shouldn't have a problem implementing it.

不忘初心 2024-12-09 01:03:21

在 2D 平面上画一个圆。

使用特殊的 2D 变换,由于这些只是看起来像金属丝网的渲染图并且颜色全部相同,因此您可以最后绘制 2D 部分。

所以:

1. Draw the 3D part

2. Transform the corners to the 2D coords

3. Draw the circles.

我假设你希望圆的形状和大小保持不变,无论立方体如何旋转。

这可能会帮助您开始:
http://www.opentk.com/node/2478

这将是到目前为止比尝试让它帮助您绘制球体(甚至是无阴影的球体)更快。

Draw a circle on a 2D plane.

Use a special 2D transform, and since these are just wire mesh looking renderings and all the same color, you can draw the 2D part last.

So:

1. Draw the 3D part

2. Transform the corners to the 2D coords

3. Draw the circles.

Im assuming you want the circles to be constant shape and size, no matter the rotation of the cube.

This may help get you started:
http://www.opentk.com/node/2478

This will be by far faster than attempting to let it help you draw a sphere, even an unshaded one.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文