Changes

Jump to: navigation, search

GAM670/DPS905 Weekly Schedule 20121

6,229 bytes added, 20:02, 21 February 2012
This Week
*: Custom Mesh
*:: Create a Mesh
*:: FVF settingsAPIGraphic.h code<syntaxhighlight lang="cpp">template <class T = Vertex, class I = Index>class APICustomMesh : public iAPIGraphic, public APIBase {  unsigned nSubsets; // number of subsets unsigned nPrimitives; // number of primitives unsigned* attribute; // points to mesh's attribute list I* index; // points to mesh's array of indices unsigned iIndex; // number of indices currently saved unsigned nIndices; // number of indices in the mesh T* vertex; // points to mesh's array of vertices unsigned iVertex; // number of vertices currently saved unsigned nVertices; // number of vertices in the mesh LPD3DXMESH apiMesh; // set of vertices, indices  protected: virtual ~APICustomMesh(); void setup();  public: APICustomMesh(unsigned*, int, int, int, int); APICustomMesh(const APICustomMesh& v); APICustomMesh& operator=(const APICustomMesh& v); APICustomMesh* clone() const { return new APICustomMesh(*this); } unsigned add(const T& v); void add(unsigned); void draw(unsigned); void suspend(); void release() { suspend(); } void Delete() const { delete this; }};</syntaxhighlight>*:: APIGraphic.cpp - APIGraphic<syntaxhighlight lang="cpp">template <class T, class I>APICustomMesh<T, I>::APICustomMesh(unsigned* a, int np, int ni, int nv, int ns) : nSubsets(ns), nPrimitives(np), nIndices(ni), nVertices(nv), iIndex(0), iVertex(0) {  attribute = new unsigned[nPrimitives]; for (unsigned i = 0; i < nPrimitives; i++) attribute[i] = a[i];  index = new I[nIndices]; vertex = new T[nVertices];  apiMesh = nullptr;}</syntaxhighlight>*:: APIGraphic.cpp - add()<syntaxhighlight lang="cpp">template <class T, class I>unsigned APICustomMesh<T, I>::add(const T& v) {  unsigned i = iVertex;  if (vertex && iVertex < nVertices) vertex[iVertex++] = v;  return i;}</syntaxhighlight><syntaxhighlight lang="cpp">template <class T, class I>void APICustomMesh<T, I>::add(unsigned v) {  if (index && iIndex < nIndices) index[iIndex++] = v;}</syntaxhighlight>*:: APIGraphic.cpp - setup()<syntaxhighlight lang="cpp">template <class T, class I>void APICustomMesh<T, I>::setup() {  T *pv; I *pi; DWORD *pa; nIndices = iIndex; nVertices = iVertex;  // create an empty mesh and lock its buffers if (FAILED(D3DXCreateMesh(nPrimitives, nVertices, 0, APIVertexDeclaration<T>::format(), d3dd, &apiMesh))) { error(L"APIMesh::14 Couldn\'t create the empty mesh"); apiMesh = nullptr; } else if (FAILED(apiMesh->LockVertexBuffer(0, (void**)&pv))) { error(L"APIMesh:: 15 Couldn\'t lock vertex buffer"); release(); } else if (FAILED(apiMesh->LockIndexBuffer(0, (void**)&pi))) { error(L"APIMesh::16 Couldn\'t lock index buffer"); release(); } else if (FAILED(apiMesh->LockAttributeBuffer(0, &pa))) { error(L"APIMesh::17 Couldn\'t lock attribute buffer"); release(); } else { // populate the newly created Vertex Buffer for (unsigned i = 0; i < nVertices; i++) vertex[i].populate((void**)&pv); apiMesh->UnlockVertexBuffer(); // populate the newly created Index Buffer for (unsigned i = 0; i < nIndices; i++) pi[i] = index[i]; apiMesh->UnlockIndexBuffer(); // Populate the newly created Attribute Buffer for (unsigned i = 0; i < nPrimitives; i++) pa[i] = attribute[i]; apiMesh->UnlockAttributeBuffer(); }}</syntaxhighlight>*:: APIGraphic.cpp - DrawSubset()<syntaxhighlight lang="cpp">template <class T, class I>void APICustomMesh<T, I>::draw(unsigned iSubset) {  // if mesh doesn't exist, set it up first if (!apiMesh) setup();  if (apiMesh) apiMesh->DrawSubset(iSubset);}</syntaxhighlight>
*::: DrawIndexedPrimitive parameters
*:: APIGraphic.h codecpp - suspend()<syntaxhighlight lang="cpp">template <class T, class I>void APICustomMesh<T, I>::suspend() {  // release the interface to the mesh if (apiMesh) { apiMesh->Release(); apiMesh = nullptr; }}</syntaxhighlight>*:: APIGraphic.cpp - ~APIGraphic<syntaxhighlight lang="cpp">template <class T, class I>APICustomMesh<T, I>::~APICustomMesh() {  release(); if (attribute) delete [] attribute; if (index) delete [] index; if (vertex) delete [] vertex;}</syntaxhighlight>
*: X File
*:: Create Mesh from File
* Billboards
*: definition, purpose of a billboard
<syntaxhighlight lang="cpp">
void Billboard::render(unsigned) {
 
Vector h, u, r, p = position();
Camera* camera = *(Camera**)(Camera::getCurrent());
Vector cameraPosition = camera->position();
Vector cameraHeading = ::normal(camera->orientation('z'));
Vector cameraUp = ::normal(camera->orientation('y'));
switch (type) {
// ... see below
}
Matrix rot(r.x, r.y, r.z, 0,
u.x, u.y, u.z, 0,
h.x, h.y, h.z, 0,
0, 0, 0, 1);
orient(rot);
 
Object::render(0);
}
</syntaxhighlight>
*: types of billboards
*:: screen-aligned - useful for annotation text, lens flares
*::: normal is opposite to camera heading
*::: up is camera->up
<syntaxhighlight lang="cpp">
case SCREEN:
h = cameraHeading; // fixed
u = cameraUp; // up is fixed
r = cross(u, h);
break;
</syntaxhighlight>
*:: axial - useful for cylindrical symmetry - trees (textured object does not face straight on)
*::: up is fixed
*::: normal faces the viewer as much as possible
<syntaxhighlight lang="cpp">
case AXIAL:
h = ::normal(position() - cameraPosition); // heading is open to change
u = Vector(0, 1, 0); // up axis is fixed
r = cross(u, h);
h = cross(u, r);
break;
</syntaxhighlight>
*:: view_plane - no distortion - useful for
*::: normal is fixed (opposite to camera heading)
*::: up is open to change
<syntaxhighlight lang="cpp">
case VIEW_PLANE:
h = cameraHeading; // heading is fixed
u = Vector(0, 1, 0); // up is open to change
r = cross(u, h);
u = cross(h, r);
break;
</syntaxhighlight>
*:: viewpoint - simulates distortion due to perspective projection - useful for clouds
<syntaxhighlight lang="cpp">
case VIEWPOINT:
h = ::normal(position() - cameraPosition); // heading is fixed
u = Vector(0, 1, 0); // up is open to change
r = cross(u, h);
u = cross(h, r);
break;
</syntaxhighlight>
*::: normal is fixed (difference between viewpoint position and camera heading)
*::: up is open to change
*:: texture creation
*:: APITexture::SetSamplerState()
<syntaxhighlight lang="cpp">
</syntaxhighlight>
* DirectX Errors
*: DirectX Utilities - Lookup Tool
*: APIDisplay::restore() example
<syntaxhighlight lang="cpp">
</syntaxhighlight>
=== To Do ===

Navigation menu