# kslam

Member

45

1. ## RTS character heading problem

Hi, I create a RTS game. I got a problem of the character heading. I can calculate the angle of rotate by using dot product, but I can not control the direction of the rotation. For example, turn to right or left when I click the location on the left hand side of the character. The character may turn to right hand side 90 degree and not left hand side 90 degree. Any one got the solution ?
2. ## RTS character heading problem

The code is in Dark gdk float ar = 0, br = -1, cr, dr; // First heading (ar, br)and second heading (cr, dr) float bb = dbMouseX(); float ba = dbMouseY(); double pickVector = dbPickObject ( bb, ba, 1, 10 ) ; float xHit = dbGetPickVectorX() + dbCameraPositionX();//Pick the x and z location on 3d terrain of mouse location float yHit = dbGetPickVectorY() + dbCameraPositionY(); float zHit = dbGetPickVectorZ() + dbCameraPositionZ(); cr = xHit; dr = zHit; kcr = xHit; kdr = zHit; dbMakeVector2 ( 1 ); dbMakeVector2 ( 2 ); dbSetVector2 (1, ar, br); dbNormalizeVector2 ( 2, 1 ); float vX1 = dbXVector2 (2); float vY1 = dbYVector2 (2); dbMakeVector2 ( 3 ); dbMakeVector2 ( 4 ); dbSetVector2 (3, cr, dr); dbNormalizeVector2 ( 4, 3 ); float vX2 = dbXVector2 (4); float vY2 = dbYVector2 (4); float vka = vX1 * vX2 + vY1 * vY2; r2 = dbACOS ( vka ); dbYRotateObject ( 10, r2); ar = kcr; br = kdr;
3. ## Create multiple 3d model object at derived class

Hi, I try to create multiple object in XNA 2.0. I create LampManager class(derived from game1.cs and pass graphicdevice, content from game1.cs) and Lamp class and try to create multiple lamp(3D Model) object, because I don't want to put all the code in game1.cs. But When I move drawmd2model() function to LampManager or Lamp, the effectpass, verdexdeclaretion got error... throw null exception, ..."pass" same scope in parent error.... I want the Lamp class got their update and draw function and effect(draw at Lamp.cs). the LampManager (run the Lamp.Draw() and Lamp.Update())is to manage the Lamp class. In the game1 class(run the LampManager.Update()) Does anyone know how to do it ? And, is it the effect, shader and draw 3d model functions only can put in the game1.cs, other than the game1.cs it will get error ? Thanks.
4. ## Tools capable of exporting .X format character animations

Does anybody know, which 3D charecter animaton software(affordable) can export to a single .x file more than 1 single animation set ? EDIT: As Gage64 says - read the FAQ on what is and is not an acceptable subject title. 'lamks' is not acceptable. [Edited by - jollyjeffers on June 20, 2008 3:19:45 AM]
5. ## skeletal animation problem

