Jump to content
  • Advertisement

isu diss

Member
  • Content Count

    68
  • Joined

  • Last visited

Community Reputation

-2 Poor

1 Follower

About isu diss

  • Rank
    Member

Personal Information

  • Role
    Programmer
  • Interests
    Art
    Programming

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. This post is about continuation of https://www.gamedev.net/forums/topic/699032-3d-rigidbody-simulation/. I have setup the Collision Detection and Collision Response for the cricket ball. But the ball doesn't bounce off the ground. After a bit of debugging, I've found that the impulse, generated when the ball bounces off the ground is very small. What should I do to make this right(right impulse)? Rigidbody.cpp XMVECTOR RigidBody::GetVelocityAtPoint(XMVECTOR p) { return (v + XMVector3Cross(Omega, (p - x))); } XMMATRIX RigidBody::GetIInverse() { return IInverse; } ...... CollisionResponse.cpp enum CollidingType { None = -1, MoveAway = 0, Resting = 1, Collide = 2 }; struct Contact { RigidBody *a, *b; XMVECTOR p, n; }; CollidingType VerifyTypeOfColliding(Contact *c) { XMVECTOR padot = c->a->GetVelocityAtPoint(c->p); XMVECTOR pbdot = c->b->GetVelocityAtPoint(c->p); XMVECTOR vrel = XMVector3Dot(c->n, (padot - pbdot)); if (vrel.m128_f32[0] > 0) return MoveAway; else if (vrel.m128_f32[0] == 0) return Resting; else if (vrel.m128_f32[0] < 0) return Collide; return None; } void CollisionResponse(Contact *c, float epsilon) { XMVECTOR padot = c->a->GetVelocityAtPoint(c->p); XMVECTOR pbdot = c->b->GetVelocityAtPoint(c->p); XMVECTOR n = c->n; XMVECTOR ra = (c->p - c->a->GetPosition()); XMVECTOR rb = (c->p - c->b->GetPosition()); XMVECTOR vrel = XMVector3Dot(c->n, (padot - pbdot)); float numerator = (-(1 + epsilon)*vrel.m128_f32[0]); float term1 = (1 / c->a->GetMass()); float term2 = (1 / c->b->GetMass()); XMVECTOR term3 = XMVector3Dot(c->n, XMVector3Cross(XMVector4Transform(XMVector3Cross(ra, n), c->a->GetIInverse()), ra)); XMVECTOR term4 = XMVector3Dot(c->n, XMVector3Cross(XMVector4Transform(XMVector3Cross(rb, n), c->b->GetIInverse()), rb)); float j = (numerator / (term1 + term2 + term3.m128_f32[0] + term4.m128_f32[0])); XMVECTOR f = (j*n); c->a->AddForce(f); c->b->AddForce(-f); c->a->AddTorque(XMVector3Cross(ra, f)); c->b->AddTorque(-XMVector3Cross(rb, f)); } ..... Collision Detection // BS - BoundingSphere class & Plane- Normal Plane class bool SpherePlaneIntersection(BS *CricketBall, Plane *CricketGround, Contact *c) { float dist = XMVector3Dot(XMLoadFloat3(&CricketBall->GetCenter()), XMLoadFloat3(&CricketGround->GetNormal())).m128_f32[0] - CricketGround->GetOffset(); c->a = rbBall; c->b = rbGround; if ((dist) <= CricketBall->GetRadius()) { c->n = XMLoadFloat3(&CricketGround->GetNormal()); c->p = XMLoadFloat3(&CricketBall->GetCenter()) - dist * XMLoadFloat3(&CricketGround->GetNormal()); return true; } else return false; return false; } ..... In the Rendering loop code Contact CBwithCG; if (SpherePlaneIntersection(cdBall, cdGround, &CBwithCG)) { if (VerifyTypeOfColliding(&CBwithCG) == Resting) { rbBall->AddForce(XMVectorSet(0, CB_Mass*g, 0, 0)); } else if (VerifyTypeOfColliding(&CBwithCG) == Collide) { CollisionResponse(&CBwithCG, .5f); } } else rbBall->AddForce(XMVectorSet(0, -CB_Mass*g, 0, 0));
  2. isu diss

    3D Rigidbody Simulation

    My code finally works!!! I'm so happy. Not only I changed the radius of the rigidbody ball, I also changed the radius of the ball's 3D model. Thank you @Irlan Robson.
  3. isu diss

    3D Rigidbody Simulation

    I'm sorry for repeated inquiries. I couldn't get my code to work, I did everything that you said. still the result is same. Anyway, I'm happy that my code works in your environment. Thanks for your support.
  4. isu diss

    3D Rigidbody Simulation

    I checked the shaders, they are just fine. Can you please create a opengl or d3d project using my sourcecode? You might be able to see the problem. Because I have no idea. I hope I'm not asking too much.
  5. isu diss

    3D Rigidbody Simulation

    Thanks @Irlan Robson I changed quat2matrix and matrixtoquat functions with the ones provided by directxmath. The result is still the same, the ball spins around the world x-axis. I don't know what to do.
  6. isu diss

    3D Rigidbody Simulation

    Rigidbody, Ball is initialized like this. These are the parameters. float CB_Mass = 0.156f;//kg float CB_Radius = 0.36f;//0.036f;//m float g = 9.83f; //ms-2 float I_tmp = (0.4f)*(CB_Mass*(CB_Radius*CB_Radius)); XMMATRIX IBody = XMMatrixSet(I_tmp, 0, 0, 0, 0, I_tmp, 0, 0, 0, 0, I_tmp, 0, 0, 0, 0, 1); rbBall = new RigidBody(CB_Mass, IBody, XMVectorSet(-100.0f, 70.0f, 0, 1), XMVectorSet(0, 0, 30.0f, 0), XMVectorSet(8e-3f, 0, 0, 0), XMMatrixRotationZ(XM_PIDIV2));
  7. isu diss

    3D Rigidbody Simulation

    I started to build a physics engine using "An Introduction to Physically Based Modeling" http://www.cs.cmu.edu/afs/cs/user/baraff/www/pbm/pbm.html by by the authors (Andrew Witkin, David Baraff and Michael Kass). This physics engine is used in a cricket simulation. So far I'm trying to simulate the cricket ball. The problem is, the ball should spin around its body space x- axis, given the angular momentum around body space x-axis but it only spins around the world space x-axis. How do I change the coordinate axis? Rigidbody dynamics code RigidBody::RigidBody(float M, XMMATRIX IBody, XMVECTOR x0, XMVECTOR v0, XMVECTOR L0, XMMATRIX R0) { Mass = M; IBodyInverse = XMMatrixInverse(NULL, IBody); x = x0; v = v0; L = L0; I0_Inverse = XMMatrixMultiply(XMMatrixTranspose(R0), IBodyInverse); I0_Inverse = XMMatrixMultiply(I0_Inverse, R0); Omega = XMVector4Transform(L0, I0_Inverse); q = MatrixToQuaternion(R0); F_Total = XMVectorSet(0, 0, 0, 0); Tau_Total = XMVectorSet(0, 0, 0, 0); } XMMATRIX RigidBody::QuaternionToMatrix(XMVECTOR q) { float vx = q.m128_f32[0]; float vy = q.m128_f32[1]; float vz = q.m128_f32[2]; float s = q.m128_f32[3]; return XMMatrixSet( (1 - ((2*vy*vy) + (2*vz*vz))), ((2*vx*vy) + (2*s*vz)), ((2*vx*vz) - (2*s*vy)), 0, ((2*vx*vy) - (2*s*vz)), (1 - ((2*vx*vx) + (2*vz*vz))), ((2*vy*vz) + (2*s*vx)), 0, ((2*vx*vz) + (2*s*vy)), ((2*vy*vz) - (2*s*vx)), (1 - ((2*vx*vx) + (2*vy*vy))), 0, 0, 0, 0, 1); } XMVECTOR RigidBody::MatrixToQuaternion(XMMATRIX m) { XMVECTOR q_tmp; float tr, s; tr = m.r[0].m128_f32[0] + m.r[1].m128_f32[1] + m.r[2].m128_f32[2]; if (tr >= 0) { s = sqrt(tr + 1); q_tmp.m128_f32[3] = 0.5f*s; s = 0.5f/s; q_tmp.m128_f32[0] = (m.r[2].m128_f32[1] - m.r[1].m128_f32[2])*s; q_tmp.m128_f32[1] = (m.r[0].m128_f32[2] - m.r[2].m128_f32[0])*s; q_tmp.m128_f32[2] = (m.r[1].m128_f32[0] - m.r[0].m128_f32[1])*s; } else { int i = 0; if (m.r[1].m128_f32[1] > m.r[0].m128_f32[0]) i = 1; if (m.r[2].m128_f32[2] > m.r[i].m128_f32[i]) i = 2; switch(i) { case 0: { s = sqrt((m.r[0].m128_f32[0] - (m.r[1].m128_f32[1] + m.r[2].m128_f32[2])) + 1); q_tmp.m128_f32[0] = 0.5f*s; s = 0.5f/s; q_tmp.m128_f32[1] = (m.r[0].m128_f32[1] + m.r[1].m128_f32[0])*s; q_tmp.m128_f32[2] = (m.r[2].m128_f32[0] + m.r[0].m128_f32[2])*s; q_tmp.m128_f32[3] = (m.r[2].m128_f32[1] - m.r[1].m128_f32[2])*s; break; } case 1: { s = sqrt((m.r[1].m128_f32[1] - (m.r[2].m128_f32[2] + m.r[0].m128_f32[0])) + 1); q_tmp.m128_f32[1] = 0.5f*s; s = 0.5f/s; q_tmp.m128_f32[2] = (m.r[1].m128_f32[2] + m.r[2].m128_f32[1])*s; q_tmp.m128_f32[0] = (m.r[0].m128_f32[1] + m.r[1].m128_f32[0])*s; q_tmp.m128_f32[3] = (m.r[0].m128_f32[2] - m.r[2].m128_f32[0])*s; break; } case 2: { s = sqrt((m.r[2].m128_f32[2] - (m.r[0].m128_f32[0] + m.r[1].m128_f32[1])) + 1); q_tmp.m128_f32[2] = 0.5f*s; s = 0.5f/s; q_tmp.m128_f32[0] = (m.r[2].m128_f32[0] + m.r[0].m128_f32[2])*s; q_tmp.m128_f32[1] = (m.r[1].m128_f32[2] + m.r[2].m128_f32[1])*s; q_tmp.m128_f32[3] = (m.r[1].m128_f32[0] - m.r[0].m128_f32[1])*s; break; } } } return q_tmp; } XMVECTOR RigidBody::GetPosition() { return x; } XMMATRIX RigidBody::GetOrientation() { return R; } void RigidBody::AddForce(XMVECTOR Force) { F_Total += Force; } void RigidBody::AddTorque(XMVECTOR Torque) { Tau_Total += Torque; } void RigidBody::Update(float h) { x += h*v; v += h*(F_Total/Mass); XMVECTOR Omegaq = XMQuaternionMultiply(q, XMVectorSet(Omega.m128_f32[0], Omega.m128_f32[1], Omega.m128_f32[2], 0)); q += 0.5f*h*Omegaq; L += h*Tau_Total; R = QuaternionToMatrix(XMQuaternionNormalize(q)); IInverse = XMMatrixMultiply(XMMatrixTranspose(R), IBodyInverse); IInverse = XMMatrixMultiply(IInverse, R); Omega = XMVector4Transform(L, IInverse); } Rendering code mgWorld = XMMatrixMultiply(rbBall->GetOrientation(), XMMatrixTranslation(rbBall->GetPosition().m128_f32[0], rbBall->GetPosition().m128_f32[1], rbBall->GetPosition().m128_f32[2])); cuvscb.mWorld = XMMatrixTranspose( mgWorld ); cuvscb.mView = XMMatrixTranspose( mgView ); cuvscb.mProjection = XMMatrixTranspose( mgProjection ); cuvscb.mLightView = XMMatrixTranspose(mgLightView); cuvscb.mLightProjection = XMMatrixTranspose(mgLightProjection); cuvscb.vCamPos = XMFLOAT3(MyCAM->GetEye().m128_f32[0], MyCAM->GetEye().m128_f32[1], MyCAM->GetEye().m128_f32[2]); cuvscb.vSun = XMFLOAT3(cos(Theta)*cos(Phi), sin(Theta), cos(Theta)*sin(Phi)); cuvscb.MieCoeffs = MC; cuvscb.RayleighCoeffs = RC; pImmediateContext->UpdateSubresource( pVSCUConstBuffer, 0, NULL, &cuvscb, 0, 0 ); pImmediateContext->VSSetConstantBuffers(0, 1, &pVSCUConstBuffer); Draw code...
  8. isu diss

    Terrain Rendering

    @Vilem OtteI'm waiting for your answer sir
  9. isu diss

    Terrain Rendering

    You've got a point there. But if I use the same render target for both skydome and terrain and snowy texture is used for terrain, downsampling stage(where bright spot is generated) also causes lens flare off the terrain. That's why I separated them.
  10. I added terrain rendering to my sky+lensflare rendering pipeline. I render terrain onto a render-target and bind it to the backbuffer as a texture. I do this in pixel shader of the fullscreen quad. return txTerrain.Sample(samLinear, Input.TextureCoords)+ txSkyDome.Sample(samLinear, Input.TextureCoords) + float4(LensFlareHalo * txDirty.Sample(samLinear, Input.TextureCoords).rgb * Intensity, 1); The problem is, the terrain is blended with sky. How do I fix this? pImmediateContext->OMSetDepthStencilState(pDSState_DD, 1); //disable depth buffer // render sky dome pImmediateContext->OMSetRenderTargets(1, &pSkyDomeRTV, pDepthStencilView); pImmediateContext->ClearRenderTargetView(pSkyDomeRTV, Colors::Black); pImmediateContext->ClearDepthStencilView(pDepthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0); //creating the sky texture in the cs shader float Theta = .2f;//XM_PI*(float)tElapsed/50; float Phi = XM_PIDIV4; CSCONSTANTBUF cscb; cscb.vSun = XMFLOAT3(cos(Theta)*cos(Phi), sin(Theta), cos(Theta)*sin(Phi)); cscb.MieCoeffs = XMFLOAT3((float)MieCoefficient(m, AerosolRadius, 680), (float)MieCoefficient(m, AerosolRadius, 530), (float)MieCoefficient(m, AerosolRadius, 470)); cscb.RayleighCoeffs = XMFLOAT3((float)RayleighCoefficient(680), (float)RayleighCoefficient(530), (float)RayleighCoefficient(470)); cscb.fHeight = 10; cscb.fWeight = 10; cscb.fWeight2 = 10; pImmediateContext->UpdateSubresource( pCSConstBuffer, 0, NULL, &cscb, 0, 0 ); UINT UAVCounts = 0; pImmediateContext->CSSetUnorderedAccessViews(0, 1, &pSkyUAV, &UAVCounts); pImmediateContext->CSSetConstantBuffers(0, 1, &pCSConstBuffer); pImmediateContext->CSSetShader(pComputeShader, NULL, 0); pImmediateContext->Dispatch(8, 8, 1); pImmediateContext->CSSetUnorderedAccessViews(0, 1, &NULLUAV, 0); pImmediateContext->CSSetShader(NULL, NULL, 0); //setting dome relevant vs and ps stuff pImmediateContext->IASetInputLayout(pVtxLayout); uiStride = sizeof(VTX); pImmediateContext->IASetVertexBuffers(0, 1, &pVtxSkyBuffer, &uiStride, &uiOffset); pImmediateContext->IASetIndexBuffer(pIndxSkyBuffer, DXGI_FORMAT_R32_UINT, 0); pImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); pImmediateContext->VSSetConstantBuffers(0, 1, &pVSSkyConstBuffer); pImmediateContext->VSSetShader(pVtxSkyShader, NULL, 0); pImmediateContext->PSSetShader(pPixlSkyShader, NULL, 0); pImmediateContext->PSSetShaderResources(0, 1, &pSkySRV); pImmediateContext->PSSetSamplers(0, 1, &SampState); mgWorld = XMMatrixTranslation(MyCAM->GetEye().m128_f32[0], MyCAM->GetEye().m128_f32[1], MyCAM->GetEye().m128_f32[2]); //drawing the sky dome VSCONSTANTBUF cb; cb.mWorld = XMMatrixTranspose( mgWorld ); cb.mView = XMMatrixTranspose( mgView ); cb.mProjection = XMMatrixTranspose( mgProjection ); pImmediateContext->UpdateSubresource( pVSSkyConstBuffer, 0, NULL, &cb, 0, 0 ); pImmediateContext->DrawIndexed((UINT)MyFBX->myInds.size(),0, 0); pImmediateContext->VSSetShader(0, NULL, 0); pImmediateContext->PSSetShader(0, NULL, 0); pImmediateContext->OMSetDepthStencilState(pDSState_DE, 1); //enable depth buffer // terrain rendering pImmediateContext->OMSetRenderTargets(1, &pTerRTV, pDepthStencilView); pImmediateContext->ClearRenderTargetView(pTerRTV, Colors::Black); pImmediateContext->ClearDepthStencilView(pDepthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0); mgWorld = XMMatrixIdentity();// XMMatrixRotationY( (float)tElapsed ); VSCONSTANTBUF tcb; tcb.mWorld = XMMatrixTranspose( mgWorld ); tcb.mView = XMMatrixTranspose( mgView ); tcb.mProjection = XMMatrixTranspose( mgProjection ); pImmediateContext->UpdateSubresource( pVSTerrainConstBuffer, 0, NULL, &tcb, 0, 0 ); //setting terain relevant vs and ps stuff pImmediateContext->IASetInputLayout(pVtxTerrainLayout); uiStride = sizeof(TERVTX); pImmediateContext->IASetVertexBuffers(2, 1, &pVtxTerrainBuffer, &uiStride, &uiOffset); pImmediateContext->IASetIndexBuffer(pIndxTerrainBuffer, DXGI_FORMAT_R32_UINT, 0); pImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); pImmediateContext->VSSetConstantBuffers(0, 1, &pVSTerrainConstBuffer); pImmediateContext->VSSetShader(pVtxTerrainShader, NULL, 0); pImmediateContext->PSSetShader(pPixlTerrainShader, NULL, 0); pImmediateContext->PSSetShaderResources(0, 1, &pTerrainSRV); pImmediateContext->PSSetSamplers(0, 1, &TerrainSampState); pImmediateContext->DrawIndexed((UINT)MyTerrain->myInds.size(), 0, 0); pImmediateContext->VSSetShader(0, NULL, 0); pImmediateContext->PSSetShader(0, NULL, 0); //downsampling stage for lens flare pImmediateContext->OMSetRenderTargets(1, &pSkyDomeBlurRTV, pDepthStencilView); pImmediateContext->ClearRenderTargetView(pSkyDomeBlurRTV, Colors::Black); pImmediateContext->ClearDepthStencilView(pDepthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0); uiStride = sizeof(VTX); pImmediateContext->IASetInputLayout(pVtxCamLayout); pImmediateContext->IASetVertexBuffers(1, 1, &pVtxCamBuffer, &uiStride, &uiOffset); pImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); pImmediateContext->VSSetShader(pVtxSkyBlurShader, NULL, 0); pImmediateContext->PSSetShader(pPixlSkyBlurShader, NULL, 0); pImmediateContext->PSSetShaderResources(0, 1, &pSkyDomeSRV);//sky+dome texture pImmediateContext->PSSetSamplers(0, 1, &CamSampState); pImmediateContext->Draw(4, 0); pImmediateContext->VSSetShader(0, NULL, 0); pImmediateContext->PSSetShader(0, NULL, 0); //backbuffer stage where lens flare code and terrain texture are set pImmediateContext->OMSetRenderTargets(1, &pRenderTargetView, pDepthStencilView); pImmediateContext->ClearRenderTargetView(pRenderTargetView, Colors::Black); pImmediateContext->ClearDepthStencilView(pDepthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0); // uiStride = sizeof(VTX); // pImmediateContext->IASetInputLayout(pVtxCamLayout); // pImmediateContext->IASetVertexBuffers(1, 1, &pVtxCamBuffer, &uiStride, &uiOffset); // pImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); pImmediateContext->VSSetShader(pVtxCamShader, NULL, 0); pImmediateContext->PSSetShader(pPixlCamShader, NULL, 0); pImmediateContext->PSSetShaderResources(0, 1, &pSRV);// dirty texture pImmediateContext->PSSetShaderResources(1, 1, &pSkyDomeBlurSRV);//sky+dome blurred texture pImmediateContext->PSSetShaderResources(2, 1, &pSkyDomeSRV);//sky+dome texture pImmediateContext->PSSetShaderResources(3, 1, &pTerSRV);//terrain texture pImmediateContext->PSSetSamplers(0, 1, &CamSampState); pImmediateContext->Draw(4, 0); pImmediateContext->VSSetShader(0, NULL, 0); pImmediateContext->PSSetShader(0, NULL, 0); pSwapChain->Present(0, 0);
  11. isu diss

    Adding Lens Flare

    Thank you very much sir!!!
  12. isu diss

    Loading FBX with Directx 11

    @AuskennfuchsThanks for your advice on manners. @galop1nThanks for your big help. I finally managed to do it. std::map code works like a charm. All I did is change p_index to its correct index, the value, returned by Mesh->GetPolygonVertex(i, j) and then magic happned. Anyone who wishes to make a fbx loader, can use my code. It works!!! Thanks everybody for support. Case closed.
  13. isu diss

    Loading FBX with Directx 11

    Now help me, I made my own code and provided it.
  14. isu diss

    Loading FBX with Directx 11

    @galop1n I managed to write std::map code. But my std::map code doesn't work. it doesn't generate duplicate vertices. For example, when I load Plane.fbx, it gives me the vertex array of -5 -5 0 5 -5 0 -5 5 0 5 5 0 0 0 0 0 0 0 the index array is simply, 0, 1, 2, 3, 4, 5 not 0, 1, 2, 2, 1, 3 Can you help me? bool operator < ( const FBXVTX &lValue, const FBXVTX &rValue) { if (lValue.Position.x != rValue.Position.x) return(lValue.Position.x < rValue.Position.x); if (lValue.Position.y != rValue.Position.y) return(lValue.Position.y < rValue.Position.y); if (lValue.Position.z != rValue.Position.z) return(lValue.Position.z < rValue.Position.z); if (lValue.TextureCoord.x != rValue.TextureCoord.x) return(lValue.TextureCoord.x < rValue.TextureCoord.x); if (lValue.TextureCoord.y != rValue.TextureCoord.y) return(lValue.TextureCoord.y < rValue.TextureCoord.y); if (lValue.Normal.x != rValue.Normal.x) return(lValue.Normal.x < rValue.Normal.x); if (lValue.Normal.y != rValue.Normal.y) return(lValue.Normal.y < rValue.Normal.y); return(lValue.Normal.z < rValue.Normal.z); } struct FBXVTX { XMFLOAT3 Position; XMFLOAT2 TextureCoord; XMFLOAT3 Normal; }; std::map< FBXVTX, int > myVertsMap; std::vector<FBXVTX> myVerts; std::vector<int> myInds; HRESULT FBXLoader::Open(HWND hWnd, char* Filename, bool UsePositionOnly) { HRESULT hr = S_OK; if (FBXM) { FBXIOS = FbxIOSettings::Create(FBXM, IOSROOT); FBXM->SetIOSettings(FBXIOS); FBXI = FbxImporter::Create(FBXM, ""); if (!(FBXI->Initialize(Filename, -1, FBXIOS))) { hr = E_FAIL; MessageBox(hWnd, (wchar_t*)FBXI->GetStatus().GetErrorString(), TEXT("ALM"), MB_OK); } FBXS = FbxScene::Create(FBXM, "REALMS"); if (!FBXS) { hr = E_FAIL; MessageBox(hWnd, TEXT("Failed to create the scene"), TEXT("ALM"), MB_OK); } if (!(FBXI->Import(FBXS))) { hr = E_FAIL; MessageBox(hWnd, TEXT("Failed to import fbx file content into the scene"), TEXT("ALM"), MB_OK); } FbxAxisSystem OurAxisSystem = FbxAxisSystem::DirectX; FbxAxisSystem SceneAxisSystem = FBXS->GetGlobalSettings().GetAxisSystem(); if(SceneAxisSystem != OurAxisSystem) { FbxAxisSystem::DirectX.ConvertScene(FBXS); } FbxSystemUnit SceneSystemUnit = FBXS->GetGlobalSettings().GetSystemUnit(); if( SceneSystemUnit.GetScaleFactor() != 1.0 ) { FbxSystemUnit::cm.ConvertScene( FBXS ); } if (FBXI) FBXI->Destroy(); FbxNode* MainNode = FBXS->GetRootNode(); int NumKids = MainNode->GetChildCount(); FbxNode* ChildNode = NULL; for (int i=0; i<NumKids; i++) { ChildNode = MainNode->GetChild(i); FbxNodeAttribute* NodeAttribute = ChildNode->GetNodeAttribute(); if (NodeAttribute->GetAttributeType() == FbxNodeAttribute::eMesh) { FbxMesh* Mesh = ChildNode->GetMesh(); if (UsePositionOnly) { NumVertices = Mesh->GetControlPointsCount();//number of vertices MyV = new XMFLOAT3[NumVertices]; for (DWORD j = 0; j < NumVertices; j++) { FbxVector4 Vertex = Mesh->GetControlPointAt(j);//Gets the control point at the specified index. MyV[j] = XMFLOAT3((float)Vertex.mData[0], (float)Vertex.mData[1], (float)Vertex.mData[2]); } NumIndices = Mesh->GetPolygonVertexCount();//number of indices MyI = (DWORD*)Mesh->GetPolygonVertices();//index array } else { FbxLayerElementArrayTemplate<FbxVector2>* uvVertices = NULL; Mesh->GetTextureUV(&uvVertices); int idx = 0; for (int i = 0; i < Mesh->GetPolygonCount(); i++)//polygon(=mostly triangle) count { for (int j = 0; j < Mesh->GetPolygonSize(i); j++)//retrieves number of vertices in a polygon { FBXVTX myVert; int p_index = 3*i+j; int t_index = Mesh->GetTextureUVIndex(i, j); FbxVector4 Vertex = Mesh->GetControlPointAt(p_index);//Gets the control point at the specified index. myVert.Position = XMFLOAT3((float)Vertex.mData[0], (float)Vertex.mData[1], (float)Vertex.mData[2]); FbxVector4 Normal; Mesh->GetPolygonVertexNormal(i, j, Normal); myVert.Normal = XMFLOAT3((float)Normal.mData[0], (float)Normal.mData[1], (float)Normal.mData[2]); FbxVector2 uv = uvVertices->GetAt(t_index); myVert.TextureCoord = XMFLOAT2((float)uv.mData[0], (float)uv.mData[1]); if ( myVertsMap.find( myVert ) != myVertsMap.end() ) myInds.push_back( myVertsMap[ myVert ]); else { myVertsMap.insert( std::pair<FBXVTX, int> (myVert, idx ) ); myVerts.push_back(myVert); myInds.push_back(idx); idx++; } } } } } } } else { hr = E_FAIL; MessageBox(hWnd, TEXT("Failed to create the FBX Manager"), TEXT("ALM"), MB_OK); } return hr; }
  15. isu diss

    Adding Lens Flare

    Thanks you@Vilem Otte. I worked it out. Is this right?
  • 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!