|
|
#include "meshproc.h"
struct CUSTOMVERTEX
{
D3DXVECTOR3 position; // The 3D position for the vertex
D3DXVECTOR3 normal; // The surface normal for the vertex
};
inline void mpp(CUSTOMVERTEX* points,long num_points,D3DXMATRIX*ma);
ID3DXMesh* MeshNormalWave(ID3DXMesh * pMesh,FLOAT Yaw,FLOAT Pitch,FLOAT Roll)
{
HRESULT hr;
CUSTOMVERTEX * ver;
void * point;
DWORD len;
D3DXMATRIX pm;
//set up matrix
D3DXMatrixRotationYawPitchRoll( &pm,
Yaw, Pitch,
Roll
);
hr=pMesh->LockVertexBuffer( D3DLOCK_DONOTWAIT,
&point
);
if(FAILED(hr))
{
MessageBox(NULL,"锁定顶点失败",NULL,MB_OK);
return NULL;
}
//get point;
ver=(CUSTOMVERTEX *)point;
//get len
len=pMesh->GetNumVertices();
mpp(ver,len,&pm);
pMesh->UnlockVertexBuffer();
return pMesh;
}
void mpp(CUSTOMVERTEX* points,long num_points,D3DXMATRIX*ma)
{
D3DVECTOR temp_point;//临时的x,y,z
for(DWORD iCount=0;iCount<num_points;iCount++)
{
temp_point.x=points->normal.x * ma->_11 + points->normal.y * ma->_12 +points->normal.z * ma->_13 + ma->_14;
temp_point.y=points->normal.x * ma->_21 + points->normal.y * ma->_22 +points->normal.z * ma->_23 + ma->_24;
temp_point.z=points->normal.x * ma->_31 + points->normal.y * ma->_32 +points->normal.z * ma->_33 + ma->_34;
points->normal.x =temp_point.x;
points->normal.y =temp_point.y;
points->normal.z =temp_point.z;
//由于找不到 顶点与矩阵相乘的函数,所以出此下策....
//上面是旋转法线,在光源不改变的情况下,实现了反光面改变的效果
/* temp_point.x=points->position.x * ma->_11 + points->position.y * ma->_12 +points->position.z * ma->_13 + ma->_14;
temp_point.y=points->position.x * ma->_21 + points->position.y * ma->_22 +points->position.z * ma->_23 + ma->_24;
temp_point.z=points->position.x * ma->_31 + points->position.y * ma->_32 +points->position.z * ma->_33 + ma->_34;
points->position.x =temp_point.x;
points->position.y =temp_point.y;
points->position.z =temp_point.z;
*/ //这里是旋转物体,但是只有傻瓜这么做, 不执行,帧速为30, 执行后,帧速为17
//想不通了,为什么使用device->SetTansform()方法就那么快呢???
points++; //指针后移,便历所有的点
}
}
执行了以上代码后,帧速从 400 直接降到 30
暴寒[em7] [em7] [em7] [em7]
如果要实现旋转法线的效果,是否有其他方法
请指教 |
|