几何形状 [英] Geometric Shapes

查看:68
本文介绍了几何形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何绘制一个立方体,请帮助我.感谢您的帮助

How can I draw a cube please help me. thanks for you assistance

推荐答案


  1. 我们不会为您做作业.
  2. 您的作业不是在画一个立方体.您只需根据给定的参数在内存中构造一个.


使用 SDL 绘制到屏幕上.您可以通过用三角形(每边2个三角形)构造立方体的每一侧来绘制一个立方体.进行一些3D数学运算,以将多维数据集旋转到正确的观看位置并具有正确的投影.然后将每个三角形的每个像素绘制到缓冲区.如果已经在缓冲区上绘制了一个点,并且z坐标比可能要绘制的点更近,则不要绘制新的点.如果要在立方体上显示图像而不是纯色,请将图像映射到每个三角形,以便将屏幕上的每个像素转换为图像中的相应像素.并且,如果要添加照明,请创建光源并进行一些计算,以查看光如何与每个三角形的表面以及观察相机交互.最后,在将所有内容绘制到该缓冲区之后,请使用SDL将其传输到屏幕.

那是很难的方法.有各种各样的库可以简化操作(SDL实际上有一些简化此任务的方法).如果您是绝对的初学者,我建议您使用XNA,但随后您必须学习一些C#. OpenGL是另一个选择(我相信SDL实际上是在OpenGL之上构建的).
Use SDL to draw to the screen. You can draw a cube by constructing each side of it with triangles (2 triangles to a side). Do some 3D math to rotate the cube into the correct viewing position and with the correct projection. Then draw each pixel of each triangle to a buffer. If a point was already drawn to the buffer and the z-coordinate is closer than the one that may get drawn, then don''t draw the new one. If you want an image on the cube rather than a solid color, map an image to each triangle so each pixel on the screen can be transformed to the corresponding pixel in the image. And if you want to add lighting, create a light source and do some calculations to see how the light interacts with the surface of each triangle and the viewing camera. Finally, once you''ve finished drawing everything to that buffer, transfer it to the screen using SDL.

That''s the hard way of doing it. There are various libraries out there for simplifying things (SDL actually has some ways of simplifying this task). If you are an absolute beginner, I recommend XNA, but then you''d have to learn some C#. OpenGL is another option (I believe SDL is actually built on top of OpenGL).


这是一个很难回答的问题.您想在哪里绘制它?您希望它移动吗? GDI有绘制线的方法,可以使它们看起来像一个立方体,但是您需要使用DirectX来绘制可以在3D中移动的实际3D形状.
This is a hard question to answer. Where do you want to draw it ? Do you expect it to move ? GDI has methods for drawing lines, which can be made to look like a cube, but you''d need to use DirectX to draw an actual 3D shape that can be moved in 3D.


这篇关于几何形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