Hi, I got a problem, when I load a charecter model by using directx 9, the charecter model not load in the world origin, I have to zoom out the camera to : D3DXMatrixLookAtLH(&view, &D3DXVECTOR3(0.0f, 0.0f, -5000.0f), &D3DXVECTOR3(0.0f, 0.0f, 0.0f), &D3DXVECTOR3(0.0f, 1.0f, 0.0f)); D3DXMatrixPerspectiveFovLH(&proj, 0.2f, 1.33333f, 0.01f, 100000.0f); then I can see the model but I can't see the texture, but I draw this model in local origin at 3d animation software. I also try to load the Blender's sample model, but I totally can not see the model. I can see the model if I opened the .x file in Directx viewer. The original source code which I using is from the book, The author draw the model by using 3Ds Max, and can be loaded properly. Is it the problem from the Model's .x(3d software) file or from the source code ? Some of the source code are as below : ----------------------------------------------------------------------- //Set camera D3DXMATRIX view, proj, world, r, s; D3DXMatrixLookAtLH(&view, &D3DXVECTOR3(0.0f, 0.0f, -5000.0f), &D3DXVECTOR3(0.0f, 0.0f, 0.0f), &D3DXVECTOR3(0.0f, 1.0f, 0.0f)); D3DXMatrixPerspectiveFovLH(&proj, 0.2f, 1.33333f, 0.01f, 100000.0f); D3DXMatrixRotationYawPitchRoll(&r, m_angle, 0.0f, 0.0f); D3DXMatrixScaling(&s, 1.0f, 1.0f, 1.0f); world = s * r; m_pDevice->SetTransform(D3DTS_VIEW, &view); m_pDevice->SetTransform(D3DTS_PROJECTION, &proj); m_pDevice->SetTransform(D3DTS_WORLD, &world); m_skinnedMesh.SetPose(world, NULL, m_unitTime); ----------------------------------------------------------------------- void SKINNEDMESH::SetPose(D3DXMATRIX world, ID3DXAnimationController* animControl, float time) { if(animControl != NULL) animControl->AdvanceTime(time, NULL); else m_pAnimControl->AdvanceTime(time, NULL); UpdateMatrices((BONE*)m_pRootBone, &world); -----------------------------------------------------------------------void SKINNEDMESH::Render(BONE *bone) { if(bone == NULL)bone = (BONE*)m_pRootBone; //If there is a mesh to render... if(bone->pMeshContainer != NULL) { BONEMESH *boneMesh = (BONEMESH*)bone->pMeshContainer; if (boneMesh->pSkinInfo != NULL) { // set up bone transforms int numBones = boneMesh->pSkinInfo->GetNumBones(); for(int i=0;i < numBones;i++) D3DXMatrixMultiply(&boneMesh->currentBoneMatrices, &boneMesh->boneOffsetMatrices, boneMesh->boneMatrixPtrs); //Update the skinned mesh BYTE *src = NULL, *dest = NULL; boneMesh->OriginalMesh->LockVertexBuffer(D3DLOCK_READONLY, (VOID**)&src); boneMesh->MeshData.pMesh->LockVertexBuffer(0, (VOID**)&dest); boneMesh->pSkinInfo->UpdateSkinnedMesh(boneMesh->currentBoneMatrices, NULL, src, dest); boneMesh->MeshData.pMesh->UnlockVertexBuffer(); boneMesh->OriginalMesh->UnlockVertexBuffer(); //Render the mesh for(int i=0;i < boneMesh->NumAttributeGroups;i++) { int mtrlIndex = boneMesh->attributeTable.AttribId; m_pDevice->SetMaterial(&(boneMesh->materials[mtrlIndex])); //m_pDevice->SetTexture(0, boneMesh->textures[mtrlIndex]); boneMesh->MeshData.pMesh->DrawSubset(mtrlIndex); } } } if(bone->pFrameSibling != NULL)Render((BONE*)bone->pFrameSibling); if(bone->pFrameFirstChild != NULL)Render((BONE*)bone->pFrameFirstChild); ----------------------------------------------------------------------- Thank you Kslam
6. ## skeletal animation problem

It didn't works.
7. ## skeletal animation problem

I validate the code below, the program run without error but can't see texture. (The model is red color without texture) If I disable the VS and PS code, the model become black color. I think this code is custom made for the 3ds Max model. HRESULT hResult = D3DXCreateTextureFromFile(m_pDevice, textureFname, &newTexture); if (FAILED(hResult)) { strcpy(emsg, "Error creating texture."); PostQuitMessage(WM_QUIT); break; } ------------------------------------------------------------- HRESULT hResult = m_pDevice->SetTexture(0, boneMesh- textures[mtrlIndex]); if (FAILED(hResult)) { strcpy(emsg, "Error settexture."); PostQuitMessage(WM_QUIT); break; }

9. ## skeletal animation problem

