skinnedmesh.h
上传用户:qccn516
上传日期:2013-05-02
资源大小:3382k
文件大小:4k
源码类别:

游戏引擎

开发平台:

Visual C++

  1. /* SkinnedMesh
  2.  *
  3.  * Copyright (C) 2003-2004, Alexander Zaprjagaev <frustum@frustum.org>
  4.  *
  5.  * This program is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 2 of the License, or
  8.  * (at your option) any later version.
  9.  *
  10.  * This program is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  * GNU General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to the Free Software
  17.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18.  */
  19. #ifndef __SKINNED_MESH_H__
  20. #define __SKINNED_MESH_H__
  21. #include <vector>
  22. #include "mathlib.h"
  23. #define SKINNED_MESH_MAGIC ('s' | 'm' << 8 | '0' << 16 | '2' << 24)
  24. class SkinnedMesh {
  25. public:
  26. SkinnedMesh(const char *name);
  27. virtual ~SkinnedMesh();
  28. void setFrame(float frame,int from = -1,int to = -1);
  29. void calculateSkin();
  30. virtual int render(int ppl = 0,int s = -1);
  31. void findSilhouette(const vec4 &light,int s = -1);
  32. int getNumIntersections(const vec3 &line0,const vec3 &line1,int s = -1);
  33. virtual int renderShadowVolume(int s = -1);
  34. int intersection(const vec3 &line0,const vec3 &line1,vec3 &point,vec3 &normal,int s = -1);
  35. void transform(const mat4 &m);
  36. struct Bone {
  37. char name[128];
  38. mat4 transform;
  39. mat4 rotation;
  40. int parent;
  41. };
  42. struct Weight {
  43. int bone;
  44. float weight;
  45. vec3 xyz;
  46. vec3 normal;
  47. vec3 tangent;
  48. vec3 binormal;
  49. };
  50. struct Vertex {
  51. vec3 xyz;
  52. vec3 normal;
  53. vec3 tangent;
  54. vec3 binormal;
  55. vec2 texcoord;
  56. int num_weights;
  57. Weight *weights;
  58. };
  59. struct Edge {
  60. int v[2];
  61. char reverse;
  62. char flag;
  63. };
  64. struct Triangle {
  65. int v[3]; // vertexes
  66. int e[3]; // edges
  67. char reverse[3]; // edge reverse flag
  68. vec4 plane; // plane
  69. vec4 c[3]; // fast point in triangle
  70. char flag;
  71. };
  72. int getNumSurfaces();
  73. const char *getSurfaceName(int s);
  74. int getSurface(const char *name);
  75. int getNumBones();
  76. Bone *getBones();
  77. const char *getBoneName(int b);
  78. int getBone(const char *name);
  79. const mat4 &getBoneTransform(int b);
  80. int getNumVertex(int s);
  81. Vertex *getVertex(int s);
  82. int getNumEdges(int s);
  83. Edge *getEdges(int s);
  84. int getNumTriangles(int s);
  85. Triangle *getTriangles(int s);
  86. const vec3 &getMin(int s = -1);
  87. const vec3 &getMax(int s = -1);
  88. const vec3 &getCenter(int s = -1);
  89. float getRadius(int s = -1);
  90. int load(const char *name);
  91. int save(const char *name);
  92. protected:
  93. int load_binary(const char *name);
  94. void read_string(FILE *file,char *string);
  95. int load_ascii(const char *name);
  96. void calculate_tangent();
  97. void create_shadow_volumes();
  98. vec3 min;
  99. vec3 max;
  100. vec3 center;
  101. float radius;
  102. struct Frame {
  103. vec3 xyz; // pivot
  104. quat rot; // rotation
  105. };
  106. int num_bones;
  107. Bone *bones;
  108. int num_frames;
  109. Frame **frames;
  110. enum {
  111. NUM_SURFACES = 32,
  112. };
  113. struct Surface {
  114. char name[128]; // name
  115. int num_vertex; // no comment :)
  116. Vertex *vertex;
  117. int num_edges;
  118. Edge *edges;
  119. int num_triangles;
  120. Triangle *triangles;
  121. int num_indices;
  122. int *indeices;
  123. int num_shadow_volume_vertex; // number of last silhouette vertexes
  124. vec4 *shadow_volume_vertex;
  125. vec3 min; // bound box
  126. vec3 max;
  127. vec3 center; // bound sphere
  128. float radius;
  129. };
  130. int num_surfaces;
  131. Surface *surfaces[NUM_SURFACES];
  132. };
  133. #endif /* __SKINNED_MESH_H__ */