diff TaskManager/Test/test_render/polygon.cpp @ 349:bd0cc480a60a draft

fix hash_regist
author admin@mcbk.cr.ie.u-ryukyu.ac.jp
date Fri, 10 Jul 2009 16:06:15 +0900
parents a046c5dac580
children 5b995810b86a
line wrap: on
line diff
--- a/TaskManager/Test/test_render/polygon.cpp	Thu Jul 09 17:59:44 2009 +0900
+++ b/TaskManager/Test/test_render/polygon.cpp	Fri Jul 10 16:06:15 2009 +0900
@@ -18,8 +18,6 @@
 extern int decode(char *cont, FILE *outfile);
 
 
-//SDL_Surface* Polygon::texture_image;
-
 Polygon::Polygon(void)
 {
     xyz[0] = 0;
@@ -36,7 +34,7 @@
     angle[3] = 1;
 
     for (int i = 0; i < 16; i++) {
-	matrix[i] = 0;
+        matrix[i] = 0;
     }
 }
 
@@ -57,7 +55,7 @@
     angle[3] = 1;
 
     for (int i = 0; i < 16; i++) {
-	matrix[i] = 0;
+        matrix[i] = 0;
     }
 }
 
@@ -69,43 +67,43 @@
     /***SceneGraphUpdate***/
     //sgp_update();
     for (int i = 0; i < sgp->info.size; i++) {
-	SceneGraphNode node = sgp->node[i];
+        SceneGraphNode node = sgp->node[i];
 
-	/***draw***/
-	int n,nt;
-	for(n=0,nt=0; n<node.size*3; n+=9,nt+=6) {
-	    xyz1[0] = node.vertex[n];
-	    xyz1[1] = node.vertex[n+1];
-	    xyz1[2] = node.vertex[n+2]*-1;
-	    xyz1[3] = 1;
-	    xyz2[0] = node.vertex[n+3];
-	    xyz2[1] = node.vertex[n+3+1];
-	    xyz2[2] = node.vertex[n+3+2]*-1;
-	    xyz2[3] = 1;
-	    xyz3[0] = node.vertex[n+6];
-	    xyz3[1] = node.vertex[n+6+1];
-	    xyz3[2] = node.vertex[n+6+2]*-1;
-	    xyz3[3] = 1;
+        /***draw***/
+        int n,nt;
+        for(n=0,nt=0; n<node.size*3; n+=9,nt+=6) {
+            xyz1[0] = node.vertex[n];
+            xyz1[1] = node.vertex[n+1];
+            xyz1[2] = node.vertex[n+2]*-1;
+            xyz1[3] = 1;
+            xyz2[0] = node.vertex[n+3];
+            xyz2[1] = node.vertex[n+3+1];
+            xyz2[2] = node.vertex[n+3+2]*-1;
+            xyz2[3] = 1;
+            xyz3[0] = node.vertex[n+6];
+            xyz3[1] = node.vertex[n+6+1];
+            xyz3[2] = node.vertex[n+6+2]*-1;
+            xyz3[3] = 1;
 
-	    rotate(xyz1, node.translation);
-	    rotate(xyz2, node.translation);
-	    rotate(xyz3, node.translation);
+            rotate(xyz1, node.translation);
+            rotate(xyz2, node.translation);
+            rotate(xyz3, node.translation);
 
-	    Vertex *ver1 = new Vertex(xyz1[0],xyz1[1],xyz1[2],node.texture[nt],node.texture[nt+1]);
-	    Vertex *ver2 = new Vertex(xyz2[0],xyz2[1],xyz2[2],node.texture[nt+2],node.texture[nt+2+1]);
-	    Vertex *ver3 = new Vertex(xyz3[0],xyz3[1],xyz3[2],node.texture[nt+4],node.texture[nt+4+1]);
+            Vertex *ver1 = new Vertex(xyz1[0],xyz1[1],xyz1[2],node.texture[nt],node.texture[nt+1]);
+            Vertex *ver2 = new Vertex(xyz2[0],xyz2[1],xyz2[2],node.texture[nt+2],node.texture[nt+2+1]);
+            Vertex *ver3 = new Vertex(xyz3[0],xyz3[1],xyz3[2],node.texture[nt+4],node.texture[nt+4+1]);
 
-	    Triangle *tri = new Triangle(ver1,ver2,ver3);
-	    Span_c *span = new Span_c();
-	    span->viewer = viewer;
-	    span->p = this;
-	    span->create_span(tri,texture_image);
-	    delete ver1;
-	    delete ver2;
-	    delete ver3;
-	    delete tri;
-	    delete span;
-	}
+            Triangle *tri = new Triangle(ver1,ver2,ver3);
+            Span_c *span = new Span_c();
+            span->viewer = viewer;
+            span->p = this;
+            span->create_span(tri,texture_image);
+            delete ver1;
+            delete ver2;
+            delete ver3;
+            delete tri;
+            delete span;
+        }
     }
 }
 
