Jump to content
  • Advertisement

GrahamZ

Member
  • Content Count

    15
  • Joined

  • Last visited

Community Reputation

122 Neutral

About GrahamZ

  • Rank
    Member
  1. Hi, I'm using Direct3D 8.1. I'm running in windowed mode and want to do some stuff with ordinary dialog boxes. When I pause the game, the still on the screen reacts badly to the dialog boxes and drop down menus. So I'm thinking if I can take what's on the back buffer and turn it into a bitmap I can use the GDI while the game's paused. I've tried a bunch of things but nothing's worked very well. How do I convert what's on a LPDIRECT3DSURFACE8 to a BITMAP? Or should I be going about this in some other way? Thanks in advance. [Edited by - GrahamZ on August 25, 2004 3:41:28 AM]
  2. GrahamZ

    Inside D3DXIntersect()

    My understanding is the ray is defined parametrically by orig + t(dir); at least in the Moller/Trumbore style functions. I'm assuming the D3DX functions would be the same. I don't know what the implications would be if they weren't. ... Got a version of the Badouel algorithm working. That'll do me. Thankyou all. GrahamZ. [Edited by - GrahamZ on July 27, 2004 5:49:52 AM]
  3. GrahamZ

    Inside D3DXIntersect()

    This is getting wierder. If I replace the call to IntersectTriangle() with a call to D3DXIntersectTri(), everything works fine. Which raises the question: "What's wrong with the IntersectTriangle() function in the Pick sample?" The only change I made to IntersectTriangle() was deleting "CMyD3DApplication::" from in front of it. For comparison, I just took the intersect_triangle() function from www.acm.org/jgt/papers/MollerTrumbore97/ and tested it. It behaved the same way as IntersectTriangle(). (I changed all the 3 element double arrays to D3DXVECTOR3 structures and so on to make it fit in.) A triangle intersection algorithm that I can type up myself and understand is what I'm doing this for. This is the version of intersect_triangle() I'm using: int intersect_triangle(const D3DXVECTOR3 &orig, const D3DXVECTOR3 &dir, const D3DXVECTOR3 &vert0, const D3DXVECTOR3 &vert1, const D3DXVECTOR3 &vert2, FLOAT *t, FLOAT *u, FLOAT *v) { D3DXVECTOR3 edge1, edge2, tvec, pvec, qvec; FLOAT det, inv_det; /* find vectors for two edges sharing vert0 */ edge1 = vert1 - vert0; edge2 = vert2 - vert0; /* begin calculating determinant - also used to calculate U parameter */ D3DXVec3Cross(&pvec, &dir, &edge2); /* if determinant is near zero, ray lies in plane of triangle */ det = D3DXVec3Dot(&edge1, &pvec); #ifdef TEST_CULL /* define TEST_CULL if culling is desired */ if (det < EPSILON) return 0; /* calculate distance from vert0 to ray origin */ tvec = orig - vert0; /* calculate U parameter and test bounds */ *u = D3DXVec3Dot(&tvec, &pvec); if (*u < 0.0f || *u > det) return 0; /* prepare to test V parameter */ D3DXVec3Cross(&qvec, &tvec, &edge1); /* calculate V parameter and test bounds */ *v = D3DXVec3Dot(&dir, &qvec); if (*v < 0.0f || *u + *v > det) return 0; /* calculate t, scale parameters, ray intersects triangle */ *t = D3DXVec3Dot(&edge2, &qvec); inv_det = 1.0f / det; *t *= inv_det; *u *= inv_det; *v *= inv_det; #else /* the non-culling branch */ if (det > -EPSILON && det < EPSILON) return 0; inv_det = 1.0f / det; /* calculate distance from vert0 to ray origin */ tvec = orig - vert0; /* calculate U parameter and test bounds */ *u = D3DXVec3Dot(&tvec, &pvec) * inv_det; if (*u < 0.0f || *u > 1.0f) return 0; /* prepare to test V parameter */ D3DXVec3Cross(&qvec, &tvec, &edge1); /* calculate V parameter and test bounds */ *v = D3DXVec3Dot(&dir, &qvec) * inv_det; if (*v < 0.0f || *u + *v > 1.0f) return 0; /* calculate t, ray intersects triangle */ *t = D3DXVec3Dot(&edge2, &qvec) * inv_det; #endif return 1; } And IntersectTriangle() looks like this: BOOL IntersectTriangle(const D3DXVECTOR3& orig, const D3DXVECTOR3& dir, D3DXVECTOR3& v0, D3DXVECTOR3& v1, D3DXVECTOR3& v2, FLOAT* t, FLOAT* u, FLOAT* v ) { // Find vectors for two edges sharing vert0 D3DXVECTOR3 edge1 = v1 - v0; D3DXVECTOR3 edge2 = v2 - v0; // Begin calculating determinant - also used to calculate U parameter D3DXVECTOR3 pvec; D3DXVec3Cross( &pvec, &dir, &edge2 ); // If determinant is near zero, ray lies in plane of triangle FLOAT det = D3DXVec3Dot( &edge1, &pvec ); D3DXVECTOR3 tvec; if( det > 0 ) { tvec = orig - v0; } else { tvec = v0 - orig; det = -det; } if( det < 0.0001f ) return FALSE; // Calculate U parameter and test bounds *u = D3DXVec3Dot( &tvec, &pvec ); if( *u < 0.0f || *u > det ) return FALSE; // Prepare to test V parameter D3DXVECTOR3 qvec; D3DXVec3Cross( &qvec, &tvec, &edge1 ); // Calculate V parameter and test bounds *v = D3DXVec3Dot( &dir, &qvec ); if( *v < 0.0f || *u + *v > det ) return FALSE; // Calculate t, scale parameters, ray intersects triangle *t = D3DXVec3Dot( &edge2, &qvec ); FLOAT fInvDet = 1.0f / det; *t *= fInvDet; *u *= fInvDet; *v *= fInvDet; return TRUE; }
  4. Does anyone know how D3DXIntersect() works inside? I'm trying to make my own version and it's not working right. I'm using the IntersectTriangle() function from the Pick sample in the SDK I'm using (DirectX 8.1) to do the actual intersection test. So all my IntersectMesh() function does is cycle through each face in the mesh. I've made all the function parameters the same as D3DXIntersect() so I don't have to change the rest of the code (just the name of the function in the call). I'm using it for collision detection. When the camera crashes into the mesh I bounce off. With D3DXIntersect() it works fine, but with my own version, it still seems to work fine if I'm travelling fast enough, but at slow speeds I just kind of sink into the surface and get stuck there. Here's what I've got now: HRESULT IntersectMesh(LPD3DXBASEMESH pMesh, CONST D3DXVECTOR3 *pRayPos, CONST D3DXVECTOR3 *pRayDir, BOOL *pHit, DWORD *pFaceIndex, FLOAT *pU, FLOAT *pV, FLOAT *pDist) { HRESULT r = 0; *pHit = FALSE; //minT begins ridiculously large. float minT = 1e30f; //Get number of faces in mesh. DWORD numFaces = pMesh->GetNumFaces(); //Test each face for ray intersection. for(DWORD face = 0; face<numFaces; face++) { //Retieve face vertices V0, V1, V2. //... //Test face for ray intersect. //If t<minT, pHit is TRUE, //and store face index, u, v and t. float t, u, v; if(IntersectTriangle(*pRayPos, *pRayDir, *V0, *V1, *V2, &t, &u, &v)) { if(t<minT) { *pHit = TRUE; *pFaceIndex = face; *pU = u; *pV = v; *pDist = minT = t; } } } return r; }
  5. GrahamZ

    Between camera- and world-space

    Everything seems to be working just fine now. Thankyou very much. GrahamZ. [Edited by - GrahamZ on June 19, 2004 3:07:01 AM]
  6. I'm using DirectX 8. How do I transform a vector in camera-space to world-space so that I can make a change to it? I then need to transform the changed vector from world-space back to camera-space. I don't have the roll, pitch and yaw of the camera; but I do have the camera-space vectors right, up and lookat. If not too much trouble please post some code; but any help welcome. Thanks in advance, GrahamZ.
  • 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!