按自己的思路整一整程序

来源:互联网 发布:淘宝试用要钱吗 编辑:程序博客网 时间:2024/05/16 10:12

按自己的思路整一整程序,写写伪码。不知道的函数查SDK,养成查SDK的习惯。

 

现在要做的事:
1,copy 地形的代码
2,地形图进行修改
3,贴另外的贴图

DoInit
{
init3D
new Terrain(map,...)
new skybox(map,...)
new camera()

SetTransform(D3DTS_WORLDMATRIX,&matworld)//在 newTerrain中

SetTransform(D3DTS_PROJECTIONMATRIX,&matprojection)
}

DoFrame
{
//要render就必需beginscene
 device->beginscene()
 SetTransform(D3DTS_VIEWMATRIX,&matview)//在camera中
 device->endscene()
}

 

//SetTransform是用来设置告诉设备,世界变换用什么矩阵,视见变换用什么矩阵。即配对的关系。

//D3DXMatrixTransformation是跟据平衡旋转和绽放来得到一个矩阵。在这个程序中 matworld用D3DXMatrixIdentity()来得到。matview用D3DXMartrixLookatLH()来得到。但是在这个程序中是自己写的函数来得到matview的。matprojection是用D3DXMatrixPerspectiveFovLH()来得到的。

 

 

搞清楚一些问题先:

1,左右手坐标

 

 

2,向量叉积方向的确定。右手坐标下比较容易。

/**************************************************************
  两向量叉积公式(共有两个):      
  U   X   V   =   n   *   |U|   *   |V|   *  sinθ;          
  其中,θ为U与V的夹角(0   <=   θ   <=   π);         n是垂直于U和V的单位向量,n的方向由右手定则确定!(问题之所在,之后讨论)              
                             |   i        j     k   
           U   X   V   =     |   Ux       Uy     Uz                 
                             |   Vx       Vy     Vz   |                                                                                            
          其中,i,j,k分别为沿x,y,z轴的单位向量,Ux,Uy,Uz为U的三个分量,Vx,Vy,V为V的三个分量。              
  ***************************************************************       
  疑问就这么来了:              
  现在令         U     =   <1,0,0>,         V     =     <0,1,0>,         则利用公式2得:     U   X   V   =   <0,0,1>。              
  一眼就可以看出:    
  U是+X轴上单位向量,         V是+Y轴上单位向量,         (U   X   V)是+Z轴上单位向量。              
  回到公式1:此时=   90度(即π/2),代入得:         <0,0,1>   =   n   *   1   *   1   *   1   就是   n     =   <0,0,1>      
  也就是:n是+Z轴上单位向量!!              
  好了,         在右手坐标系里,此时的确是U,V,n满足右手定则了;可是换到左手坐标系里就错(左手坐标系的XYZ轴当然是满足左手定则)!  

 

权威的说明在<introduction to 3d game programing>P38

 

You candetermine the vector returned by the cross product by the left hand thumb rule. (We use a left hand rule because we are using a left-handed coordinate system. We would switch to the right hand rule if we were using a right-handed coordinate system.) If you curve the fingers of your left hand in the direction of the first vector toward the second  vector,your thumb points in the direction of the returned vector.

 
原创粉丝点击