# isu diss

Member

68

-2 Poor

• Rank
Member

• Role
Programmer
• Interests
Art
Programming

## Recent Profile Visitors

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

2. ## 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. ## 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. ## 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. ## 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. ## 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. ## 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...

9. ## 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. ## DX11 Terrain Rendering

Thank you very much sir!!!

@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.

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

@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; }