# carl granberg

Members

48

56 Neutral

• Rank
Member
1. ## Make cube

Hi everybody,I had a problem want to someguys show help,you know I working with XNA primitive,I want to build a cube with six side,I already done it,but it can not rotate along with axes(X,y,z),I don't know is I should use orbit Rotate or just rotate?show me some code please!as soon as answer me!

3. ## click mesh code

A member of Game.dev net share me some code show below: [b][color="#808080"]bool[/color][/b] CPolygon::Pic( [b][color="#808080"]HWND[/color][/b] m_hWnd, [b][color="#808080"]int[/color][/b] Width, [b][color="#808080"]int[/color][/b] Height, [b][color="#808080"]float[/color][/b] &fRetDist ) { D3DXVECTOR3 vPickRayDir; D3DXVECTOR3 vDir; D3DXVECTOR3 vPickRayOrig; D3DXMATRIXA16 matProj; pd3d_Device->GetTransform( D3DTS_PROJECTION, &matProj ); POINT ptCursor; GetCursorPos( &ptCursor ); ScreenToClient( m_hWnd, &ptCursor ); [color="#008200"]// Compute the vector of the pick ray in screen space [/color] D3DXVECTOR3 v; v.x = ( ( ( 2.0f * ptCursor.x ) / Width ) - 1 ) / matProj._11; v.y = -( ( ( 2.0f * ptCursor.y ) / Height ) - 1 ) / matProj._22; v.z = 1.0f; [color="#008200"]// Get the inverse of the composite view and world matrix [/color] D3DXMATRIXA16 matView, matWorld, m; pd3d_Device->GetTransform( D3DTS_VIEW, &matView ); pd3d_Device->GetTransform( D3DTS_WORLD, &matWorld ); m = matWorld * matView; D3DXMatrixInverse( &m, NULL, &m ); [color="#008200"]// Transform the screen space pick ray into 3D space [/color] vPickRayDir.x = v.x*m._11 + v.y*m._21 + v.z*m._31; vPickRayDir.y = v.x*m._12 + v.y*m._22 + v.z*m._32; vPickRayDir.z = v.x*m._13 + v.y*m._23 + v.z*m._33; D3DXVec3Normalize(&vDir,&vPickRayDir); vPickRayOrig.x = m._41; vPickRayOrig.y = m._42; vPickRayOrig.z = m._43; [b][color="#808080"]BOOL[/color][/b] bHitItersect; [b][color="#808080"]DWORD[/color][/b] dwFace; [b][color="#808080"]FLOAT[/color][/b] fBary1, fBary2, fDist; D3DXIntersect(m_pMeshPolygon, &vPickRayOrig, &vDir, &bHitItersect, &dwFace, &fBary1, &fBary2, &fDist, NULL, NULL); [b][color="#006699"]if[/color][/b]( bHitItersect ) { fRetDist = fDist; [b][color="#006699"]return[/color][/b] [b][color="#006699"]true[/color][/b]; } [b][color="#006699"]return[/color][/b] [b][color="#006699"]false[/color][/b]; } I have a similiar function like this and I use it in my projects,but it in my projects,this function work incorrect,actually I only click one mesh,but it reply me I click all the mesh In the programm,how do you think this problem?
4. ## when mouse click the mesh

did someone really don't know why,I have no any way to fix the problem,unless someone share me example and comment very detail.
5. ## when mouse click the mesh

did someone can show me a full example ,all the mesh in the example must created from a same file.the problem show above can not occur in my projects
6. ## when mouse click the mesh

Hey guys,I reading the book"Programming Role playing games with Directx",I found a few lines of code that show on below BOOL cApp::MouseClickMesh(cMesh *Mesh) { D3DXVECTOR3 vecRay, vecDir; // Ray’s position and direction D3DXVECTOR3 v; // Temporary vector D3DXMATRIX matProj, matView; // Projection and view matrices D3DXMATRIX m; // Temporary matrix // Get the current projection and view transformations m_Graphics.GetDeviceCOM()->GetTransform(D3DTS_PROJECTION, \ &matProj); m_Graphics.GetDeviceCOM()->GetTransform(D3DTS_VIEW, \ &matView); // Inverse the view matrix D3DXMatrixInverse(&m, NULL, &matView); // Read mouse coordinates (to prepare for reading) //m_Mouse.Read(); // Compute the vector of the pick ray in screen space v.x = (((2.0f * m_Mouse.GetXPos()) / m_Graphics.GetWidth()) - \ 1) / matProj._11; v.y = -(((2.0f * m_Mouse.GetYPos()) / m_Graphics.GetHeight()) - \ 1) / matProj._22; v.z = 1.0f; // Transform the screen space ray vecRay.x = m._41; vecRay.y = m._42; vecRay.z = m._43; vecDir.x = v.x*m._11 + v.y*m._21 + v.z*m._31; vecDir.y = v.x*m._12 + v.y*m._22 + v.z*m._32; vecDir.z = v.x*m._13 + v.y*m._23 + v.z*m._33; // Mesh = pre-loaded cMesh object ID3DXMesh *pMesh; BOOL Hit; DWORD Face; float u, V, Dist; // Get pointer to cMesh ID3DXMesh object pMesh = Mesh->GetParentMesh()->m_Mesh; // call above code to get ray vectors and call intersect D3DXIntersect(pMesh, &vecRay, &vecDir, &Hit, &Face, \ &u, &V, &Dist, NULL, NULL); // If Hit is TRUE, then user clicked on mesh if(Hit == true && m_Mouse.GetButtonState(MOUSE_LBUTTON ) == true) return true; return false; } The book's author says thease code will use to do a collision test check did mouse click the dest mesh.I use it to my projects.I build a room use a x file,and I rollout many mesh for it,but when the programm has running,this function reply me a information says I click all mesh comprise the room.but I just click one mesh,why?I put a break point to that statement if(Hit == true && m_Mouse.GetButtonState(MOUSE_LBUTTON ) == true),then debug again,the hit is always true as long as I click the left button on mouse and I run the function ,even I just click one mesh,have you encounter this scenario,if so please help me find why cause the result.
7. ## Role playing code

There is some code experts from jim adams's book Programming Role playing games if(Size > m_MaxSize && Num > m_MaxPolygons) { for(i=0;i<(unsigned long)((m_TreeType==QUADTREE)?4:8);i++) { XOff = (((i % 2) < 1) ? -1.0f : 1.0f) * (Size / 4.0f); ZOff = (((i % 4) < 2) ? -1.0f : 1.0f) * (Size / 4.0f); YOff = (((i % 8) < 4) ? -1.0f : 1.0f) * (Size / 4.0f); // See if any polygons in new node bounding box if(CountPolygons(XPos+XOff,YPos+YOff,ZPos+ZOff,Size/2.0f)) { Node->Nodes[i] = new sNode(); // Create new child node // Sort the polygons with the new child node SortNode(Node->Nodes[i],XPos+XOff,YPos+YOff,ZPos+ZOff,Size/2.0f); } } does someone undertstand why we caculate the Xoff and Yoff and ZOff as this way,try to explain that code very detail don't use the depth math than I can undertstand !
8. ## Role games code

There is some code experts from jim adams's book Programming Role playing games if(Size > m_MaxSize && Num > m_MaxPolygons) { for(i=0;i<(unsigned long)((m_TreeType==QUADTREE)?4:8);i++) { XOff = (((i % 2) < 1) ? -1.0f : 1.0f) * (Size / 4.0f); ZOff = (((i % 4) < 2) ? -1.0f : 1.0f) * (Size / 4.0f); YOff = (((i % 8) < 4) ? -1.0f : 1.0f) * (Size / 4.0f); // See if any polygons in new node bounding box if(CountPolygons(XPos+XOff,YPos+YOff,ZPos+ZOff,Size/2.0f)) { Node->Nodes[i] = new sNode(); // Create new child node // Sort the polygons with the new child node SortNode(Node->Nodes[i],XPos+XOff,YPos+YOff,ZPos+ZOff,Size/2.0f); } } does someone undertstand why we caculate the Xoff and Yoff and ZOff as this way,try to explain that code very detail don't use the depth math than I can undertstand !
9. ## Developing a advanced 3D game engine

Your guys don't know the expalin of thease code is so rude for me,I read that section again again,but no words can give me a way to slove it understand it!so don,t delay my time,just to explain it that is all!
10. ## Developing a advanced 3D game engine

if you read the book programming role playing games,you must remember the function as below: if(Size > m_MaxSize && Num > m_MaxPolygons) { for(i=0;i<(unsigned long)((m_TreeType==QUADTREE)?4:8);i++) { if(Size > m_MaxSize && Num > m_MaxPolygons) { for(i=0;i<(unsigned long)((m_TreeType==QUADTREE)?4:8);i++) { XOff = (((i % 2) < 1) ? -1.0f : 1.0f) * (Size / 4.0f); ZOff = (((i % 4) < 2) ? -1.0f : 1.0f) * (Size / 4.0f); YOff = (((i % 8) < 4) ? -1.0f : 1.0f) * (Size / 4.0f); // See if any polygons in new node bounding box if(CountPolygons(XPos+XOff,YPos+YOff,ZPos+ZOff,Size/2.0f)) { Node->Nodes[i] = new sNode(); // Create new child node // Sort the polygons with the new child node SortNode(Node->Nodes[i],XPos+XOff,YPos+YOff,ZPos+ZOff,Size/2.0f); } } // See if any polygons in new node bounding box if(CountPolygons(XPos+XOff,YPos+YOff,ZPos+ZOff,Size/2.0f)) { Node->Nodes[i] = new sNode(); // Create new child node // Sort the polygons with the new child node SortNode(Node->Nodes[i],XPos+XOff,YPos+YOff,ZPos+ZOff,Size/2.0f); } } Ok so jog your mind what 's mean with thease code?: if(Size > m_MaxSize && Num > m_MaxPolygons) { for(i=0;i<(unsigned long)((m_TreeType==QUADTREE)?4:8);i++) { XOff = (((i % 2) < 1) ? -1.0f : 1.0f) * (Size / 4.0f); ZOff = (((i % 4) < 2) ? -1.0f : 1.0f) * (Size / 4.0f); YOff = (((i % 8) < 4) ? -1.0f : 1.0f) * (Size / 4.0f); please explain thease code to me special on how to caculate the xOff and ZOff and YOff value,tell me where they come?
11. ## Noise function

why does no man give me an correct answer ,I need to buid na desert terrain /jungle terrain,so it is random height or use some special picture,so please first give me some noise function use in Rts 4 game produce differnt terrain!please email me at [email="frankluna11@yahoo.com"]frankluna11@yahoo.com[/email]
12. ## Noise function

I read the book<Programming Rts game programming with directx>I find a function Name is Noise,they are shown as below the are use to produce random height use for Terrain!if someone undertstand the code please explain to me! float Noise(int x) { x = (x<<13) ^ x; return (1.0 - ((x * (x*x * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0); } float CosInterpolate(float v1, float v2, float a) { float angle = a * D3DX_PI; float prc = (1.0f - cos(angle)) * 0.5f; return v1*(1.0f - prc) + v2*prc; }
13. ## Does someone undersatnd the code

Don't understand why the ind[index++] = z0 * (width + 1) + x0; and for you reply why you says gird[2][6] = gird1D(6*8+2) ok the code from here I don't understand : for( z=source.top, z0 = 0;z<source.bottom;z++, z0++) for(int x=source.left, x0 = 0;x<source.right;x++, x0++) { //Triangle 1 ind[index++] = z0 * (width + 1) + x0; ind[index++] = z0 * (width + 1) + x0 + 1; ind[index++] = (z0+1) * (width + 1) + x0; //Triangle 2 ind[index++] = (z0+1) * (width + 1) + x0; ind[index++] = z0 * (width + 1) + x0 + 1; ind[index++] = (z0+1) * (width + 1) + x0 + 1; } m_pMesh->UnlockIndexBuffer(); //Set Attributes DWORD *att = 0, a = 0; m_pMesh->LockAttributeBuffer(0,&att); memset(att, 0, sizeof(DWORD)*nrTri); m_pMesh->UnlockAttributeBuffer(); it's so hard to understand the concept of save the vertices into traingles,and another things please explain D3DXCreateMeshFVF function!and what that mean attributes?
14. ## Did someone can share his learn methoods

Hi actually is not just on thread ,you will look the title is really diffrent,one request is want to get a learn plan,second is try to get a explain on that code
15. ## Does someone undersatnd the code

the code has a FVF define as:const DWORD TERRAINVertex::FVF = D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1;the book says have two UV coordinate first alpha second color,but I don't really understand the all code as here! const DWORD TERRAINVertex::FVF = D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1; ////////////////////////////////////////////////////////////////////////////////////////// // PATCH // ////////////////////////////////////////////////////////////////////////////////////////// PATCH::PATCH() { m_pDevice = NULL; m_pMesh = NULL; } PATCH::~PATCH() { Release(); } void PATCH::Release() { if(m_pMesh != NULL) m_pMesh->Release(); m_pMesh = NULL; } HRESULT PATCH::CreateMesh(HEIGHTMAP &hm, RECT source, IDirect3DDevice9* Dev) { if(m_pMesh != NULL) { m_pMesh->Release(); m_pMesh = NULL; } try { m_pDevice = Dev; int width = source.right - source.left; int height = source.bottom - source.top; int nrVert = (width + 1) * (height + 1); int nrTri = width * height * 2; if(FAILED(D3DXCreateMeshFVF(nrTri, nrVert, D3DXMESH_MANAGED, TERRAINVertex::FVF, m_pDevice, &m_pMesh))) { debug.Print("Couldn't create mesh for PATCH"); return E_FAIL; } //Create vertices TERRAINVertex* ver = 0; m_pMesh->LockVertexBuffer(0,(void**)&ver); for(int z=source.top, z0 = 0;z<=source.bottom;z++, z0++) for(int x=source.left, x0 = 0;x<=source.right;x++, x0++) { D3DXVECTOR3 pos = D3DXVECTOR3(x, hm.m_pHeightMap[x + z * hm.m_size.x], -z); D3DXVECTOR2 uv = D3DXVECTOR2(x * 0.2f, z * 0.2f); ver[z0 * (width + 1) + x0] = TERRAINVertex(pos, uv); } m_pMesh->UnlockVertexBuffer(); //Calculate Indices WORD* ind = 0; m_pMesh->LockIndexBuffer(0,(void**)&ind); int index = 0; for( z=source.top, z0 = 0;z<source.bottom;z++, z0++) for(int x=source.left, x0 = 0;x<source.right;x++, x0++) { //Triangle 1 ind[index++] = z0 * (width + 1) + x0; ind[index++] = z0 * (width + 1) + x0 + 1; ind[index++] = (z0+1) * (width + 1) + x0; //Triangle 2 ind[index++] = (z0+1) * (width + 1) + x0; ind[index++] = z0 * (width + 1) + x0 + 1; ind[index++] = (z0+1) * (width + 1) + x0 + 1; } m_pMesh->UnlockIndexBuffer(); //Set Attributes DWORD *att = 0, a = 0; m_pMesh->LockAttributeBuffer(0,&att); for( z=source.top;z<source.bottom;z++) for(int x=source.left;x<source.right;x++) { //Calculate quad subsets depending on height int subset; if(hm.m_pHeightMap[x + z * hm.m_size.x] == 0.0f) subset = 0; else if(hm.m_pHeightMap[x + z * hm.m_size.x] <= hm.m_maxHeight * 0.6f) subset = 1; else subset = 2; att[a++] = subset; att[a++] = subset; } m_pMesh->UnlockAttributeBuffer(); //Compute normals D3DXComputeNormals(m_pMesh, NULL); } catch(...) { debug.Print("Error in PATCH::CreateMesh()"); return E_FAIL; } return S_OK; } void PATCH::Render(int texture) { //Draw mesh if(m_pMesh != NULL) m_pMesh->DrawSubset(texture); } Did you can tell me how to understand D3DCreateMeshFVF?