154
edits
Changes
→GAM670/DPS905 -- Weekly Schedule 20121
=== Resources ===
== Week 7 - Feb 20 ==
=== This Week ===
* Effects Framework
** techniques
*: passes
* Source Code
: APIBase.h
<syntaxhighlight lang="cpp">
static ID3DXEffect* effect; // points to effects framework
</syntaxhighlight>
: APIBase.cpp
<syntaxhighlight lang="cpp">
ID3DXEffect* APIBase::effect = nullptr; // effects framework
</syntaxhighlight>
: APIDisplay.h
<syntaxhighlight lang="cpp">
// Effects Framework handles
D3DXHANDLE viewProjection; // view * projection
D3DXHANDLE viewPoint; // camera viewpoint
D3DXHANDLE ambient; // global ambient color
D3DXHANDLE ambientHandle; // current ambient reflectivity
D3DXHANDLE diffuseHandle; // current diffuse reflectivity
D3DXHANDLE specularHandle; // current specular reflectivity
D3DXHANDLE powerHandle; // current shininess coefficient
D3DXHANDLE worldHandle; // current world transformation
</syntaxhighlight>
<syntaxhighlight lang="cpp">
void beginEffect(const char*, unsigned&);
void beginPass(unsigned);
void endPass();
void endEffect();
</syntaxhighlight>
: APIDisplay.cpp - APIDisplay()
<syntaxhighlight lang="cpp">
viewProjection = nullptr;
viewPoint = nullptr;
ambient = nullptr;
ambientHandle = nullptr;
diffuseHandle = nullptr;
specularHandle = nullptr;
powerHandle = nullptr;
worldHandle = nullptr;
</syntaxhighlight>
: APIDisplay.cpp - setup()
<syntaxhighlight lang="cpp">
LPD3DXBUFFER errorBuffer = NULL;
</syntaxhighlight>
<syntaxhighlight lang="cpp">
// create the effects framework
else if (FAILED(D3DXCreateEffectFromFile(d3dd, EFFECT_FILE, 0,
0, D3DXSHADER_DEBUG, 0, &effect, &errorBuffer))) {
release();
error(L"APIDisplay::17 Unable to create the effects framework");
}
</syntaxhighlight>
<syntaxhighlight lang="cpp">
if (errorBuffer) errorBuffer->Release();
viewProjection = effect->GetParameterByName(0, "viewProjection");
viewPoint = effect->GetParameterByName(0, "viewPoint");
ambient = effect->GetParameterByName(0, "ambient");
worldHandle = effect->GetParameterByName(0, "world");
ambientHandle = effect->GetParameterByName(0, "material.ambient");
diffuseHandle = effect->GetParameterByName(0, "material.diffuse");
specularHandle = effect->GetParameterByName(0, "material.specular");
powerHandle = effect->GetParameterByName(0, "material.power");
</syntaxhighlight>
: APIDisplay.cpp - beginDrawFrame()
<syntaxhighlight lang="cpp">
Matrix& v = *((Matrix*)view);
Matrix viewprojection = v * projection;
Vector heading(v.m13, v.m23, v.m33);
effect->SetMatrix(viewProjection, (D3DXMATRIX*)&viewprojection);
effect->SetVector(viewPoint, (D3DXVECTOR4*)&heading);
</syntaxhighlight>
<syntaxhighlight lang="cpp">
Colour colour(red, green, blue);
effect->SetVector(ambient, (D3DXVECTOR4*)&colour);
</syntaxhighlight>
: APIDisplay.cpp - beginEffect()
<syntaxhighlight lang="cpp">
void APIDisplay::beginEffect(const char* technique, unsigned& nPasses) {
D3DXHANDLE techniqueHandle = effect->GetTechniqueByName(technique);
effect->SetTechnique(techniqueHandle);
effect->Begin(&nPasses, 0);
}
</syntaxhighlight>
: APIDisplay.cpp - beginPass()
<syntaxhighlight lang="cpp">
void APIDisplay::beginPass(unsigned i) {
effect->BeginPass(i);
}
</syntaxhighlight>
: APIDisplay.cpp - endPass()
<syntaxhighlight lang="cpp">
void APIDisplay::endPass() {
effect->EndPass();
}
</syntaxhighlight>
: APIDisplay.cpp - endEffect()
<syntaxhighlight lang="cpp">
void APIDisplay::endEffect() {
effect->End();
}
</syntaxhighlight>
: APIDisplay.cpp - setWorld()
<syntaxhighlight lang="cpp">
effect->SetMatrix(worldHandle, (D3DXMATRIX*)world);
</syntaxhighlight>
: APIDisplay.cpp - setReflectivity()
<syntaxhighlight lang="cpp">
effect->SetVector(ambientHandle, (D3DXVECTOR4*)&r.ambient);
effect->SetVector(diffuseHandle, (D3DXVECTOR4*)&r.diffuse);
effect->SetVector(specularHandle, (D3DXVECTOR4*)&r.specular);
effect->SetFloat(powerHandle, r.power);
effect->CommitChanges();
</syntaxhighlight>
: APIDisplay.cpp - release()
<syntaxhighlight lang="cpp">
if (effect) {
effect->Release();
effect = NULL;
}
</syntaxhighlight>
<syntaxhighlight lang="cpp">
</syntaxhighlight>
<syntaxhighlight lang="cpp">
</syntaxhighlight>
<syntaxhighlight lang="cpp">
</syntaxhighlight>
<syntaxhighlight lang="cpp">
</syntaxhighlight>
=== To Do ===
=== Resources ===
<!--
== Week 8 - Mar 4 ==
=== This Week ===