I can see the model, but I can't see the texture. The settexture code as below : void SKINNEDMESH::Render(BONE *bone) { if(bone == NULL)bone = (BONE*)m_pRootBone; //If there is a mesh to render... if(bone->pMeshContainer != NULL) { BONEMESH *boneMesh = (BONEMESH*)bone->pMeshContainer; if (boneMesh->pSkinInfo != NULL) { // set up bone transforms int numBones = boneMesh->pSkinInfo->GetNumBones(); for(int i=0;i < numBones;i++) D3DXMatrixMultiply(&boneMesh->currentBoneMatrices, &boneMesh->boneOffsetMatrices, boneMesh->boneMatrixPtrs); //Update the skinned mesh BYTE *src = NULL, *dest = NULL; boneMesh->OriginalMesh->LockVertexBuffer(D3DLOCK_READONLY, (VOID**)&src); boneMesh->MeshData.pMesh->LockVertexBuffer(0, (VOID**)&dest); boneMesh->pSkinInfo->UpdateSkinnedMesh(boneMesh->currentBoneMatrices, NULL, src, dest); boneMesh->MeshData.pMesh->UnlockVertexBuffer(); boneMesh->OriginalMesh->UnlockVertexBuffer(); //Render the mesh for(int i=0;i < boneMesh->NumAttributeGroups;i++) { int mtrlIndex = boneMesh->attributeTable.AttribId; m_pDevice->SetMaterial(&(boneMesh->materials[mtrlIndex])); m_pDevice->SetTexture(0, boneMesh->textures[mtrlIndex]); boneMesh->MeshData.pMesh->DrawSubset(mtrlIndex); } } } if(bone->pFrameSibling != NULL)Render((BONE*)bone->pFrameSibling); if(bone->pFrameFirstChild != NULL)Render((BONE*)bone->pFrameFirstChild); }
10. ## skeletal animation problem

