#ifndef _C_MY_OBJECT_H_
#define _C_MY_OBJECT_H_
#include <xnamath.h>
class cMyObject
{
public:
cMyObject() : posX(0.0f),
posY(0.0f),
posZ(0.0f),
rot(0.0f),
scaleMod(0.3f),
scaleFull(false) {};
~cMyObject() {};
//void DeclareMyObject(float rotPassed, float posXnew, float posYnew, float posZnew)
void DeclareMyObject( float newScale,
float rotIn,
float posXnew,
float posYnew,
float posZnew )
{
currCubeWorldMat = XMMatrixIdentity(); //Reset current cubes coords
Scale = XMMatrixScaling( newScale, newScale, newScale );
XMVECTOR rotaxis = XMVectorSet( 0.0f, 0.0f, 1.0f, 0.0f ); //Define objects world space matrix
Rotation = XMMatrixRotationAxis( rotaxis, rotIn );
Translation = XMMatrixTranslation( posXnew, posYnew, posZnew );
//SRT scale, rot, translation
currCubeWorldMat = Scale * Rotation * Translation; //Set cube1's world space using the transformations
}
XMMATRIX ReturnWorldMatrix() { return currCubeWorldMat; }
/*
void DrawMyObject( ID3D11DeviceContext* d3d11DevCon,
XMMATRIX& WVP,
cbPerObject& cbPerObjectBuffer,
cbPerObject& cbPerObj,
ID3D11ShaderResourceView* TextureRef,
ID3D11SamplerState* TexSamplerRef,
XMMATRIX& camView,
XMMATRIX& camProjection)
{
WVP = currCubeWorldMat * camView * camProjection;
cbPerObj.WVP = XMMatrixTranspose(WVP);
d3d11DevCon->UpdateSubresource( cbPerObjectBuffer, 0, NULL, &cbPerObj, 0, 0 );
d3d11DevCon->VSSetConstantBuffers( 0, 1, &cbPerObjectBuffer );
d3d11DevCon->PSSetShaderResources( 0, 1, &TextureRef );
d3d11DevCon->PSSetSamplers( 0, 1, &TexSamplerRef );
//Draw the cube
d3d11DevCon->DrawIndexed( 36, 0, 0 );
}
*/
private:
XMMATRIX currCubeWorldMat;
XMMATRIX Scale,
Rotation,
Translation;
float posX,
posY,
posZ,
rot,
scaleMod;
bool scaleFull;
};
#endif
//declarations at the top of main.cpp
std::vector<cMyObject> vCubes;
in the main update function
void UpdateScene()
{
float newX = 0.0f;
for(int i = 0; i < 3; i++)
{
vCubes.push_back( cMyObject( ) );
vCubes[i].DeclareMyObject( newX, 0.0f, 0.0f );
newX += 0.3f;
}
}
in the drawscene function when I swap to this function i get the following error:
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\vector(870): error C2719: '_Val': formal parameter with __declspec(align('16')) won't be aligned
1> main.cpp(103) : see reference to class template instantiation 'std::vector<_Ty>' being compiled
for(int i = 0; i < 3; i++)
{
WVP = vCubes[i].ReturnWorldMatrix() * camView * camProjection;
cbPerObj.WVP = XMMatrixTranspose(WVP);
d3d11DevCon->UpdateSubresource( cbPerObjectBuffer, 0, NULL, &cbPerObj, 0, 0 );
d3d11DevCon->VSSetConstantBuffers( 0, 1, &cbPerObjectBuffer );
d3d11DevCon->PSSetShaderResources( 0, 1, &CubesTexture );
d3d11DevCon->PSSetSamplers( 0, 1, &CubesTexSamplerState );
//Draw the cube
d3d11DevCon->DrawIndexed( 36, 0, 0 );
}
The code works fine if I split up the variables into seperate calls eg:
//initial declarations
cMyObject object1;
cMyObject object2;
cMyObject object3;
//in the update scene
object1.DeclareMyObject( scaleMod, rot, -2.0f, 0.0f, 0.0f );
object2.DeclareMyObject( scaleMod, rot, 0.0f, 3.0f, 2.0f );
object3.DeclareMyObject( scaleMod, rot, 4.0f, 1.0f, 0.0f );
//in the draw call
WVP = object1.ReturnWorldMatrix() * camView * camProjection;
cbPerObj.WVP = XMMatrixTranspose(WVP);
d3d11DevCon->UpdateSubresource( cbPerObjectBuffer, 0, NULL, &cbPerObj, 0, 0 );
d3d11DevCon->VSSetConstantBuffers( 0, 1, &cbPerObjectBuffer );
d3d11DevCon->PSSetShaderResources( 0, 1, &CubesTexture2 );
d3d11DevCon->PSSetSamplers( 0, 1, &CubesTexSamplerState2 );
//Draw the cube
d3d11DevCon->DrawIndexed( 36, 0, 0 );
//code repeated with 2/3 etc