Advertisement Jump to content
Sign in to follow this  
newtechnology

SkinnedMesh problem

This topic is 1868 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement

Thanks for sharing.

 

Did you have anything else?  Any other information you’d like to provide?

 

 

L. Spiro

Edited by L. Spiro

Share this post


Link to post
Share on other sites
#ifndef SKINNED_MESH_RENDERER_H
#define SKINNED_MESH_RENDERER_H
 
class SkinnedMeshRenderer
{
private:
SkinnedMesh* mSkinnedMesh;
DirLight mLight;
Mtrl     mWhiteMtrl;
IDirect3DTexture9* mTex;
 
ID3DXEffect* mFX;
D3DXHANDLE   mhTech;
D3DXHANDLE   mhWVP;
D3DXHANDLE   mhWorldInvTrans;
D3DXHANDLE   mhFinalXForms;
D3DXHANDLE   mhEyePos;
D3DXHANDLE   mhWorld;
D3DXHANDLE   mhTex;
D3DXHANDLE   mhMtrl;
D3DXHANDLE   mhLight;
public:
SkinnedMeshRenderer();
~SkinnedMeshRenderer();
 
 
void DrawScene();
void UpdateScene(float &dt);
void BuildFX();
void Init();
};
 
#endif

.cpp

SkinnedMeshRenderer::SkinnedMeshRenderer()
{
mFX = 0;
mTex = 0;
mSkinnedMesh = 0;
 
 
 
}
 
SkinnedMeshRenderer::~SkinnedMeshRenderer()
{
ReleaseCOM(mFX);
ReleaseCOM(mTex);
 
delete mSkinnedMesh;
}
 
void SkinnedMeshRenderer::BuildFX()
{
ID3DXBuffer* errors = 0;
D3DXCreateEffectFromFile(pDevice, "Main\\Shaders\\vblend2.fx", 
0, 0, D3DXSHADER_DEBUG, 0, &mFX, &errors);
if(errors)
MessageBox(0, (char*)errors->GetBufferPointer(), 0, 0);
 
mhTech            = mFX->GetTechniqueByName("VBlend2Tech");
mhWVP             = mFX->GetParameterByName(0, "gWVP");
mhWorldInvTrans   = mFX->GetParameterByName(0, "gWorldInvTrans");
mhFinalXForms     = mFX->GetParameterByName(0, "gFinalXForms");
mhMtrl            = mFX->GetParameterByName(0, "gMtrl");
mhLight           = mFX->GetParameterByName(0, "gLight");
mhEyePos          = mFX->GetParameterByName(0, "gEyePosW");
mhWorld           = mFX->GetParameterByName(0, "gWorld");
mhTex             = mFX->GetParameterByName(0, "gTex");
}
 
void SkinnedMeshRenderer::Init()
{
BuildFX();
 
mSkinnedMesh = new SkinnedMesh("Main\\Models\\tiny.x");
D3DXCreateTextureFromFile(pDevice, "Main\\Shaders\\Tiny_skin.bmp", &mTex);
 
 
}
 
void SkinnedMeshRenderer::UpdateScene(float &dt)
{
mSkinnedMesh->update(dt);
}
 
void SkinnedMeshRenderer::DrawScene()
{
UpdateScene(gDeltatime);
 
 
D3DXMATRIX Scale, Translate;
 
D3DXMatrixScaling(&Scale, 0.01f, 0.01f, 0.01f);
D3DXMatrixTranslation(&Translate, 8.0f, 35.0f + 5.0f, -100.0f);
 
D3DXMATRIX World = Scale * Translate;
 
mLight.dirW    = D3DXVECTOR3(8.0f + 1.0f, 35.0f + 5.0f + 1.0f, -100.0f + 2.0f);
D3DXVec3Normalize(&mLight.dirW, &mLight.dirW);
mLight.ambient = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f);
mLight.diffuse = D3DXCOLOR(0.8f, 0.8f, 0.8f, 1.0f);
mLight.spec    = D3DXCOLOR(0.8f, 0.8f, 0.8f, 1.0f);
 
 
mWhiteMtrl.ambient = WHITE * 0.9f;
mWhiteMtrl.diffuse = WHITE* 0.6f;
mWhiteMtrl.spec    = WHITE* 0.6f;
mWhiteMtrl.specPower = 48.0f;
 
mFX->SetValue(mhEyePos, &gCamera->look(), sizeof(D3DXVECTOR3));
mFX->SetMatrixArray(mhFinalXForms, mSkinnedMesh->getFinalXFormArray(), mSkinnedMesh->numBones());
mFX->SetValue(mhLight, &mLight, sizeof(DirLight));
mFX->SetMatrix(mhWVP, &(World * gCamera->viewProj()));
D3DXMATRIX worldInvTrans;
D3DXMatrixInverse(&worldInvTrans, 0, &World);
D3DXMatrixTranspose(&worldInvTrans, &worldInvTrans);
mFX->SetMatrix(mhWorldInvTrans, &worldInvTrans);
mFX->SetMatrix(mhWorld, &World);
mFX->SetValue(mhMtrl, &mWhiteMtrl, sizeof(Mtrl));
mFX->SetTexture(mhTex, mTex);
 
mFX->SetTechnique(mhTech);
UINT numPasses = 0;
mFX->Begin(&numPasses, 0);
mFX->BeginPass(0);
 
mSkinnedMesh->draw();
 
mFX->EndPass();
mFX->End();
 
}
Edited by newtechnology

Share this post


Link to post
Share on other sites

There are 2 parts to lighting: Setup and Usage.

You’ve shown the setup.

Is there something else you would like to provide…?

 

 

L. Spiro

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!