The model create using 3ds max can load successfully( position and texture). The tiny.x can be loaded but not in origin coordinate, I have to zoom out in order to see the model and can not see the texture. Do u know how to set the model to origin position in Directx 9. The texture code as below : HRESULT BONE_HIERARCHY::CreateMeshContainer(LPCSTR Name, CONST D3DXMESHDATA *pMeshData, CONST D3DXMATERIAL *pMaterials, CONST D3DXEFFECTINSTANCE *pEffectInstances, DWORD NumMaterials, CONST DWORD *pAdjacency, LPD3DXSKININFO pSkinInfo, LPD3DXMESHCONTAINER *ppNewMeshContainer) { //Create new Bone Mesh BONEMESH *boneMesh = new BONEMESH; memset(boneMesh, 0, sizeof(BONEMESH)); //Get mesh data boneMesh->OriginalMesh = pMeshData->pMesh; boneMesh->MeshData.pMesh = pMeshData->pMesh; boneMesh->MeshData.Type = pMeshData->Type; pMeshData->pMesh->AddRef(); //Add Reference so that the mesh isnt deallocated IDirect3DDevice9 *m_pDevice = NULL; pMeshData->pMesh->GetDevice(&m_pDevice); //Get Device ptr from mesh //Copy materials and load textures (just like with a static mesh) for(int i=0;i<NumMaterials;i++) { D3DXMATERIAL mtrl; memcpy(&mtrl, &pMaterials, sizeof(D3DXMATERIAL)); boneMesh->materials.push_back(mtrl.MatD3D); if(mtrl.pTextureFilename) { char textureFname[200]; strcpy(textureFname, "units/"); strcat(textureFname, mtrl.pTextureFilename); //Load texture IDirect3DTexture9* newTexture = NULL; D3DXCreateTextureFromFile(m_pDevice, textureFname, &newTexture); boneMesh->textures.push_back(newTexture); } } if(pSkinInfo != NULL) { //Get Skin Info boneMesh->pSkinInfo = pSkinInfo; pSkinInfo->AddRef(); //Add reference so that the SkinInfo isnt deallocated //Clone mesh and store in boneMesh->MeshData.pMesh pMeshData->pMesh->CloneMeshFVF(D3DXMESH_MANAGED, pMeshData->pMesh->GetFVF(), m_pDevice, &boneMesh->MeshData.pMesh); //Get Attribute Table boneMesh->MeshData.pMesh->GetAttributeTable(NULL, &boneMesh->NumAttributeGroups); boneMesh->attributeTable = new D3DXATTRIBUTERANGE[boneMesh->NumAttributeGroups]; boneMesh->MeshData.pMesh->GetAttributeTable(boneMesh->attributeTable, NULL); //Create bone offset and current matrices int NumBones = pSkinInfo->GetNumBones(); boneMesh->boneOffsetMatrices = new D3DXMATRIX[NumBones]; boneMesh->currentBoneMatrices = new D3DXMATRIX[NumBones]; //Get bone offset matrices for(int i=0;i < NumBones;i++) boneMesh->boneOffsetMatrices = *(boneMesh->pSkinInfo->GetBoneOffsetMatrix(i)); } //Set ppNewMeshContainer to the newly created boneMesh container *ppNewMeshContainer = boneMesh; return S_OK; }
11. ## .X file animation question

another new error come out. How about you give me your email, I send this .x file to you ?
12. ## .X file animation question

Hi, I want to inquiry that how can I create several animations set (such as run, jump, attack) in one single MS3D file and convert to one .x file in order for me to use the directx9 (SetTrackAnimationSet, GetAnimationSet) to switch the animation set ? Is it the Milkshape3d can convert to .X file which can contain more than one animation ? If not, is it directx9 can support md3 file or other format which directx9 can support(all the animation in a single .x file) and how to make it ? Thank you Kslam
13. ## .X file animation question

When I load .X file, there is an error : Invalid file "expected 'frame' token. found // The .x file is running properly in DirectX viewer.
14. ## Milkshape .X exporter plugin for directx 9

Hi, Does anybody know where can I find the Milkshape .X exporter plugin for directx 9 ? I only can find the directx 8.0 and JT exporter. Is it can use in directx 9 ? Thank you
15. ## Quaternion rotation using Directx API

Hi, I would like to inquiry that any tutorial link or book which show u how to do the Quaternion rotation by using Directx API ?

17. ## Character animation question

Hi ! I draw a character in Lightwave, is there any Lightwave API to link with directx or C++ in order to make some realtime character animation? Or other 3D Modeler API ? Thanks
18. ## Character animation question

which 3D Modeller software can export to .x format ?
19. ## Light question

Hi All, I got question, how to calculate the Final Object colour = object color * Light_Ambient (If only got ambient light) It is, object color * Light_Ambient or object color + Light_Ambient / 2 to get the Final Object colour ? (256, G, B) * (128, G, B) = 32768(>256) (256, G, B) + (128, G, B) /2 = 192 ???
20. ## Z buffer

Normally interpolation is after the screen coordinate stage is it ? If yes, at the screen coordinate stage only got (X, Y) without Z, so how to I interpolate (Y, Z) ?
21. ## Z buffer

Hi all, I very confused about the Z buffer and 1/z. I have read a book about the Z buffer, there is something.. buffer array, perspective projection of Y and Z, Z interpolation. As I know, after convert the vertex coordinate to screen coordinate, then interpolate Y and X. But why got Z interpolation ? Any Link and books to recommand(non API) ?

Thank you.
23. ## backface remove

Hi All, I draw a polycon and compute the Normal of this polycon. How I know the direction of the Normal is face UP or face Down ? Thank You.
24. ## backface remove

If all the vertex are positive value ? For example : Bottom Polycon A, vertex v0=(10, 10, 10), v1=(20, 10, 10), v2=(15, 10, 20) Top Polycon B, vertex v0= (10, 30, 10), v1=(20, 30, 10), v2=(15, 30, 20) I'm not using APIs.
25. ## backface remove

Assume that I draw a box which got 6 face. I view from the above, I can see 3 faces of the box. If without backface remove, I can see 6 faces. Now I want to remove 3 faces (behind Left and Right face, Bottom face). If the Direction of the Normal face up, the Top Face of the box's Dot product is < 90 degree. But if like this, the Bottom Face' Dot product < 90 degree. Top Face same like Bottom face. It is incorrect.(Normal Direction Top Face and Bottom Face is same, they face up, as I know all Normal Direction of the polycon is face UP??) If the Normal Direction of the Bottom Face is face down(the DP > 90 degree) , then it is correct, I can remove the Bottom face. My question is, how do I know the direction of the Normal is face up or face down ?(Direction Normal of the Top Face is UP, the Bottom Face is DOWN) As I know that the polycon on the Top Face and the polycon at the Bottom Face is same, the different is, one on top the other one at bottom of the box. How to control the Normal direction of the polycon to face up or face down ? Beside that, how about the behind Left and Right face, their Direction Normal will face to left or right ?