Morph Shpere to Cube

 
                                                                             UBITest_2: DirectX 3D Morphing
 
Goal
 
Create a program that performs morphing of a 3D mesh from a sphere mesh to a cube mesh in real-time while respecting the lighting conditions.
 
Details                
 
In this program, a 3D mesh object will need to morph from a sphere to a cube using linear interpolation. The mesh object must be created with a large number of faces to respect the lighting conditions. The user will be able to rotate around the cube in order to watch the mesh morph and see the lighting adapt to the mesh. The time of the morphing can be pre-determined but it must be slow enough so we can see the transition.
 
Methodology
 
You will need to use DirectX to setup a basic rendering framework that supports vertex shaders. You will need to research on DirectX functionalities, vertex shaders and vertex morphing. A few resources are provided at the end of this document. In addition to the web site, you can consult the DirectX SDK documentation.
 
The program must be able to generate a textured mesh that has a lot of faces. The shape of the mesh object must start as a sphere and morph to a cube using linear interpolation. From the cube, it will morph back linearly to a sphere. You can use any texture that you like.
 
The program must light the scene using a directional light and an ambient light. The lighting must affect the 3D object as it morphs between the sphere and the cube.
 
For the vertex morphing, you will have to use linear interpolation on the vertices. For the lighting, you will have to use linear interpolation on the normals (approximation is acceptable).
 
The camera should be able to rotate around the 3D mesh to verify the lighting. The rotation can be done with the mouse or with arrows.
 
Requirements
 
l         Draw the mesh on screen (sphere morphing to cube)
l         Using one directional light and one ambient light
l         Using vertex shaders
l         Morph smoothly from sphere to cube and vice-versa
l         Camera can rotate around the mesh by mouse or key-board input
 
Resources
 
DirectX resources center
 
DirectX documentation
 
Vertex shaders
 
Vertex morphing
 
這時ubi的一道面試題,咋一看挺複雜,但是想想還是很容易實現的。
 圓和內切正方體有這樣的關係: 半徑^2 = (1/2邊長)^2 * 3; 也就是說,如果圓的半徑是1.732,那麼長方體的邊長是2。
之vertex shader中,對超出正方體的頂點,以該頂點和投影到響應正方體面上的點作插值,就可以了。
比如:
 if( vert.pos.y>1 )
 {
  float h = lerp( 1.0,vert.pos.y,factor);
  vert.pos.y = h;
 }

 -----〉

代碼放在http://file.mofile.com/  提取碼5026797624383246,有興趣可以看一下。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章