Quote:Original post by Endurion
The usual suspects:
Are you mayhaps using a pure device?
In that case the GetTransform and GetViewport calls will fail. You should check the result codes from them.
It might be a good idea to store the matrices and viewport when you set them anyway to save the getter calls.
Thanks,
the Getters are all working ok, I have just checked them and they all return S_OK. It seems that maybe I am getting the correct values, but maybe my view is all wrong.
Below is my render method that I use:
void GameEntity::Render(IDirect3DDevice9* p_d3dDevice){ // select which vertex format we are using p_d3dDevice->SetFVF(CUSTOMFVF); // set the view transform D3DXMATRIX matView; // the view transform matrix D3DXMatrixLookAtLH(&matView, &D3DXVECTOR3 (0.0f, 8.0f, 25.0f), // the camera position &D3DXVECTOR3 (0.0f, 0.0f, 0.0f), // the look-at position &D3DXVECTOR3 (0.0f, 1.0f, 0.0f)); // the up direction p_d3dDevice->SetTransform(D3DTS_VIEW, &matView); // set the world transform static float index = 0.0f; index += 0.03f; // an ever-increasing float value D3DXMATRIX matRotateY; // a matrix to store the rotation D3DXMatrixRotationY(&matRotateY, index); // the rotation matrix // set the projection transform D3DXMATRIX matProjection; // the projection transform matrix D3DXMatrixPerspectiveFovLH(&matProjection, D3DXToRadian(45), // the horizontal field of view 640.0f / 480.0f, // aspect ratio 1.0f, // the near view-plane 100.0f); // the far view-plane p_d3dDevice->SetTransform(D3DTS_PROJECTION, &matProjection); //convert clicked positions into 3D space positions if user has //clicked the mouse... this->SetupLocalMousePoints(p_d3dDevice, &m_xOffset, &m_yOffset); //Remember...Scaling, Translation, Rotation //translate the X and Y of needed D3DXMATRIX matTranslate; D3DXMatrixTranslation(&matTranslate, m_xOffset, m_yOffset, m_zOffset); //ALWAYS, Rotate before Translate p_d3dDevice->SetTransform(D3DTS_WORLD, &(matRotateY * matTranslate)); // set the world transform // select the vertex buffer to display p_d3dDevice->SetStreamSource(0, this->GetVertexBuffer(), 0, sizeof(CUSTOMVERTEX)); // set the texture p_d3dDevice->SetTexture(0, m_triangleTexture); // draw the textured square p_d3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); p_d3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 4, 2); p_d3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 8, 2); p_d3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 12, 2); p_d3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 16, 2); p_d3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 20, 2); }
and the SetupLocalMousePoints method (yes it is different than the original post, as I am simply try new things :))
void GameEntity::SetupLocalMousePoints(IDirect3DDevice9* p_d3dDevice, float* m_xOffset, float* m_yOffset){ if (m_mousePoint) { D3DXVECTOR3 screenPoint; D3DVIEWPORT9 viewport; D3DXMATRIX matProjection; D3DXMATRIX matView; D3DXMATRIX matWorld; D3DXVECTOR3 screenVector; screenPoint.x = m_mousePoint->x; screenPoint.y = m_mousePoint->y; screenPoint.z = 0.0f; HRESULT viewportRes = p_d3dDevice->GetViewport(&viewport); HRESULT projRes = p_d3dDevice->GetTransform( D3DTS_PROJECTION, &matProjection ); HRESULT viewRes = p_d3dDevice->GetTransform( D3DTS_VIEW, &matView ); HRESULT worldRes = p_d3dDevice->GetTransform( D3DTS_WORLD, &matWorld ); //transform the mouse clicked location D3DXVec3Unproject( &screenVector, &screenPoint, &viewport, &matProjection, &matView, &matWorld ); *m_xOffset = screenVector.x; *m_yOffset = screenVector.y; m_mousePoint = 0; }}
Mark