zephia

Members
  • Content count

    2
  • Joined

  • Last visited

Community Reputation

102 Neutral

About zephia

  • Rank
    Newbie
  1. Oh, I see. Thank you so much for this help! I did not realize that aspect at all. Again, thank you.
  2. Hello, I recently started learning DirectX and Direct3D 10 ( I know, not 11, but please bear with me ^^ ) by reading the Ultimate Game Programming as well as Luna's books. I feel like I have missed a glaringly obvious detail, in that I still do not know how to rotate / transform vertices independently? What I mean is, I currently have a program which simply displays 2 cubes, and what I'd like to do is rotate one a certain angle in the y-direction, and the other one a certain angle in the x-direction. I feed in a transformation matrix into my shader ( made from using the MatrixRotationY and MatrixRotationX functions ), and I change that matrix before each object's draw call, yet no matter what, I end up with the two cubes oriented the exact same way. Can someone explain what I am doing wrong? This is my shader file: [source lang="plain"]cbuffer Variables { matrix World; matrix View; matrix Projection; matrix Transform; }; struct PS_INPUT { float4 Pos : SV_POSITION; float4 Color : COLOR0; }; PS_INPUT VS( float4 Pos : POSITION, float4 Color : COLOR ) { PS_INPUT psInput; Pos = mul ( Pos, Transform ); Pos = mul ( Pos, World ); Pos = mul ( Pos, View ); psInput.Pos = mul( Pos, Projection ); psInput.Color = Color; return psInput; } PS_INPUT VS2( float4 Pos : POSITION, float4 Color : COLOR ) { } float4 PS( PS_INPUT psInput ) : SV_Target { return psInput.Color; } technique10 Render { pass P0 { SetVertexShader ( CompileShader( vs_4_0, VS() ) ); SetGeometryShader ( NULL ); SetPixelShader ( CompileShader( ps_4_0, PS() ) ); } }[/source] And here are parts of my main file: I build my effect and vertex layouts here [source lang="cpp"]void InitDirect3DApp::buildFX() { DWORD shaderFlags = D3D10_SHADER_ENABLE_STRICTNESS; #if defined( DEBUG ) || defined( _DEBUG ) shaderFlags |= D3D10_SHADER_DEBUG; shaderFlags |= D3D10_SHADER_SKIP_OPTIMIZATION; #endif ID3D10Blob* compilationErrors = 0; HRESULT hr = 0; hr = D3DX10CreateEffectFromFile(L"shadertest.fx", 0, 0, "fx_4_0", shaderFlags, 0, md3dDevice, 0, 0, &mFX, &compilationErrors, 0); if(FAILED(hr)) { if( compilationErrors ) { MessageBoxA(0, (char*)compilationErrors->GetBufferPointer(), 0, 0); ReleaseCOM(compilationErrors); } DXTrace(__FILE__, (DWORD)__LINE__, hr, L"D3DX10CreateEffectFromFile", true); } mTech = mFX->GetTechniqueByName("Render"); pViewMatrixEffectVariable = mFX->GetVariableByName( "View" )->AsMatrix(); pProjectionMatrixEffectVariable = mFX->GetVariableByName( "Projection" )->AsMatrix(); pWorldMatrixEffectVariable = mFX->GetVariableByName( "World" )->AsMatrix(); pTransformationMatrixEffectVariable = mFX->GetVariableByName( "Transform" )->AsMatrix(); } void InitDirect3DApp::buildVertexLayouts() { // Create the vertex input layout. D3D10_INPUT_ELEMENT_DESC vertexDesc[] = { {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0}, {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0} }; [/source] here is where I try to draw my cubes, with different orientations: [source lang="cpp"]void InitDirect3DApp::drawScene() { D3DApp::drawScene(); md3dDevice->OMSetDepthStencilState(0, 0); float blendFactors[] = { 0.0f, 0.0f, 0.0f, 0.0f }; md3dDevice->OMSetBlendState(0, blendFactors, 0xffffffff); md3dDevice->IASetInputLayout(mVertexLayout); md3dDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST); static float r; D3DXMATRIX w; D3DXMatrixIdentity(&w); //D3DXMatrixRotationY(&w, r); //r += 0.001f; mWVP = mView * mProj; pWorldMatrixEffectVariable->SetMatrix(w); pViewMatrixEffectVariable->SetMatrix(mView); pProjectionMatrixEffectVariable->SetMatrix(mProj); pTransformationMatrixEffectVariable->SetMatrix(mTransform); D3D10_TECHNIQUE_DESC techDesc; mTech->GetDesc( &techDesc ); for (UINT p = 0; p < techDesc.Passes; ++p) { mTech->GetPassByIndex( p )->Apply(0); D3DXMatrixRotationY(&mTransform, -.2f); mShape1.draw( 0.5f, 0.3f, 0.0f ); D3DXMatrixRotationX(&mTransform, .3f); mShape2.draw( 1.0f, -0.3f, 0.5f ); } // We specify DT_NOCLIP, so we do not care about width/height of the rect. RECT R = {50, 50, 0, 0}; mFont->DrawText(0, mFrameStats.c_str(), -1, &R, DT_NOCLIP, BLACK); mSwapChain->Present(0, 0); }[/source] Thank you so much for any help you can give. And I apologize if I made some pretty obvious mistakes ( which I feel like I did ).