我想找个代码在D3D11中创建一个球体,结果发现很多代码都不合适。它们往往只生成顶点,不生成面索引,比如:
http://gamedev.stackexchange.com/questions/16585/how-do-you-programmatically-generate-a-sphere
所以,自己写了一个。
#include "DXUT.h"
#include "wrMesh.h"
#include "wrMath.h"
struct wrSimpleVertexInput
{
DirectX::XMFLOAT3 position;
DirectX::XMFLOAT3 normal;
};
using namespace DirectX;
void CreateSphere(float r, int stacks, int slices, wrSimpleVertexInput** vArr, DWORD** iArr)
{
const float PI = WR_M_PI;
wrSimpleVertexInput*& pV = *vArr;
DWORD*& pI = *iArr;
int nv = (stacks - 1)*slices + 2;
int nf = (stacks-1)*slices * 2;
const int offsetv1 = 1;
const int offsetv2 = nv - slices - 1;
const int offseti1 = 3 * slices;
const int offseti2 = 3 * (nf - slices);
pV = new wrSimpleVertexInput[nv];