@@ -114,20 +112,20 @@
 {
     for(int n=0; n<pp->info.size; n++)
     {
-	Vertex *ver1 = new Vertex(pp->tri[n].ver1.x,pp->tri[n].ver1.y,pp->tri[n].ver1.z,pp->tri[n].ver1.tex_x,pp->tri[n].ver1.tex_y);
-	Vertex *ver2 = new Vertex(pp->tri[n].ver2.x,pp->tri[n].ver2.y,pp->tri[n].ver2.z,pp->tri[n].ver2.tex_x,pp->tri[n].ver2.tex_y);
-	Vertex *ver3 = new Vertex(pp->tri[n].ver3.x,pp->tri[n].ver3.y,pp->tri[n].ver3.z,pp->tri[n].ver3.tex_x,pp->tri[n].ver3.tex_y);
+        Vertex *ver1 = new Vertex(pp->tri[n].ver1.x,pp->tri[n].ver1.y,pp->tri[n].ver1.z,pp->tri[n].ver1.tex_x,pp->tri[n].ver1.tex_y);
+        Vertex *ver2 = new Vertex(pp->tri[n].ver2.x,pp->tri[n].ver2.y,pp->tri[n].ver2.z,pp->tri[n].ver2.tex_x,pp->tri[n].ver2.tex_y);
+        Vertex *ver3 = new Vertex(pp->tri[n].ver3.x,pp->tri[n].ver3.y,pp->tri[n].ver3.z,pp->tri[n].ver3.tex_x,pp->tri[n].ver3.tex_y);
 
-	Triangle *tri = new Triangle(ver1,ver2,ver3);
-	Span_c *span = new Span_c();
-	span->viewer = viewer;
-	span->p = this;
-	span->create_span(tri,texture_image);
-	delete ver1;
-	delete ver2;
-	delete ver3;
-	delete tri;
-	delete span;
+        Triangle *tri = new Triangle(ver1,ver2,ver3);
+        Span_c *span = new Span_c();
+        span->viewer = viewer;
+        span->p = this;
+        span->create_span(tri,texture_image);
+        delete ver1;
+        delete ver2;
+        delete ver3;
+        delete tri;
+        delete span;
     }
 }
 
@@ -136,42 +134,42 @@
     Span *span;
 
     for (int n = 0; n < sp->info.size; n++) {
-	span = &sp->span[n];
+        span = &sp->span[n];
 
-	//int x = span->x;
-	//int y = span->y;
-	float z = span->start_z;
-	int end = span->length_x;
-	float zpos = span->end_z;
-	float tex1 = span->tex_x1;
-	float tex2 = span->tex_x2;
-	float tey1 = span->tex_y1;
-	float tey2 = span->tex_y2;
-	Uint32 rgb;
-	int tex_xpos;
-	int tex_ypos;
-	int tex_zpos;
-	float tex_x, tex_y, tex_z;
+        //int x = span->x;
+        //int y = span->y;
+        float z = span->start_z;
+        int end = span->length_x;
+        float zpos = span->end_z;
+        float tex1 = span->tex_x1;
+        float tex2 = span->tex_x2;
+        float tey1 = span->tex_y1;
+        float tey2 = span->tex_y2;
+        Uint32 rgb;
+        int tex_xpos;
+        int tex_ypos;
+        int tex_zpos;
+        float tex_x, tex_y, tex_z;
 
-	if (end == 1) {
-	    tex_xpos = (int)((span->tex_height-1) * tex1);
-	    tex_ypos = (int)((span->tex_width-1) * tey1);
-	    tex_zpos = (int)z;
-	    rgb = get_rgb(tex_xpos, tex_ypos);
-	    //viewer->write_pixel(x, y, zpos, rgb);
-	} else {
-	    for (int j = 0; j < end; j++) {
-		tex_x = tex1*(end-1-j)/(end-1) + tex2*j/(end-1);
-		tex_y = tey1*(end-1-j)/(end-1) + tey2*j/(end-1);
-		tex_z = z*(end-1-j)/(end-1) + zpos*j/(end-1);
-		if (tex_x > 1) tex_x = 1;
-		if (tex_y > 1) tex_y = 1;
-		tex_xpos = (int)((span->tex_height-1) * tex_x);
-		tex_ypos = (int)((span->tex_width-1) * tex_y);
-		rgb = get_rgb(tex_xpos,tex_ypos);
-		//viewer->write_pixel(j + x, y, tex_z, rgb);
-	    }
-	}
+        if (end == 1) {
+            tex_xpos = (int)((span->tex_height-1) * tex1);
+            tex_ypos = (int)((span->tex_width-1) * tey1);
+            tex_zpos = (int)z;
+            rgb = get_rgb(tex_xpos, tex_ypos);
+            //viewer->write_pixel(x, y, zpos, rgb);
+        } else {
+            for (int j = 0; j < end; j++) {
+                tex_x = tex1*(end-1-j)/(end-1) + tex2*j/(end-1);
+                tex_y = tey1*(end-1-j)/(end-1) + tey2*j/(end-1);
+                tex_z = z*(end-1-j)/(end-1) + zpos*j/(end-1);
+                if (tex_x > 1) tex_x = 1;
+                if (tex_y > 1) tex_y = 1;
+                tex_xpos = (int)((span->tex_height-1) * tex_x);
+                tex_ypos = (int)((span->tex_width-1) * tex_y);
+                rgb = get_rgb(tex_xpos,tex_ypos);
+                //viewer->write_pixel(j + x, y, tex_z, rgb);
+            }
+        }
     }
 }
 
