annotate Renderer/Engine/polygon.cc @ 1087:20f09564c586 draft

fix (not yet tested)
author root@localhost.localdomain
date Fri, 17 Dec 2010 18:34:29 +0900
parents 9ce0480cde63
children b733c7903d07
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include <iostream>
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #include <SDL.h>
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 #include <SDL_opengl.h>
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 #include <SDL_image.h>
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 #include "polygon.h"
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 #include "xml.h"
1050
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1047
diff changeset
7 #include "matrix_calc.h"
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 #include "triangle.h"
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 #include "vertex.h"
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 #include "Span.h"
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 #include "SpanC.h"
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 #include "scene_graph_pack.h"
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 #include "error.h"
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 #include "viewer_types.h"
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 using namespace std;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 Polygon::Polygon(void)
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 {
1050
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1047
diff changeset
20 position_init();
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 void
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 Polygon::position_init(void)
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 {
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 xyz[0] = 0;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 xyz[1] = 0;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 xyz[2] = 0;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 xyz[3] = 1;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 c_xyz[0] = 0;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 c_xyz[1] = 0;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 c_xyz[2] = 0;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 c_xyz[3] = 1;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 angle[0] = 0;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 angle[1] = 0;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 angle[2] = 0;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 angle[3] = 1;
1050
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1047
diff changeset
38 scale[0] = 1;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1047
diff changeset
39 scale[1] = 1;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1047
diff changeset
40 scale[2] = 1;
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41
861
fda7b71c3cc6 Still on the way
yutaka@localhost.localdomain
parents: 860
diff changeset
42
fda7b71c3cc6 Still on the way
yutaka@localhost.localdomain
parents: 860
diff changeset
43 #if !SPE_CREATE_POLYGON
fda7b71c3cc6 Still on the way
yutaka@localhost.localdomain
parents: 860
diff changeset
44
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 for (int i = 0; i < 16; i++) {
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 matrix[i] = 0;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 }
861
fda7b71c3cc6 Still on the way
yutaka@localhost.localdomain
parents: 860
diff changeset
48
fda7b71c3cc6 Still on the way
yutaka@localhost.localdomain
parents: 860
diff changeset
49 #endif
fda7b71c3cc6 Still on the way
yutaka@localhost.localdomain
parents: 860
diff changeset
50
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 void Polygon::pickup_coordinate(char *cont)
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 {
860
63a08f3a468a Still on the way
yutaka@localhost.localdomain
parents: 539
diff changeset
55
906
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
56 char *tmp_cont = cont;
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
57 int bound = 8; // coord_vertex size is 8byte.
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
58 int offset = 0;
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
59
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 for(int n=0; n<size*3; n+=3)
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 {
906
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
62 tmp_cont = pickup_float(tmp_cont, coord_xyz+n);
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
63 tmp_cont = pickup_float(tmp_cont, coord_xyz+n+1);
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
64 tmp_cont = pickup_float(tmp_cont, coord_xyz+n+2);
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65
906
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
66 if (tmp_cont == NULL)
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 {
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 cout << "Analyzing obj data failed coordinate\n";
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 }
860
63a08f3a468a Still on the way
yutaka@localhost.localdomain
parents: 539
diff changeset
71
906
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
72 tmp_cont = cont;
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
73
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
74 for(int n=0; n<size; n++)
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
75 {
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
76 tmp_cont = pickup_float(tmp_cont, coord_pack+n*bound+offset);
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
77 tmp_cont = pickup_float(tmp_cont, coord_pack+n*bound+offset+1);
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
78 tmp_cont = pickup_float(tmp_cont, coord_pack+n*bound+offset+2);
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
79
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
80 if (tmp_cont == NULL)
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
81 {
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
82 cout << "Analyzing obj data failed coordinate\n";
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
83 }
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
84 }
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
85
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
86 #if SPE_CREATE_POLYGON_CHECK
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
87
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
88 for (int i = 0; i < size; i++) {
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
89
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
90 if (*(coord_xyz+i*3) != *(coord_pack+i*bound+offset)) {
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
91 printf("hoge\n");
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
92 }
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
93
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
94 if (*(coord_xyz+i*3+1) != *(coord_pack+i*bound+offset+1)) {
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
95 printf("hoge\n");
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
96 }
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
97
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
98 if (*(coord_xyz+i*3+2) != *(coord_pack+i*bound+offset+2)) {
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
99 printf("hoge\n");
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
100 }
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
101
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
102 }
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
103
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
104 #endif
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
105
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
107
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 void Polygon::pickup_normal(char *cont)
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 {
860
63a08f3a468a Still on the way
yutaka@localhost.localdomain
parents: 539
diff changeset
110
906
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
111 char *tmp_cont = cont;
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
112 int bound = 8; // coord_pack size is 8byte.
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
113 int offset = 5; // coord_pack (xyz(3) + tex_x,tex_y(2) + n_xyz(3))
860
63a08f3a468a Still on the way
yutaka@localhost.localdomain
parents: 539
diff changeset
114
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 for (int n = 0; n<size*3; n += 3)
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 {
906
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
117 tmp_cont = pickup_float(tmp_cont, normal+n);
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
118 tmp_cont = pickup_float(tmp_cont, normal+n+1);
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
119 tmp_cont = pickup_float(tmp_cont, normal+n+2);
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
120
906
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
121 if (tmp_cont == NULL)
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 {
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 cout << "Analyzing obj data failed normal\n";
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 }
860
63a08f3a468a Still on the way
yutaka@localhost.localdomain
parents: 539
diff changeset
126
906
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
127 tmp_cont = cont;
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
128
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
129 for(int n=0; n<size; n++)
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
130 {
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
131 tmp_cont = pickup_float(tmp_cont, coord_pack+n*bound+offset);
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
132 tmp_cont = pickup_float(tmp_cont, coord_pack+n*bound+offset+1);
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
133 tmp_cont = pickup_float(tmp_cont, coord_pack+n*bound+offset+2);
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
134
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
135 if (tmp_cont == NULL)
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
136 {
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
137 cout << "Analyzing obj data failed coordinate\n";
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
138 }
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
139 }
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
140
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
141 #if SPE_CREATE_POLYGON_CHECK
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
142
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
143 for (int i = 0; i < size; i++) {
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
144
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
145 if (*(normal+i*3) != *(coord_pack+i*bound+offset)) {
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
146 printf("hoge\n");
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
147 }
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
148
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
149 if (*(normal+i*3+1) != *(coord_pack+i*bound+offset+1)) {
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
150 printf("hoge\n");
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
151 }
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
152
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
153 if (*(normal+i*3+2) != *(coord_pack+i*bound+offset+2)) {
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
154 printf("hoge\n");
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
155 }
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
156
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
157 }
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
158
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
159 #endif
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
160
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
161 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
162
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
163 void Polygon::pickup_model(char *cont)
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 {
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
165 cont = pickup_float(cont,c_xyz);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
166 cont = pickup_float(cont,c_xyz+1);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
167 cont = pickup_float(cont,c_xyz+2);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
168
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
169 if (cont == NULL)
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 {
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
171 cout << "Analyzing obj data failed model\n";
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
172 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
173 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
174
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
175 void Polygon::pickup_texture(char *cont)
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
176 {
860
63a08f3a468a Still on the way
yutaka@localhost.localdomain
parents: 539
diff changeset
177
906
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
178 char *tmp_cont = cont;
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
179 int bound = 8; // coord_pack size is 8byte.
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
180 int offset = 3; // coord_pack (xyz(3) + tex_x,tex_y(2) + n_xyz(3))
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
181
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
182 for (int n = 0; n < size*3; n += 3)
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
183 {
906
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
184 tmp_cont = pickup_float(tmp_cont, coord_tex+n);
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
185 tmp_cont = pickup_float(tmp_cont, coord_tex+n+1);
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
186 coord_tex[n+2] = 1.0;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
187
906
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
188 if (tmp_cont == NULL)
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
189 {
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
190 cout << "Analyzing obj data failed texture\n";
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
191 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
192 }
860
63a08f3a468a Still on the way
yutaka@localhost.localdomain
parents: 539
diff changeset
193
906
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
194 tmp_cont = cont;
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
195
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
196 for(int n=0; n<size; n++)
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
197 {
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
198 tmp_cont = pickup_float(tmp_cont, coord_pack+n*bound+offset);
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
199 tmp_cont = pickup_float(tmp_cont, coord_pack+n*bound+offset+1);
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
200
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
201 if (tmp_cont == NULL)
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
202 {
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
203 cout << "Analyzing obj data failed coordinate\n";
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
204 }
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
205 }
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
206
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
207 #if SPE_CREATE_POLYGON_CHECK
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
208
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
209 for (int i = 0; i < size; i++) {
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
210
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
211 if (*(coord_tex+i*3) != *(coord_pack+i*bound+offset)) {
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
212 printf("hoge\n");
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
213 }
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
214
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
215 if (*(coord_tex+i*3+1) != *(coord_pack+i*bound+offset+1)) {
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
216 printf("hoge\n");
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
217 }
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
218
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
219
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
220 }
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
221
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
222 #endif
becd6fad3ae0 coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents: 861
diff changeset
223
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
224 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
225
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
226 char *get_pixel(int tx, int ty, SDL_Surface *texture_image)
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
227 {
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
228 return (char*)texture_image->pixels+(texture_image->format->BytesPerPixel*((texture_image->w)*ty+tx));
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
229 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
230
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
231 unsigned my_ntohl(unsigned u) {
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
232 // rr gg bb 00
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
233 // rr
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
234 // bb gg rr
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
235 //unsigned u1 = ((u&0xff)<<24) +
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
236 // ((u&0xff00)<<8) +
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
237 // ((u&0xff0000)>>8) +
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
238 // ((u&0xff000000)>>24);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
239 unsigned u1;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
240 unsigned b = (u&0xff000000)>>24;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
241 unsigned g = (u&0xff0000)>>16;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
242 unsigned r = (u&0xff00)>>8;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
243 u1 = r + (g<<8) + (b<<16);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
244 //printf("pixel %x->%x\n",u,u1);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
245 return u1;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
246 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
247
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
248 Uint32 Polygon::get_rgb(int tx, int ty)
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
249 {
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
250 SDL_PixelFormat *fmt;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
251 //Uint32 temp, pixel;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
252 Uint8 red, green, blue;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
253
1055
9ce0480cde63 remove texture_image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1050
diff changeset
254 fmt = texture_info.texture_image->format;
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
255
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
256 if (tx<0) tx = 0;
1055
9ce0480cde63 remove texture_image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1050
diff changeset
257 if (texture_info.texture_image->w-1< tx) tx = texture_info.texture_image->w-1 ;
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
258 if (ty<0) ty = 0;
1055
9ce0480cde63 remove texture_image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1050
diff changeset
259 if (texture_info.texture_image->h-1< ty) ty = texture_info.texture_image->h-1 ;
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
260
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
261
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
262
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
263 //SDL_LockSurface(texture_image);
1055
9ce0480cde63 remove texture_image
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1050
diff changeset
264 char *p = get_pixel(tx,ty,texture_info.texture_image);
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
265 blue = (Uint8) p[0];
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
266 green = (Uint8) p[1];
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
267 red = (Uint8) p[2];
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
268
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
269 //printf("tx = %d ty = %d ", tx,ty);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
270 //printf("pixel color => R: %d, G: %d, B: %d\n", red, green, blue);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
271
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
272 SDL_PixelFormat *pf = NULL;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
273 //pf = viewer->screen->format;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
274
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
275 //cout << SDL_MapRGB(pf, red, green, blue) << endl;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
276 return SDL_MapRGB(pf, red, green, blue);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
277 }