BOOL Game::checkCollision(D3DXVECTOR3 pos,D3DXVECTOR3 look,int bulletNo) { for(int i=0;i<enemyManager->noEnemyObject;i++) { D3DXVECTOR3 p=enemyManager->EnemyObjects.at(i)->position; D3DXVECTOR3 modelPosruc=p,modelPosllc=p,modelPosruc1,modelPosllc1; //-378.749969 20.000000 -56.944309 /*modelPosllc.x=-323.443420; modelPosllc.y=0; modelPosllc.z=-76.979378; modelPosruc.x=-392.181702; modelPosruc.y=100; modelPosruc.z=-21.086603; */ //right side corner modelPosruc.x=modelPosllc.x+10; modelPosruc.y=modelPosllc.y+10; modelPosruc.z=modelPosllc.z-10; //left side corner modelPosllc.x=modelPosllc.x-10; modelPosllc.y=modelPosllc.y-35; modelPosllc.z=modelPosllc.z+10; modelPosllc1=modelPosruc; modelPosruc1=modelPosllc; if(D3DXBoxBoundProbe(&modelPosllc,&modelPosruc,&pos,&look)||D3DXBoxBoundProbe(&modelPosruc,&modelPosruc,&pos,&look) && enemyManager->EnemyObjects.at(i)->disabled==false) { hitCount++; hit[i]=true; enemyManager->DisableEnemyObject(i); if(bcolor==D3DXCOLOR(0.5,0.0,0.5,0)) bcolor=D3DXCOLOR(0,0.5,0.5,0); else bcolor=D3DXCOLOR(0.5,0,0.5,0); return true; } } return false; }
bool BoundingBox::IntersectsRay(Vector3f rayOrigin, Vector3f rayDir, bool localSpace)const { //if local space is specified, transform ray to local space if (localSpace) { TransformRayToLocalSpace(&rayOrigin,&rayDir); } return D3DXBoxBoundProbe(&mBoundsMin,&mBoundsMax,&rayOrigin,&rayDir) != 0; }
//----------------------------------------------------------------------------- // Recursively checks the given ray against the scene's leaves and faces. //----------------------------------------------------------------------------- void SceneManager::RecursiveSceneRayCheck( SceneLeaf *leaf, RayIntersectionResult *result, D3DXVECTOR3 rayPosition, D3DXVECTOR3 rayDirection, float *hitDistance ) { // Check against the ray against the scene leaf. if( D3DXBoxBoundProbe( &leaf->GetBoundingBox()->min, &leaf->GetBoundingBox()->max, &rayPosition, &rayDirection ) == false ) return; // Recursively check the scene's children. for( char c = 0; c < 8; c++ ) if( leaf->children[c] != NULL ) RecursiveSceneRayCheck( leaf->children[c], result, rayPosition, rayDirection, hitDistance ); // Check the faces in this leaf. for( unsigned long f = 0; f < leaf->totalFaces; f++ ) { // Skip this face if its material is set to ignore rays. if( m_faces[leaf->faces[f]].renderCache->GetMaterial()->GetIgnoreRay() == true ) continue; // Check the ray against this face. if( D3DXIntersectTri( (D3DXVECTOR3*)&m_vertices[m_faces[leaf->faces[f]].vertex0], (D3DXVECTOR3*)&m_vertices[m_faces[leaf->faces[f]].vertex1], (D3DXVECTOR3*)&m_vertices[m_faces[leaf->faces[f]].vertex2], &rayPosition, &rayDirection, NULL, NULL, hitDistance ) == TRUE ) { if( *hitDistance < result->distance || result->material == NULL ) { ( *result ).distance = *hitDistance; ( *result ).material = m_faces[leaf->faces[f]].renderCache->GetMaterial(); } } } }
void optQ2 ( int n, D3DXVECTOR3 o_pos, D3DXVECTOR3 n_pos, float BoundingSphere ) { D3DXVECTOR3 min, max; if ( n >= 0 ) { min = ConvertVectorFromQ3 ( node_list2 [ n ].mins ); max = ConvertVectorFromQ3 ( node_list2 [ n ].maxs ); } else { min = ConvertVectorFromQ3 ( leaf_list2 [ -n - 1 ].mins ); max = ConvertVectorFromQ3 ( leaf_list2 [ -n - 1 ].maxs ); } float c = BoundingSphere; min -= D3DXVECTOR3 ( c, c, c ); max += D3DXVECTOR3 ( c, c, c ); if ( D3DXBoxBoundProbe ( &min, &max, &o_pos, &( n_pos - o_pos ) ) && D3DXBoxBoundProbe ( &min, &max, &n_pos, &( o_pos - n_pos ) ) ) { if ( n < 0 ) { for ( int x = 0; x < leaf_list2 [ -n - 1 ].numleaffaces; x++ ) { int face_idx = leafface_list [ leaf_list2 [ -n - 1 ].firstleafface + x ]; if ( QMAP.faces [ face_idx ].flags & ( QSURF_NODRAW | QSURF_HINT | QSURF_SKIP | QSURF_SKY ) ) continue; col_opt_Q12.check [ face_idx ] = TRUE; } return; } optQ2 ( node_list2 [ n ].children [ 0 ], o_pos, n_pos, BoundingSphere ); optQ2 ( node_list2 [ n ].children [ 1 ], o_pos, n_pos, BoundingSphere ); } }
////////////////////////////////////////////////////////////////////////// // CheckSpearing ////////////////////////////////////////////////////////////////////////// void ZClothEmblem::CheckSpearing( rvector& bullet_begin_, rvector& bullet_end_, float power_ ) { if(mbIsInFrustrum) { if(!isInViewFrustum( &mAABB, RGetViewFrustum())) mbIsInFrustrum =false; } else return; rvector dir = bullet_end_ - bullet_begin_; D3DXVec3Normalize( &dir, &dir ); // test line vs AABB if( !D3DXBoxBoundProbe( &mAABB.vmin , &mAABB.vmax, &bullet_begin_, &dir ) ) { return; } // line vs triangle test and determine which particle get power int index[3], sIndex = -1; rvector uvt; rvector* v[3]; for( int i = 0 ; i < mpMeshNode->m_face_num; ++i ) { for( int j = 0 ; j < 3; ++j ) { index[j]= mpMeshNode->m_face_list[i].m_point_index[j]; v[j] = &m_pX[index[j]]; } if( D3DXIntersectTri( v[0], v[1], v[2], &bullet_begin_, &dir, &uvt.x, &uvt.y, &uvt.z ) ) { if( uvt.x + uvt.y < 0.66 ) { sIndex = index[2]; } else if( uvt.x > uvt.y ) { sIndex = index[0]; } else { sIndex = index[1]; } m_pForce[sIndex] += dir * power_; break; } } }
bool OBB::Intersect(Ray &ray) { D3DXMATRIX p, r, world; D3DXMatrixTranslation(&p, m_pos.x, m_pos.y, m_pos.z); D3DXMatrixRotationQuaternion(&r, &m_rot); D3DXMatrixMultiply(&world, &r, &p); D3DXMatrixInverse(&world, NULL, &world); D3DXVECTOR3 org, dir; D3DXVec3TransformCoord(&org, &ray.m_org, &world); D3DXVec3TransformNormal(&dir, &ray.m_dir, &world); return D3DXBoxBoundProbe(&(-m_size), &m_size, &org, &dir) == TRUE; }
bool BoundingBox::IntersectsRay(Vector3f rayOrigin, Vector3f rayDir, Vector3f *outLocalRayOrigin, Vector3f *outLocalRayDir)const { TransformRayToLocalSpace(&rayOrigin,&rayDir); bool hit = D3DXBoxBoundProbe(&mBoundsMin,&mBoundsMax,&rayOrigin,&rayDir) != 0; if (hit) { *outLocalRayOrigin = rayOrigin; *outLocalRayDir = rayDir; } else { outLocalRayOrigin = nullptr; outLocalRayDir = nullptr; } return hit; }
float RAY::Intersect(BBOX bBox) { if(D3DXBoxBoundProbe(&bBox.min, &bBox.max, &org, &dir)) return D3DXVec3Length(&(((bBox.min + bBox.max) / 2.0f) - org)); else return -1.0f; }
static void D3DXBoundProbeTest(void) { BOOL result; D3DXVECTOR3 bottom_point, center, top_point, raydirection, rayposition; FLOAT radius; /*____________Test the Box case___________________________*/ bottom_point.x = -3.0f; bottom_point.y = -2.0f; bottom_point.z = -1.0f; top_point.x = 7.0f; top_point.y = 8.0f; top_point.z = 9.0f; raydirection.x = -4.0f; raydirection.y = -5.0f; raydirection.z = -6.0f; rayposition.x = 5.0f; rayposition.y = 5.0f; rayposition.z = 11.0f; result = D3DXBoxBoundProbe(&bottom_point, &top_point, &rayposition, &raydirection); ok(result == TRUE, "expected TRUE, received FALSE\n"); raydirection.x = 4.0f; raydirection.y = 5.0f; raydirection.z = 6.0f; rayposition.x = 5.0f; rayposition.y = 5.0f; rayposition.z = 11.0f; result = D3DXBoxBoundProbe(&bottom_point, &top_point, &rayposition, &raydirection); ok(result == FALSE, "expected FALSE, received TRUE\n"); rayposition.x = -4.0f; rayposition.y = 1.0f; rayposition.z = -2.0f; result = D3DXBoxBoundProbe(&bottom_point, &top_point, &rayposition, &raydirection); ok(result == TRUE, "expected TRUE, received FALSE\n"); bottom_point.x = 1.0f; bottom_point.y = 0.0f; bottom_point.z = 0.0f; top_point.x = 1.0f; top_point.y = 0.0f; top_point.z = 0.0f; rayposition.x = 0.0f; rayposition.y = 1.0f; rayposition.z = 0.0f; raydirection.x = 0.0f; raydirection.y = 3.0f; raydirection.z = 0.0f; result = D3DXBoxBoundProbe(&bottom_point, &top_point, &rayposition, &raydirection); ok(result == FALSE, "expected FALSE, received TRUE\n"); bottom_point.x = 1.0f; bottom_point.y = 2.0f; bottom_point.z = 3.0f; top_point.x = 10.0f; top_point.y = 15.0f; top_point.z = 20.0f; raydirection.x = 7.0f; raydirection.y = 8.0f; raydirection.z = 9.0f; rayposition.x = 3.0f; rayposition.y = 7.0f; rayposition.z = -6.0f; result = D3DXBoxBoundProbe(&bottom_point, &top_point, &rayposition, &raydirection); ok(result == TRUE, "expected TRUE, received FALSE\n"); bottom_point.x = 0.0f; bottom_point.y = 0.0f; bottom_point.z = 0.0f; top_point.x = 1.0f; top_point.y = 1.0f; top_point.z = 1.0f; raydirection.x = 0.0f; raydirection.y = 1.0f; raydirection.z = .0f; rayposition.x = -3.0f; rayposition.y = 0.0f; rayposition.z = 0.0f; result = D3DXBoxBoundProbe(&bottom_point, &top_point, &rayposition, &raydirection); ok(result == FALSE, "expected FALSE, received TRUE\n"); raydirection.x = 1.0f; raydirection.y = 0.0f; raydirection.z = .0f; rayposition.x = -3.0f; rayposition.y = 0.0f; rayposition.z = 0.0f; result = D3DXBoxBoundProbe(&bottom_point, &top_point, &rayposition, &raydirection); ok(result == TRUE, "expected TRUE, received FALSE\n"); /*____________Test the Sphere case________________________*/ radius = sqrt(77.0f); center.x = 1.0f; center.y = 2.0f; center.z = 3.0f; raydirection.x = 2.0f; raydirection.y = -4.0f; raydirection.z = 2.0f; rayposition.x = 5.0f; rayposition.y = 5.0f; rayposition.z = 9.0f; result = D3DXSphereBoundProbe(¢er, radius, &rayposition, &raydirection); ok(result == TRUE, "expected TRUE, received FALSE\n"); rayposition.x = 45.0f; rayposition.y = -75.0f; rayposition.z = 49.0f; result = D3DXSphereBoundProbe(¢er, radius, &rayposition, &raydirection); ok(result == FALSE, "expected FALSE, received TRUE\n"); rayposition.x = 5.0f; rayposition.y = 11.0f; rayposition.z = 9.0f; result = D3DXSphereBoundProbe(¢er, radius, &rayposition, &raydirection); ok(result == FALSE, "expected FALSE, received TRUE\n"); }
float SFRay::IntersectBox(AABB bbox) { if(D3DXBoxBoundProbe(&bbox.minPt, &bbox.maxPt, &mOrigin, &mDirection)) return D3DXVec3Length(&(((bbox.minPt + bbox.maxPt) / 2.0f) - mOrigin)); else return -1.0f; }