summaryrefslogtreecommitdiffstats
path: root/sdk/rwsdk/include/d3d8/rtbary.h
blob: 61c39b07eb1c6c6c8947e4e686f842d1d72d855b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/***************************************************************************
 *                                                                         *
 * Module  : rtbary.h                                                      *
 *                                                                         *
 * Purpose : Barycentric operations                                        *
 *                                                                         *
 **************************************************************************/

#ifndef RTBARY_H
#define RTBARY_H

/**
 * \defgroup rtbary RtBary
 * \ingroup rttool
 *
 * Barycentric Toolkit for RenderWare.
 */


/****************************************************************************
 Includes
 */

#include <rwcore.h>

#include <rtbary.rpe>          /* automatically generated header file */


/****************************************************************************
 Global types
 */

/**
 * \ingroup rtbary
 * \typedef RtBaryV4d
 * typedef for the 4 element homogeneous row of a transform matrix mapping 
 * a point from Cartesian space to the barycentric space defined by a triangle.
 */
typedef RwReal      RtBaryV4d[4];

/**
 * \ingroup rtbary
 * \typedef RtBaryTransform
 * typedef for the 4x4 homogeneous transform matrix mapping a point
 * from Cartesian space to the barycentric space defined by a triangle.
 */
typedef RtBaryV4d   RtBaryTransform[4];

/****************************************************************************
 Defines
 */

#define RtBaryV3dFromWeightsMacro(_out, _b, _v0, _v1, _v2)      \
MACRO_START                                                     \
{                                                               \
    (_out)->x = (RwReal)( ((_v0)->x * (_b)[0]) +                \
                          ((_v1)->x * (_b)[1]) +                \
                          ((_v2)->x * (_b)[2]) );               \
    (_out)->y = (RwReal)( ((_v0)->y * (_b)[0]) +                \
                          ((_v1)->y * (_b)[1]) +                \
                          ((_v2)->y * (_b)[2]) );               \
    (_out)->z = (RwReal)( ((_v0)->z * (_b)[0]) +                \
                          ((_v1)->z * (_b)[1]) +                \
                          ((_v2)->z * (_b)[2]) );               \
}                                                               \
MACRO_STOP

#define RtBaryWeightsFromV3dMacro(_out, _m, _in)        \
MACRO_START                                             \
{                                                       \
    (_out)[0] = ( (_m)[0][0] * (_in)->x +               \
                  (_m)[1][0] * (_in)->y +               \
                  (_m)[2][0] * (_in)->z +               \
                  (_m)[3][0] );                         \
    (_out)[1] = ( (_m)[0][1] * (_in)->x +               \
                  (_m)[1][1] * (_in)->y +               \
                  (_m)[2][1] * (_in)->z +               \
                  (_m)[3][1] );                         \
    (_out)[2] = ( (_m)[0][2] * (_in)->x +               \
                  (_m)[1][2] * (_in)->y +               \
                  (_m)[2][2] * (_in)->z +               \
                  (_m)[3][2] );                         \
    (_out)[3] = ( (_m)[0][3] * (_in)->x +               \
                  (_m)[1][3] * (_in)->y +               \
                  (_m)[2][3] * (_in)->z +               \
                  (_m)[3][3] );                         \
}                                                       \
MACRO_STOP

#if (! ( defined(RWDEBUG) || defined(RWSUPPRESSINLINE) ))

#define RtBaryV3dFromWeights(_out, _b, _v0, _v1, _v2)     \
        RtBaryV3dFromWeightsMacro(_out, _b, _v0, _v1, _v2)

#define RtBaryWeightsFromV3d(_out, _m, _in)               \
        RtBaryWeightsFromV3dMacro(_out, _m, _in)

#endif /* (! ( defined(RWDEBUG) || defined(RWSUPPRESSINLINE) )) */

/****************************************************************************
 Function prototypes
 */

#ifdef    __cplusplus
extern              "C"
{
#endif                          /* __cplusplus */

extern RwBool
RtBaryGetTransform(RtBaryTransform m,
                   RwReal * const area,
                   const RwV3d * const v0,
                   const RwV3d * const v1,
                   const RwV3d * const v2);

#if ( defined(RWDEBUG) || defined(RWSUPPRESSINLINE) )

extern void
RtBaryV3dFromWeights(RwV3d * const out,
                     const RtBaryV4d weights,
                     const RwV3d * const v0, 
                     const RwV3d * const v1, 
                     const RwV3d * const v2);

extern void
RtBaryWeightsFromV3d(RtBaryV4d out,
                        RtBaryTransform mat,
                        const RwV3d * const in);

extern void
_rtImportWorldBaryFromEdge(RtBaryV4d out,
                           RtBaryTransform mat,
                           const RwV3d * const in);

#endif   /* ( defined(RWDEBUG) || defined(RWSUPPRESSINLINE) ) */

#ifdef    __cplusplus
}
#endif                          /* __cplusplus */

#endif /* RTBARY_H */