@@ -181,14 +179,14 @@
 {
     for(int n=0; n<size*3; n+=3)
     {
-	cont = pickup_float(cont, coord_xyz+n);
-	cont = pickup_float(cont, coord_xyz+n+1);
-	cont = pickup_float(cont, coord_xyz+n+2);
-      
-	if (cont == NULL)
-	{
-	    cout << "Analyzing obj data failed coordinate\n";
-	}
+        cont = pickup_float(cont, coord_xyz+n);
+        cont = pickup_float(cont, coord_xyz+n+1);
+        cont = pickup_float(cont, coord_xyz+n+2);
+
+        if (cont == NULL)
+        {
+            cout << "Analyzing obj data failed coordinate\n";
+        }
     }
 }
 
@@ -196,14 +194,14 @@
 {
     for (int n = 0; n<size*3; n += 3)
     {
-	cont = pickup_float(cont, normal+n);
-	cont = pickup_float(cont, normal+n+1);
-	cont = pickup_float(cont, normal+n+2);
-      
-	if (cont == NULL)
-	{
-	    cout << "Analyzing obj data failed normal\n";
-	}
+        cont = pickup_float(cont, normal+n);
+        cont = pickup_float(cont, normal+n+1);
+        cont = pickup_float(cont, normal+n+2);
+
+        if (cont == NULL)
+        {
+            cout << "Analyzing obj data failed normal\n";
+        }
     }
 }
 
@@ -212,10 +210,10 @@
     cont = pickup_float(cont,c_xyz);
     cont = pickup_float(cont,c_xyz+1);
     cont = pickup_float(cont,c_xyz+2);
-  
+
     if (cont == NULL)
     {
-	cout << "Analyzing obj data failed model\n";
+        cout << "Analyzing obj data failed model\n";
     }
 }
 
@@ -223,14 +221,14 @@
 {
     for (int n = 0; n < size*3; n += 3)
     {
-	cont = pickup_float(cont, coord_tex+n);
-	cont = pickup_float(cont, coord_tex+n+1);
-	coord_tex[n+2] = 1.0;
-      
-	if (cont == NULL)
-	{
-	    cout << "Analyzing obj data failed texture\n";
-	}
+        cont = pickup_float(cont, coord_tex+n);
+        cont = pickup_float(cont, coord_tex+n+1);
+        coord_tex[n+2] = 1.0;
+
+        if (cont == NULL)
+        {
+            cout << "Analyzing obj data failed texture\n";
+        }
     }
 }
 
@@ -261,7 +259,7 @@
     SDL_PixelFormat *fmt;
     //Uint32 temp, pixel;
     Uint8 red, green, blue;
-  
+
     fmt = texture_image->format;
 
     if (tx<0) tx = 0;
@@ -278,17 +276,17 @@
     //printf("pixel = %d\n", pixel);
     //printf("pixel %x bpp = %d ",p, fmt->BytesPerPixel);
     //SDL_UnlockSurface(texture_image);
-  
+
     temp = pixel&fmt->Rmask;
     temp = temp>>fmt->Rshift;
     temp = temp<<fmt->Rloss;
     red = (Uint8)temp;
-  
+
     temp = pixel&fmt->Gmask;
     temp = temp>>fmt->Gshift;
     temp = temp<<fmt->Gloss;
     green = (Uint8)temp;
-  
+
     temp = pixel&fmt->Bmask;
     temp = temp>>fmt->Bshift;
     temp = temp<<fmt->Bloss;
@@ -297,8 +295,8 @@
     blue  = (Uint8) p[0];
     green = (Uint8) p[1];
     red   = (Uint8) p[2];
-	  
-    //printf("tx = %d ty = %d ", tx,ty); 
+
+    //printf("tx = %d ty = %d ", tx,ty);
     //printf("pixel color =>  R: %d,  G: %d,  B: %d\n", red, green, blue);
 
     SDL_PixelFormat *pf = NULL;