void CPhysicsActor::GetTransform(Matrix4x4& trans) { NxMat34 tmp = m_Actor->getGlobalPose(); float* tmp2 = new float[16]; tmp.getColumnMajor44( tmp2 ); trans.SetFrom4x4( tmp2 ); delete tmp2; }
void DXApp::RenderFrame() { _p_device->Clear(0, NULL, D3DCLEAR_TARGET, 0x00000000, 1.0f, 0); _p_device->BeginScene(); _p_device->SetRenderState(D3DRS_AMBIENT,RGB(255,255,255)); _p_device->SetRenderState(D3DRS_LIGHTING,false); _p_device->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE); _p_device->SetRenderState(D3DRS_ZWRITEENABLE, TRUE); _p_device->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESSEQUAL); D3DXMatrixPerspectiveFovLH(&matProjection,0.30f,(float)width/height,200.0f,2000.0f); //D3DXMatrixRotationX(&trans1, CameraAngleX); D3DXMatrixRotationYawPitchRoll(&trans1, 0.0f, CameraAngleX, CameraAngleY); D3DXMatrixIdentity(&matView); D3DXMatrixLookAtLH( &matView, (D3DXVECTOR3*)&Cam.location, (D3DXVECTOR3*)&(Cam.location + Cam.ViewDir), &D3DXVECTOR3( 0.0f, 1.0f, 0.0f ) ); //D3DXMatrixMultiply(&matView, &trans1, &matView); D3DXMATRIX matLocal; D3DXMatrixIdentity(&matLocal); _p_device->GetRenderTarget(0, & _back_buffer); /////////////////////////////////////////////////// //Render Shadow Buffer IDirect3DSurface9* _shadow_buffer; ShadowBuffer->GetSurfaceLevel(0, &_shadow_buffer); _p_device->SetRenderTarget(0, _shadow_buffer); _p_device->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xFFFFFFFF, 1.0f, 0); D3DXMATRIX matSBView; D3DXMATRIX matSBProjection; D3DXMATRIX matSBFull; D3DXMatrixLookAtLH( &matSBView, (D3DXVECTOR3*)&DrawLight.location, &D3DXVECTOR3( 0.0f, 0.0f, 0.0f ), &D3DXVECTOR3( 0.0f, 1.0f, 0.0f ) ); D3DXMatrixPerspectiveFovLH( &matSBProjection, D3DXToRadian(30.0f), 1,200.0f,2000.0f); D3DXMatrixMultiply( &matSBFull, &matSBView, &matSBProjection ); _p_SB_vertex_constant_able->SetMatrix(_p_device, hSBMatProjection, &matSBFull); _p_device->SetFVF(particle_fvf); _p_device->SetPixelShader(_p_SB_shader); _p_device->SetVertexShader(_p_SB_vshader); //now render the scene for(int i=0; i < _max_particle_count; i++) { if(_particle_list[i].Particle != NULL) { NxMat34 Pose = _particle_list[i].Particle->getGlobalPose(); float MatTransform[16]; Pose.getColumnMajor44((NxF32*)&MatTransform); D3DXMATRIX Transfom(MatTransform); D3DXMatrixScaling(&matLocal, CubeMeshDrawScale, CubeMeshDrawScale, CubeMeshDrawScale); D3DXMatrixMultiply(&Transfom, &matLocal, &Transfom); _p_SB_vertex_constant_able->SetMatrix(_p_device, hSBMatWorld, &Transfom); _particle_Mesh->DrawSubset(0); } } _shadow_buffer->Release(); ///////////////////////////////////////////////// //Render Scene //_p_device->SetTexture(0, _point_texture); IDirect3DSurface9* screen_surface; _screen_buffer->GetSurfaceLevel(0, &screen_surface); _p_device->SetRenderTarget(0, screen_surface); _p_device->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xFF000000, 1.0f, 0); _p_device->SetRenderTarget(0, _back_buffer); _p_device->SetTexture(0, ShadowBuffer); IDirect3DSurface9* blur_surface; if(bMotionBlur) { _blur_buffer->GetSurfaceLevel(0, &blur_surface); _p_device->SetRenderTarget(1, blur_surface); _p_device->Clear(0, NULL, D3DCLEAR_TARGET, 0x00000000, 1.0f, 0); } _p_device->SetRenderTarget(0, screen_surface); //Setup the Transform Matricies for the VertexShader; _p_vertex_constant_able->SetMatrix(_p_device, hMatProjection, &matProjection); _p_vertex_constant_able->SetMatrix(_p_device, hMatView, &matView); _p_vertex_constant_able->SetFloatArray(_p_device, hLightPosition, (float*)&DrawLight.location, 3); float fTexOffs = 0.5f + (0.5f / (float)ShadowMapSize); D3DXMATRIX matTexAdj( 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, -0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, fTexOffs, fTexOffs, 0.0f, 1.0f ); D3DXMATRIX matTexture;// = matView; //D3DXMatrixInverse( &matTexture, NULL, &matTexture ); D3DXMatrixIdentity(&matTexture); D3DXMatrixMultiply( &matTexture, &matTexture, &matSBFull ); D3DXMatrixMultiply( &matTexture, &matSBFull, &matTexAdj ); _p_vertex_constant_able->SetMatrix(_p_device, hMatTexture, &matTexture); _p_device->SetFVF(particle_fvf); _p_device->SetPixelShader(_p_shader); _p_device->SetVertexShader(_p_vshader); { D3DXMATRIX Transform; D3DXMatrixTranslation(&Transform, DrawLight.location.x, DrawLight.location.y, DrawLight.location.z); _p_vertex_constant_able->SetFloatArray(_p_device, hDeltaPos, (float*)&NxVec3(0,0,0), 3); _p_vertex_constant_able->SetMatrix(_p_device, hMatWorld, &Transform); _particle_Mesh->DrawSubset(0); D3DXMatrixIdentity(&Transform); D3DXMatrixScaling(&Transform, 200.0f, 200.0f, 200.0f); D3DXMatrixRotationAxis(&matLocal, &D3DXVECTOR3(1.0f,0.0f,0.0f), D3DXToRadian(90)); D3DXMatrixMultiply(&Transform, &matLocal, &Transform); _p_vertex_constant_able->SetMatrix(_p_device, hMatWorld, &Transform); _p_vertex_constant_able->SetFloatArray(_p_device, hDeltaPos, (float*)&NxVec3(0,0,0), 3); _p_device->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, defQuad, sizeof(NxVec3)); } _p_device->SetFVF(particle_fvf); //now render the scene for(int i=0; i < _max_particle_count; i++) { if(_particle_list[i].Particle != NULL) { //NxVec3 Translation = _particle_list[i].Particle->getGlobalPosition(); NxVec3 Velocity; if(bBlurVel) Velocity = _particle_list[i].Particle->getLinearVelocity(); else Velocity = NxVec3(0,0,0); NxMat34 Pose = _particle_list[i].Particle->getGlobalPose(); //Velocity *= _time_step; float MatTransform[16]; Pose.getColumnMajor44((NxF32*)&MatTransform); D3DXMATRIX Transfom(MatTransform); D3DXMatrixScaling(&matLocal, CubeMeshDrawScale, CubeMeshDrawScale, CubeMeshDrawScale); D3DXMatrixMultiply(&Transfom, &matLocal, &Transfom); _p_vertex_constant_able->SetMatrix(_p_device, hMatWorld, &Transfom); _p_vertex_constant_able->SetFloatArray(_p_device, hDeltaPos, (float*)&Velocity, 3); _particle_Mesh->DrawSubset(0); } } _p_device->SetTexture(0, NULL); D3DXMatrixIdentity(&matLocal); //_p_vertex_constant_able->SetMatrix(_p_device, hMatLocal, &matLocal); _p_vertex_constant_able->SetMatrix(_p_device, hMatWorld, &matLocal); _p_device->SetRenderState(D3DRS_POINTSPRITEENABLE, true); _p_device->SetRenderState(D3DRS_POINTSCALEENABLE,true); _p_device->SetRenderState(D3DRS_POINTSIZE,*((DWORD*)&_particle_size)); _p_device->SetRenderState(D3DRS_POINTSCALE_B,*((DWORD*)&_particle_scale)); _p_device->SetRenderState(D3DRS_ALPHABLENDENABLE,true); _p_device->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_ONE); _p_device->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_ONE); _p_device->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE); _p_device->SetRenderState(D3DRS_ZWRITEENABLE, FALSE); _p_device->SetFVF(light_fvf); _p_device->SetPixelShader(_p_lightshader); _p_device->DrawPrimitiveUP(D3DPT_POINTLIST, 1, &DrawLight, sizeof(DrawParticle)); _p_device->SetRenderState(D3DRS_POINTSPRITEENABLE, false); _p_device->SetRenderState(D3DRS_POINTSCALEENABLE, false); _p_device->SetRenderState(D3DRS_POINTSIZE, 0); _p_device->SetRenderState(D3DRS_POINTSCALE_B, 0); _p_device->SetRenderState(D3DRS_ALPHABLENDENABLE, false); _p_device->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_ONE); _p_device->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_ZERO); D3DXMatrixIdentity(&matProjection); _p_device->SetRenderTarget(0, _back_buffer); _p_device->SetRenderTarget(1, NULL); if(blur_surface) { blur_surface->Release(); IDirect3DTexture9* tmp; tmp=_blur_buffer; _blur_buffer=_old_blur_buffer; _old_blur_buffer=tmp; } screen_surface->Release(); _p_device->SetPixelShader(_p_combinershader); _p_device->SetVertexShader(_p_alignshader); _p_device->SetTexture(0, _screen_buffer); _p_device->SetTexture(1, _blur_buffer); _p_device->SetTexture(2, _old_blur_buffer); _p_device->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, defQuad, sizeof(NxVec3)); _p_device->SetTexture(0, NULL); _p_device->SetTexture(1, NULL); //Render the FPS Counter RECT Rect; SetRect(&Rect, 10, 10, width, height); CHAR buffer[128]; sprintf(buffer, "%d Instant FPS", (int)(1/DeltaTime)); FPSFont->DrawText(NULL, buffer, -1, &Rect, DT_LEFT|DT_NOCLIP, 0xFFFFFFFF); _p_device->EndScene(); _p_device->Present(NULL, NULL, NULL, NULL); }
Matrix::Matrix(const NxMat34& mat) { mat.getColumnMajor44(m_Matrix); }