mapi32/tests: Fix typo.
[wine] / dlls / d3dx9_36 / mesh.c
1  /*
2  * Mesh operations specific to D3DX9.
3  *
4  * Copyright (C) 2009 David Adam
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include "config.h"
22 #include "windef.h"
23 #include "wingdi.h"
24 #include "wine/debug.h"
25 #include "d3dx9.h"
26
27 WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
28
29 /*************************************************************************
30  * D3DXIntersectTri
31  */
32 BOOL WINAPI D3DXIntersectTri(CONST D3DXVECTOR3 *p0, CONST D3DXVECTOR3 *p1, CONST D3DXVECTOR3 *p2, CONST D3DXVECTOR3 *praypos, CONST D3DXVECTOR3 *praydir, FLOAT *pu, FLOAT *pv, FLOAT *pdist)
33 {
34     D3DXMATRIX m;
35     D3DXVECTOR4 vec;
36
37     m.m[0][0] = p1->x - p0->x;
38     m.m[1][0] = p2->x - p0->x;
39     m.m[2][0] = -praydir->x;
40     m.m[3][0] = 0.0f;
41     m.m[0][1] = p1->y - p0->z;
42     m.m[1][1] = p2->y - p0->z;
43     m.m[2][1] = -praydir->y;
44     m.m[3][1] = 0.0f;
45     m.m[0][2] = p1->z - p0->z;
46     m.m[1][2] = p2->z - p0->z;
47     m.m[2][2] = -praydir->z;
48     m.m[3][2] = 0.0f;
49     m.m[0][3] = 0.0f;
50     m.m[1][3] = 0.0f;
51     m.m[2][3] = 0.0f;
52     m.m[3][3] = 1.0f;
53
54     vec.x = praypos->x - p0->x;
55     vec.y = praypos->y - p0->y;
56     vec.z = praypos->z - p0->z;
57     vec.w = 0.0f;
58
59     if ( D3DXMatrixInverse(&m, NULL, &m) )
60     {
61         D3DXVec4Transform(&vec, &vec, &m);
62         if ( (vec.x >= 0.0f) && (vec.y >= 0.0f) && (vec.x + vec.y <= 1.0f) && (vec.z >= 0.0f) )
63         {
64             *pu = vec.x;
65             *pv = vec.y;
66             *pdist = fabs( vec.z );
67             return TRUE;
68         }
69     }
70
71     return FALSE;
72 }