| /* |
| * Mesh operations specific to D3DX9. |
| * |
| * Copyright (C) 2009 David Adam |
| * |
| * This library is free software; you can redistribute it and/or |
| * modify it under the terms of the GNU Lesser General Public |
| * License as published by the Free Software Foundation; either |
| * version 2.1 of the License, or (at your option) any later version. |
| * |
| * This library is distributed in the hope that it will be useful, |
| * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| * Lesser General Public License for more details. |
| * |
| * You should have received a copy of the GNU Lesser General Public |
| * License along with this library; if not, write to the Free Software |
| * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
| */ |
| |
| #include "config.h" |
| #include "windef.h" |
| #include "wingdi.h" |
| #include "d3dx9.h" |
| |
| |
| /************************************************************************* |
| * D3DXIntersectTri |
| */ |
| BOOL WINAPI D3DXIntersectTri(CONST D3DXVECTOR3 *p0, CONST D3DXVECTOR3 *p1, CONST D3DXVECTOR3 *p2, CONST D3DXVECTOR3 *praypos, CONST D3DXVECTOR3 *praydir, FLOAT *pu, FLOAT *pv, FLOAT *pdist) |
| { |
| D3DXMATRIX m; |
| D3DXVECTOR4 vec; |
| |
| m.m[0][0] = p1->x - p0->x; |
| m.m[1][0] = p2->x - p0->x; |
| m.m[2][0] = -praydir->x; |
| m.m[3][0] = 0.0f; |
| m.m[0][1] = p1->y - p0->z; |
| m.m[1][1] = p2->y - p0->z; |
| m.m[2][1] = -praydir->y; |
| m.m[3][1] = 0.0f; |
| m.m[0][2] = p1->z - p0->z; |
| m.m[1][2] = p2->z - p0->z; |
| m.m[2][2] = -praydir->z; |
| m.m[3][2] = 0.0f; |
| m.m[0][3] = 0.0f; |
| m.m[1][3] = 0.0f; |
| m.m[2][3] = 0.0f; |
| m.m[3][3] = 1.0f; |
| |
| vec.x = praypos->x - p0->x; |
| vec.y = praypos->y - p0->y; |
| vec.z = praypos->z - p0->z; |
| vec.w = 0.0f; |
| |
| if ( D3DXMatrixInverse(&m, NULL, &m) ) |
| { |
| D3DXVec4Transform(&vec, &vec, &m); |
| if ( (vec.x >= 0.0f) && (vec.y >= 0.0f) && (vec.x + vec.y <= 1.0f) && (vec.z >= 0.0f) ) |
| { |
| *pu = vec.x; |
| *pv = vec.y; |
| *pdist = fabs( vec.z ); |
| return TRUE; |
| } |
| } |
| |
| return FALSE; |
| } |