Pyrogenesis  trunk
MikktspaceWrap.h
Go to the documentation of this file.
1 /* Copyright (C) 2012 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef INCLUDED_MIKKWRAP
19 #define INCLUDED_MIKKWRAP
20 
21 
23 
25 {
26 
27 public:
28 
29  MikkTSpace(const CModelDefPtr& m, std::vector<float>& v, bool gpuSkinning);
30 
31  void generate();
32 
33 private:
34 
37 
39 
40  std::vector<float>& m_NewVertices;
42 
43 
44  // Returns the number of faces (triangles/quads) on the mesh to be processed.
45  static int getNumFaces(const SMikkTSpaceContext *pContext);
46 
47 
48  // Returns the number of vertices on face number iFace
49  // iFace is a number in the range {0, 1, ..., getNumFaces()-1}
50  static int getNumVerticesOfFace(const SMikkTSpaceContext *pContext, const int iFace);
51 
52 
53  // returns the position/normal/texcoord of the referenced face of vertex number iVert.
54  // iVert is in the range {0,1,2} for triangles and {0,1,2,3} for quads.
55  static void getPosition(const SMikkTSpaceContext *pContext,
56  float fvPosOut[], const int iFace, const int iVert);
57 
58  static void getNormal(const SMikkTSpaceContext *pContext,
59  float fvNormOut[], const int iFace, const int iVert);
60 
61  static void getTexCoord(const SMikkTSpaceContext *pContext,
62  float fvTexcOut[], const int iFace, const int iVert);
63 
64 
65  // This function is used to return tangent space results to the application.
66  // fvTangent and fvBiTangent are unit length vectors and fMagS and fMagT are their
67  // true magnitudes which can be used for relief mapping effects.
68  // fvBiTangent is the "real" bitangent and thus may not be perpendicular to fvTangent.
69  // However, both are perpendicular to the vertex normal.
70  // For normal maps it is sufficient to use the following simplified version of the bitangent which is generated at pixel/vertex level.
71  // fSign = bIsOrientationPreserving ? 1.0f : (-1.0f);
72  // bitangent = fSign * cross(vN, tangent);
73  static void setTSpace(const SMikkTSpaceContext * pContext, const float fvTangent[],
74  const float fvBiTangent[], const float fMagS, const float fMagT,
75  const tbool bIsOrientationPreserving, const int iFace, const int iVert);
76 
77 
78 };
79 
80 
81 #endif // INCLUDED_MIKKWRAP
bool m_GpuSkinning
Definition: MikktspaceWrap.h:41
static void setTSpace(const SMikkTSpaceContext *pContext, const float fvTangent[], const float fvBiTangent[], const float fMagS, const float fMagT, const tbool bIsOrientationPreserving, const int iFace, const int iVert)
Definition: MikktspaceWrap.cpp:112
const CModelDefPtr & m_Model
Definition: MikktspaceWrap.h:38
static int getNumFaces(const SMikkTSpaceContext *pContext)
Definition: MikktspaceWrap.cpp:61
std::vector< float > & m_NewVertices
Definition: MikktspaceWrap.h:40
Definition: mikktspace.h:65
Definition: MikktspaceWrap.h:24
std::shared_ptr< CModelDef > CModelDefPtr
Definition: MeshManager.h:26
void generate()
Definition: MikktspaceWrap.cpp:55
SMikkTSpaceContext m_Context
Definition: MikktspaceWrap.h:36
static void getTexCoord(const SMikkTSpaceContext *pContext, float fvTexcOut[], const int iFace, const int iVert)
Definition: MikktspaceWrap.cpp:99
Definition: mikktspace.h:107
static void getNormal(const SMikkTSpaceContext *pContext, float fvNormOut[], const int iFace, const int iVert)
Definition: MikktspaceWrap.cpp:86
static void getPosition(const SMikkTSpaceContext *pContext, float fvPosOut[], const int iFace, const int iVert)
Definition: MikktspaceWrap.cpp:73
MikkTSpace(const CModelDefPtr &m, std::vector< float > &v, bool gpuSkinning)
Definition: MikktspaceWrap.cpp:35
int tbool
Copyright (C) 2011 by Morten S.
Definition: mikktspace.h:62
static int getNumVerticesOfFace(const SMikkTSpaceContext *pContext, const int iFace)
Definition: MikktspaceWrap.cpp:67
SMikkTSpaceInterface m_Interface
Definition: MikktspaceWrap.h:35