void CTank::calcDirBottom() { float x,y,z; // 移動方向の左右確認 static D3DXVECTOR2 v1,v2; v1.x = _BottomDir.x; v1.y = _BottomDir.z; v2.x = _MoveVec.x; v2.y = _MoveVec.z; float fCross = D3DXVec2CCW(&v1,&v2); // 外積 float fDot; // 左右判定 if(fCross > 0) { turnBottom(_fTurnSpeed); } else if(fCross < 0) { turnBottom(-_fTurnSpeed); } else { fDot = D3DXVec3Dot(&_BottomDir,&_MoveVec); if(fDot < 0) { turnBottom(_fTurnSpeed); } } x = _matBottom._41; y = _matBottom._42; z = _matBottom._43; static const D3DXVECTOR3 XV(0.0f,0.0f,1.0f); D3DXVec3Normalize(&_BottomDir,&_BottomDir); _matBottom._41 = _matBottom._42 = _matBottom._43 = 0; D3DXMatrixRotationY(&_matBottom,-atan2f(_BottomDir.z,_BottomDir.x) + 0.5F*3.1415f); _matBottom._41 = x; _matBottom._42 = y; _matBottom._43 = z; }
//============================================================================= // is hit line //============================================================================= bool CollisionCircle::IsHitLine(const D3DXVECTOR2& position,const D3DXVECTOR2& start,const D3DXVECTOR2& end)const { D3DXVECTOR2 vector_l = end - start; D3DXVECTOR2 vector_a = position_ - (start + position); D3DXVECTOR2 vector_b = position_ - (end + position); f32 distance = D3DXVec2CCW(&vector_l,&vector_a) / D3DXVec2Length(&vector_l); if(distance <= radius_) { if(D3DXVec2Dot(&vector_a,&vector_l) * D3DXVec2Dot(&vector_b,&vector_l) <= 0) { return true; } if(D3DXVec2Length(&vector_a) <= radius_ || D3DXVec2Length(&vector_b) <= radius_) { return true; } } return false; }
//============================================================================= // is hit line //============================================================================= bool CollisionPoint::IsHitLine(const D3DXVECTOR2& position,const D3DXVECTOR2& start,const D3DXVECTOR2& end)const { D3DXVECTOR2 vector_l = end - start; D3DXVECTOR2 vector_a = position_ - (start + position); D3DXVECTOR2 vector_b = position_ - (end + position); f32 cross = D3DXVec2CCW(&vector_l,&vector_a); if(cross <= 0.0001f || cross >= -0.0001f) { cross = 0.0f; } if(cross == 0.0f) { if(D3DXVec2Dot(&vector_a,&vector_l) >= 0 && D3DXVec2Length(&vector_l) >= D3DXVec2Length(&vector_a)) { return true; } } return false; }
int CBgDisp2::MoveTexUV( D3DXMATRIX matView ) { int i; D3DTLVERTEX* tlvptr1 = m_tlv1; D3DTLVERTEX2* tlvptr2 = m_tlv2; if( (uanime != 0.0f) || (vanime != 0.0f ) ){ for( i = 0; i < BGTLVNUM; i++ ){ tlvptr2->tu2 += uanime; tlvptr2->tv2 += vanime; tlvptr2++; } } if( isround ){ D3DXVECTOR3 vecbef;// = {0.0, 0.0, -1.0}; D3DXVECTOR3 vecaft; vecbef.x = 0.0f; vecbef.y = 0.0f; vecbef.z = -1.0f; float lx = vecbef.x; float ly = vecbef.y; float lz = vecbef.z; //!!!! 平行移動成分は、加味しない。 vecaft.x = matView._11*lx + matView._21*ly + matView._31*lz;// + matView._41; vecaft.y = matView._12*lx + matView._22*ly + matView._32*lz;// + matView._42; vecaft.z = matView._13*lx + matView._23*ly + matView._33*lz;// + matView._43; D3DXVec3Normalize( &vecaft, &vecaft ); D3DXVECTOR2 vec0; // = {0.0f, -1.0f}; D3DXVECTOR2 vec1; vec0.x = 0.0f; vec0.y = -1.0f; vec1.x = vecaft.x; vec1.y = vecaft.z; D3DXVec2Normalize( &vec1, &vec1 ); float dot; dot = D3DXVec2Dot( &vec0, &vec1 ); float rad; if( dot <= -1.0f ) dot = -1.0f; else if( dot >= 1.0f ) dot = 1.0f; rad = (float)acos( dot ); float ccw; ccw = D3DXVec2CCW( &vec0, &vec1 ); //float roty; //if( ccw >= 0.0f ){ // roty = -rad; //}else{ // roty = rad; //} float roty; if( ccw >= 0.0f ){ roty = rad; }else{ roty = -rad; } float centeru; centeru = 0.5f + roty * ( 0.5f / PI ); float usize, befu, aftu; usize = 0.4f; befu = centeru - usize; aftu = centeru + usize; //if( befu < 0.0f ) // befu += 1.0f; //if( aftu > 1.0f ) // aftu -= 1.0f; _ASSERT( BGUNUM == 3 );//!!!!!!!!!!!!!!!!! int uno, vno; int tlvno = 0; for( vno = 0; vno < BGVNUM; vno++ ){ for( uno = 0; uno < BGUNUM; uno++ ){ if( uno == 0 ){ m_tlv1[tlvno].tu = befu; m_tlv2[tlvno].tu1 = befu; }else if( uno == 1 ){ m_tlv1[tlvno].tu = centeru; m_tlv2[tlvno].tu1 = centeru; }else if( uno == 2 ){ m_tlv1[tlvno].tu = aftu; m_tlv2[tlvno].tu1 = aftu; }else{ _ASSERT( 0 ); m_tlv1[tlvno].tu = 0.0f; m_tlv2[tlvno].tu1 = 0.0f; } tlvno++; } } } return 0; }