20 #pragma warning(disable : 4244) 33 List<int> collapse_map;
34 int renderpolycount=0;
35 Vector model_position;
36 Quaternion model_orientation;
75 int Map(
int a,
int mx) {
83 void DrawModelTriangles() {
84 assert(collapse_map.num);
87 for(i=0;i<tri.num;i++) {
88 int p0= Map(tri[i].v[0],render_num);
89 int p1= Map(tri[i].v[1],render_num);
90 int p2= Map(tri[i].v[2],render_num);
94 if(p0==p1 || p1==p2 || p2==p0)
continue;
98 int q0= Map(p0,(
int)(render_num*lodbase));
99 int q1= Map(p1,(
int)(render_num*lodbase));
100 int q2= Map(p2,(
int)(render_num*lodbase));
102 v0 = vert[p0]*morph + vert[q0]*(1-morph);
103 v1 = vert[p1]*morph + vert[q1]*(1-morph);
104 v2 = vert[p2]*morph + vert[q2]*(1-morph);
108 Vector nrml = (v1-v0) * (v2-v1);
109 if(0<magnitude(nrml)) {
120 void PermuteVertices(List<int> &permutation) {
122 List<Vector> temp_list;
124 assert(permutation.num==vert.num);
125 for(i=0;i<vert.num;i++) {
126 temp_list.Add(vert[i]);
128 for(i=0;i<vert.num;i++) {
129 vert[permutation[i]]=temp_list[i];
132 for(i=0;i<tri.num;i++) {
133 for(
int j=0;j<3;j++) {
134 tri[i].v[j] = permutation[tri[i].v[j]];
139 void GetRabbitData(){
143 for(i=0;i<RABBIT_VERTEX_NUM;i++) {
144 float *vp=rabbit_vertices[i];
145 vert.Add(Vector(vp[0],vp[1],vp[2]));
147 for(i=0;i<RABBIT_TRIANGLE_NUM;i++) {
149 td.v[0]=rabbit_triangles[i][0];
150 td.v[1]=rabbit_triangles[i][1];
151 td.v[2]=rabbit_triangles[i][2];
159 List<int> permutation;
161 ProgressiveMesh(vert,tri,collapse_map,permutation);
162 PermuteVertices(permutation);
163 model_position = Vector(0,0,-3);
164 Quaternion yaw(Vector(0,1,0),-3.14
f/4);
165 Quaternion pitch(Vector(1,0,0),3.14
f/12);
166 model_orientation = pitch*yaw;
172 float b = (float)render_num/(
float)vert.num;
173 float a = b*(lodbase );
174 glDisable(GL_LIGHTING);
175 glMatrixMode( GL_PROJECTION );
178 glOrtho(-0.15,15,-0.1,1.1,-0.1,100);
179 glMatrixMode( GL_MODELVIEW );
212 glMatrixMode( GL_PROJECTION );
214 glMatrixMode( GL_MODELVIEW );
221 struct keyframethings {
243 void AnimateParameters() {
248 while(time>keys[k+1].t) {
251 float interp = (time-keys[
k].t)/(keys[k+1].t-keys[k].t);
252 render_num = vert.num*(keys[
k].n + interp*keys[
k].dn);
253 morph = keys[
k].m + interp*keys[
k].dm;
254 morph = (morph>1.0f) ? 1.0
f : morph;
255 if(render_num>vert.num) render_num=vert.num;
256 if(render_num<0 ) render_num=0;
262 glEnable(GL_LIGHTING);
266 glTranslatef(model_position.x,model_position.y,model_position.z);
268 Vector axis=model_orientation.axis();
269 float angle=model_orientation.angle()*180.0f/3.14f;
270 glRotatef(angle,axis.x,axis.y,axis.z);
271 DrawModelTriangles();
276 sprintf(buf,
"Polys: %d Vertices: %d ",renderpolycount,render_num);
278 sprintf(buf+strlen(buf),
"<-> %d morph: %4.2f ",
279 (
int)(lodbase *render_num),morph);
281 PostString(buf,0,-2,5);
label k
Boltzmann constant.
quaternion normalize(const quaternion &q)
Return the normalized (unit) quaternion of the given quaternion.