annotate Renderer/Engine/polygon.cc @ 906:348b48db317e

coord_pack is stuffed with infomation of create polygon at spe.
author Yutaka_Kinjyo
date Mon, 19 Jul 2010 23:40:53 +0900
parents 000a8b63ad9a
children 2683838396c6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
507
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include <iostream>
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #include <SDL.h>
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 #include <SDL_opengl.h>
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 #include <SDL_image.h>
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 #include "polygon.h"
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 #include "xml.h"
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 #include "sys.h"
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 #include "triangle.h"
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 #include "vertex.h"
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 #include "Span.h"
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 #include "SpanC.h"
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 #include "scene_graph_pack.h"
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 #include "error.h"
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 #include "viewer_types.h"
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 using namespace std;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 //extern int decode(char *cont, char *file_name);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 extern int decode(char *cont, FILE *outfile);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 Polygon::Polygon(void)
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 {
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 xyz[0] = 0;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 xyz[1] = 0;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 xyz[2] = 0;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 xyz[3] = 1;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 c_xyz[0] = 0;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 c_xyz[1] = 0;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 c_xyz[2] = 0;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 c_xyz[3] = 1;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 angle[0] = 0;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 angle[1] = 0;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 angle[2] = 0;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 angle[3] = 1;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35
861
000a8b63ad9a Still on the way
yutaka@localhost.localdomain
parents: 860
diff changeset
36
000a8b63ad9a Still on the way
yutaka@localhost.localdomain
parents: 860
diff changeset
37 #if !SPE_CREATE_POLYGON
000a8b63ad9a Still on the way
yutaka@localhost.localdomain
parents: 860
diff changeset
38
507
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 for (int i = 0; i < 16; i++) {
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 matrix[i] = 0;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 }
861
000a8b63ad9a Still on the way
yutaka@localhost.localdomain
parents: 860
diff changeset
42
000a8b63ad9a Still on the way
yutaka@localhost.localdomain
parents: 860
diff changeset
43 #endif
000a8b63ad9a Still on the way
yutaka@localhost.localdomain
parents: 860
diff changeset
44
507
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 }
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 void
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 Polygon::position_init(void)
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 {
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 xyz[0] = 0;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 xyz[1] = 0;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 xyz[2] = 0;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 xyz[3] = 1;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 c_xyz[0] = 0;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 c_xyz[1] = 0;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 c_xyz[2] = 0;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 c_xyz[3] = 1;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 angle[0] = 0;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 angle[1] = 0;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 angle[2] = 0;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 angle[3] = 1;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62
861
000a8b63ad9a Still on the way
yutaka@localhost.localdomain
parents: 860
diff changeset
63
000a8b63ad9a Still on the way
yutaka@localhost.localdomain
parents: 860
diff changeset
64 #if !SPE_CREATE_POLYGON
000a8b63ad9a Still on the way
yutaka@localhost.localdomain
parents: 860
diff changeset
65
507
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 for (int i = 0; i < 16; i++) {
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 matrix[i] = 0;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 }
861
000a8b63ad9a Still on the way
yutaka@localhost.localdomain
parents: 860
diff changeset
69
000a8b63ad9a Still on the way
yutaka@localhost.localdomain
parents: 860
diff changeset
70 #endif
000a8b63ad9a Still on the way
yutaka@localhost.localdomain
parents: 860
diff changeset
71
507
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 }
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
73
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 #if 0
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 void Polygon::draw(SceneGraphPack *sgp)
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 {
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 float xyz1[4],xyz2[4],xyz3[4];
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
78
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 /***SceneGraphUpdate***/
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 //sgp_update();
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 for (int i = 0; i < sgp->info.size; i++) {
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 SceneGraphNode node = sgp->node[i];
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
83
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 /***draw***/
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 int n,nt;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 for(n=0,nt=0; n<node.size*3; n+=9,nt+=6) {
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 xyz1[0] = node.vertex[n];
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 xyz1[1] = node.vertex[n+1];
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 xyz1[2] = node.vertex[n+2]*-1;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 xyz1[3] = 1;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 xyz2[0] = node.vertex[n+3];
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 xyz2[1] = node.vertex[n+3+1];
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 xyz2[2] = node.vertex[n+3+2]*-1;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 xyz2[3] = 1;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 xyz3[0] = node.vertex[n+6];
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 xyz3[1] = node.vertex[n+6+1];
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 xyz3[2] = node.vertex[n+6+2]*-1;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 xyz3[3] = 1;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
99
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 rotate(xyz1, node.translation);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 rotate(xyz2, node.translation);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 rotate(xyz3, node.translation);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
103
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 Vertex *ver1 = new Vertex(xyz1[0],xyz1[1],xyz1[2],node.texture[nt],node.texture[nt+1]);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
105 Vertex *ver2 = new Vertex(xyz2[0],xyz2[1],xyz2[2],node.texture[nt+2],node.texture[nt+2+1]);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 Vertex *ver3 = new Vertex(xyz3[0],xyz3[1],xyz3[2],node.texture[nt+4],node.texture[nt+4+1]);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
107
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 Triangle *tri = new Triangle(ver1,ver2,ver3);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 Span_c *span = new Span_c();
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 span->viewer = viewer;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 span->p = this;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 span->create_span(tri,texture_image);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 delete ver1;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 delete ver2;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 delete ver3;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 delete tri;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 delete span;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 }
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 }
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 }
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
121
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
122
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 void Polygon::draw(PolygonPack *pp)
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 {
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 for(int n=0; n<pp->info.size; n++)
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 {
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
127 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);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 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);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
129 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);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
130
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 Triangle *tri = new Triangle(ver1,ver2,ver3);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
132 Span_c *span = new Span_c();
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
133 span->viewer = viewer;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
134 span->p = this;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 span->create_span(tri,texture_image);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 delete ver1;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
137 delete ver2;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
138 delete ver3;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
139 delete tri;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
140 delete span;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
141 }
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 }
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
143
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
144 void Polygon::draw(SpanPack *sp)
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
145 {
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 Span *span;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
147
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
148 for (int n = 0; n < sp->info.size; n++) {
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
149 span = &sp->span[n];
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
150
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
151 //int x = span->x;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
152 //int y = span->y;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 float z = span->start_z;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
154 int end = span->length_x;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
155 float zpos = span->end_z;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
156 float tex1 = span->tex_x1;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
157 float tex2 = span->tex_x2;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 float tey1 = span->tex_y1;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 float tey2 = span->tex_y2;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
160 Uint32 rgb;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
161 int tex_xpos;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
162 int tex_ypos;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
163 int tex_zpos;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 float tex_x, tex_y, tex_z;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
165
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
166 if (end == 1) {
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
167 tex_xpos = (int)((span->tex_height-1) * tex1);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
168 tex_ypos = (int)((span->tex_width-1) * tey1);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
169 tex_zpos = (int)z;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 rgb = get_rgb(tex_xpos, tex_ypos);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
171 //viewer->write_pixel(x, y, zpos, rgb);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
172 } else {
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
173 for (int j = 0; j < end; j++) {
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
174 tex_x = tex1*(end-1-j)/(end-1) + tex2*j/(end-1);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
175 tex_y = tey1*(end-1-j)/(end-1) + tey2*j/(end-1);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
176 tex_z = z*(end-1-j)/(end-1) + zpos*j/(end-1);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
177 if (tex_x > 1) tex_x = 1;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
178 if (tex_y > 1) tex_y = 1;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
179 tex_xpos = (int)((span->tex_height-1) * tex_x);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
180 tex_ypos = (int)((span->tex_width-1) * tex_y);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 rgb = get_rgb(tex_xpos,tex_ypos);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
182 //viewer->write_pixel(j + x, y, tex_z, rgb);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
183 }
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
184 }
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
185 }
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
186 }
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
187
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
188 #endif
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
189
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
190 void Polygon::pickup_coordinate(char *cont)
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
191 {
860
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
192
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
193 #if SPE_CREATE_POLYGON
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
194
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
195 TrianglePackPtr cur = tri_pack;
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
196
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
197 for(int n=0; n<size; n+=3)
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
198 {
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
199
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
200 cont = pickup_float(cont, &cur->ver1.x);
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
201 cont = pickup_float(cont, &cur->ver1.y);
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
202 cont = pickup_float(cont, &cur->ver1.z);
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
203
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
204 cont = pickup_float(cont, &cur->ver2.x);
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
205 cont = pickup_float(cont, &cur->ver2.y);
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
206 cont = pickup_float(cont, &cur->ver2.z);
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
207
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
208 cont = pickup_float(cont, &cur->ver3.x);
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
209 cont = pickup_float(cont, &cur->ver3.y);
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
210 cont = pickup_float(cont, &cur->ver3.z);
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
211
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
212 cur = cur + 1;
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
213
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
214 if (cont == NULL)
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
215 {
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
216 cout << "Analyzing obj data failed coordinate\n";
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
217 }
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
218 }
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
219
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
220 #else
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
221
906
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
222 char *tmp_cont = cont;
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
223 int bound = 8; // coord_vertex size is 8byte.
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
224 int offset = 0;
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
225
507
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
226 for(int n=0; n<size*3; n+=3)
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
227 {
906
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
228 tmp_cont = pickup_float(tmp_cont, coord_xyz+n);
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
229 tmp_cont = pickup_float(tmp_cont, coord_xyz+n+1);
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
230 tmp_cont = pickup_float(tmp_cont, coord_xyz+n+2);
507
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
231
906
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
232 if (tmp_cont == NULL)
507
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
233 {
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
234 cout << "Analyzing obj data failed coordinate\n";
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
235 }
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
236 }
860
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
237
906
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
238 tmp_cont = cont;
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
239
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
240 for(int n=0; n<size; n++)
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
241 {
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
242 tmp_cont = pickup_float(tmp_cont, coord_pack+n*bound+offset);
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
243 tmp_cont = pickup_float(tmp_cont, coord_pack+n*bound+offset+1);
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
244 tmp_cont = pickup_float(tmp_cont, coord_pack+n*bound+offset+2);
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
245
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
246 if (tmp_cont == NULL)
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
247 {
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
248 cout << "Analyzing obj data failed coordinate\n";
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
249 }
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
250 }
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
251
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
252 #if SPE_CREATE_POLYGON_CHECK
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
253
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
254 for (int i = 0; i < size; i++) {
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
255
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
256 if (*(coord_xyz+i*3) != *(coord_pack+i*bound+offset)) {
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
257 printf("hoge\n");
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
258 }
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
259
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
260 if (*(coord_xyz+i*3+1) != *(coord_pack+i*bound+offset+1)) {
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
261 printf("hoge\n");
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
262 }
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
263
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
264 if (*(coord_xyz+i*3+2) != *(coord_pack+i*bound+offset+2)) {
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
265 printf("hoge\n");
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
266 }
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
267
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
268 }
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
269
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
270 #endif
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
271
860
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
272 #endif
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
273
507
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
274 }
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
275
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
276 void Polygon::pickup_normal(char *cont)
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
277 {
860
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
278
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
279 #if SPE_CREATE_POLYGON
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
280
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
281 TrianglePackPtr cur = tri_pack;
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
282
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
283 for(int n=0; n<size; n+=3)
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
284 {
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
285
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
286 cont = pickup_float(cont, &cur->normal1.x);
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
287 cont = pickup_float(cont, &cur->normal1.y);
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
288 cont = pickup_float(cont, &cur->normal1.z);
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
289
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
290 cont = pickup_float(cont, &cur->normal2.x);
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
291 cont = pickup_float(cont, &cur->normal2.y);
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
292 cont = pickup_float(cont, &cur->normal2.z);
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
293
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
294 cont = pickup_float(cont, &cur->normal3.x);
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
295 cont = pickup_float(cont, &cur->normal3.y);
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
296 cont = pickup_float(cont, &cur->normal3.z);
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
297
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
298 cur = cur + 1;
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
299
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
300 if (cont == NULL)
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
301 {
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
302 cout << "Analyzing obj data failed coordinate\n";
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
303 }
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
304 }
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
305
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
306 #else
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
307
906
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
308 char *tmp_cont = cont;
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
309 int bound = 8; // coord_pack size is 8byte.
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
310 int offset = 5; // coord_pack (xyz(3) + tex_x,tex_y(2) + n_xyz(3))
860
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
311
507
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
312 for (int n = 0; n<size*3; n += 3)
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
313 {
906
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
314 tmp_cont = pickup_float(tmp_cont, normal+n);
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
315 tmp_cont = pickup_float(tmp_cont, normal+n+1);
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
316 tmp_cont = pickup_float(tmp_cont, normal+n+2);
507
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
317
906
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
318 if (tmp_cont == NULL)
507
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
319 {
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
320 cout << "Analyzing obj data failed normal\n";
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
321 }
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
322 }
860
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
323
906
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
324 tmp_cont = cont;
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
325
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
326 for(int n=0; n<size; n++)
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
327 {
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
328 tmp_cont = pickup_float(tmp_cont, coord_pack+n*bound+offset);
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
329 tmp_cont = pickup_float(tmp_cont, coord_pack+n*bound+offset+1);
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
330 tmp_cont = pickup_float(tmp_cont, coord_pack+n*bound+offset+2);
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
331
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
332 if (tmp_cont == NULL)
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
333 {
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
334 cout << "Analyzing obj data failed coordinate\n";
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
335 }
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
336 }
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
337
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
338 #if SPE_CREATE_POLYGON_CHECK
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
339
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
340 for (int i = 0; i < size; i++) {
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
341
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
342 if (*(normal+i*3) != *(coord_pack+i*bound+offset)) {
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
343 printf("hoge\n");
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
344 }
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
345
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
346 if (*(normal+i*3+1) != *(coord_pack+i*bound+offset+1)) {
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
347 printf("hoge\n");
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
348 }
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
349
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
350 if (*(normal+i*3+2) != *(coord_pack+i*bound+offset+2)) {
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
351 printf("hoge\n");
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
352 }
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
353
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
354 }
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
355
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
356 #endif
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
357
860
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
358 #endif
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
359
507
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
360 }
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
361
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
362 void Polygon::pickup_model(char *cont)
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
363 {
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
364 cont = pickup_float(cont,c_xyz);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
365 cont = pickup_float(cont,c_xyz+1);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
366 cont = pickup_float(cont,c_xyz+2);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
367
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
368 if (cont == NULL)
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
369 {
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
370 cout << "Analyzing obj data failed model\n";
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
371 }
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
372 }
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
373
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
374 void Polygon::pickup_texture(char *cont)
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
375 {
860
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
376
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
377 #if SPE_CREATE_POLYGON
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
378
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
379 TrianglePackPtr cur = tri_pack;
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
380
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
381 for(int n=0; n<size; n+=3)
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
382 {
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
383
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
384 cont = pickup_float(cont, &cur->ver1.tex_x);
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
385 cont = pickup_float(cont, &cur->ver1.tex_y);
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
386
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
387 cont = pickup_float(cont, &cur->ver2.tex_x);
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
388 cont = pickup_float(cont, &cur->ver2.tex_y);
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
389
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
390 cont = pickup_float(cont, &cur->ver3.tex_x);
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
391 cont = pickup_float(cont, &cur->ver3.tex_y);
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
392
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
393 cur = cur + 1;
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
394
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
395 if (cont == NULL)
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
396 {
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
397 cout << "Analyzing obj data failed coordinate\n";
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
398 }
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
399 }
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
400
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
401 #else
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
402
906
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
403 char *tmp_cont = cont;
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
404 int bound = 8; // coord_pack size is 8byte.
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
405 int offset = 3; // coord_pack (xyz(3) + tex_x,tex_y(2) + n_xyz(3))
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
406
507
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
407 for (int n = 0; n < size*3; n += 3)
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
408 {
906
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
409 tmp_cont = pickup_float(tmp_cont, coord_tex+n);
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
410 tmp_cont = pickup_float(tmp_cont, coord_tex+n+1);
507
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
411 coord_tex[n+2] = 1.0;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
412
906
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
413 if (tmp_cont == NULL)
507
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
414 {
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
415 cout << "Analyzing obj data failed texture\n";
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
416 }
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
417 }
860
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
418
906
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
419 tmp_cont = cont;
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
420
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
421 for(int n=0; n<size; n++)
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
422 {
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
423 tmp_cont = pickup_float(tmp_cont, coord_pack+n*bound+offset);
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
424 tmp_cont = pickup_float(tmp_cont, coord_pack+n*bound+offset+1);
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
425
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
426 if (tmp_cont == NULL)
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
427 {
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
428 cout << "Analyzing obj data failed coordinate\n";
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
429 }
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
430 }
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
431
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
432 #if SPE_CREATE_POLYGON_CHECK
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
433
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
434 for (int i = 0; i < size; i++) {
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
435
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
436 if (*(coord_tex+i*3) != *(coord_pack+i*bound+offset)) {
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
437 printf("hoge\n");
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
438 }
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
439
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
440 if (*(coord_tex+i*3+1) != *(coord_pack+i*bound+offset+1)) {
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
441 printf("hoge\n");
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
442 }
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
443
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
444
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
445 }
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
446
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
447 #endif
348b48db317e coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
448
860
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
449 #endif
649e4cb84683 Still on the way
yutaka@localhost.localdomain
parents: 507
diff changeset
450
507
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
451 }
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
452
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
453 char *get_pixel(int tx, int ty, SDL_Surface *texture_image)
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
454 {
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
455 return (char*)texture_image->pixels+(texture_image->format->BytesPerPixel*((texture_image->w)*ty+tx));
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
456 }
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
457
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
458 unsigned my_ntohl(unsigned u) {
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
459 // rr gg bb 00
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
460 // rr
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
461 // bb gg rr
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
462 //unsigned u1 = ((u&0xff)<<24) +
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
463 // ((u&0xff00)<<8) +
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
464 // ((u&0xff0000)>>8) +
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
465 // ((u&0xff000000)>>24);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
466 unsigned u1;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
467 unsigned b = (u&0xff000000)>>24;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
468 unsigned g = (u&0xff0000)>>16;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
469 unsigned r = (u&0xff00)>>8;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
470 u1 = r + (g<<8) + (b<<16);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
471 //printf("pixel %x->%x\n",u,u1);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
472 return u1;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
473 }
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
474
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
475 Uint32 Polygon::get_rgb(int tx, int ty)
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
476 {
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
477 SDL_PixelFormat *fmt;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
478 //Uint32 temp, pixel;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
479 Uint8 red, green, blue;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
480
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
481 fmt = texture_image->format;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
482
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
483 if (tx<0) tx = 0;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
484 if (texture_image->w-1< tx) tx = texture_image->w-1 ;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
485 if (ty<0) ty = 0;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
486 if (texture_image->h-1< ty) ty = texture_image->h-1 ;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
487
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
488
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
489
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
490 //SDL_LockSurface(texture_image);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
491 char *p = get_pixel(tx,ty,texture_image);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
492 #if 0
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
493 pixel = my_ntohl(*(Uint32*)p);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
494 //printf("pixel = %d\n", pixel);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
495 //printf("pixel %x bpp = %d ",p, fmt->BytesPerPixel);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
496 //SDL_UnlockSurface(texture_image);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
497
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
498 temp = pixel&fmt->Rmask;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
499 temp = temp>>fmt->Rshift;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
500 temp = temp<<fmt->Rloss;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
501 red = (Uint8)temp;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
502
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
503 temp = pixel&fmt->Gmask;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
504 temp = temp>>fmt->Gshift;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
505 temp = temp<<fmt->Gloss;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
506 green = (Uint8)temp;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
507
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
508 temp = pixel&fmt->Bmask;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
509 temp = temp>>fmt->Bshift;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
510 temp = temp<<fmt->Bloss;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
511 blue = (Uint8)temp;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
512 #endif
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
513 blue = (Uint8) p[0];
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
514 green = (Uint8) p[1];
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
515 red = (Uint8) p[2];
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
516
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
517 //printf("tx = %d ty = %d ", tx,ty);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
518 //printf("pixel color => R: %d, G: %d, B: %d\n", red, green, blue);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
519
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
520 SDL_PixelFormat *pf = NULL;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
521 //pf = viewer->screen->format;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
522
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
523 //cout << SDL_MapRGB(pf, red, green, blue) << endl;
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
524 return SDL_MapRGB(pf, red, green, blue);
735f76483bb2 Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
525 }