83
|
1 #include <stdio.h>
|
109
|
2 #include <stdlib.h>
|
|
3 #include <malloc.h>
|
83
|
4 #include "CreatePolygonPack.h"
|
|
5 #include "polygon_pack.h"
|
|
6 #include "scene_graph_pack.h"
|
|
7
|
88
|
8
|
|
9 void
|
|
10 CreatePolygonPack::read(void)
|
|
11 {
|
109
|
12 SchedTask::read();
|
88
|
13 }
|
|
14
|
83
|
15 int
|
|
16 CreatePolygonPack::run(void *rbuf, void *wbuf)
|
|
17 {
|
109
|
18 SceneGraphPack *sgp = (SceneGraphPack*)rbuf;
|
|
19 PolygonPack *pp = (PolygonPack*)wbuf;
|
83
|
20
|
109
|
21 float xyz1[4],xyz2[4],xyz3[4];
|
83
|
22
|
109
|
23 for (int i = 0; i < sgp->info.size; i++) {
|
|
24 SceneGraphNodePtr node = &sgp->node[i];
|
83
|
25
|
109
|
26 int n,nt,pt;
|
|
27 for(n=0,nt=0,pt=0; n<node->size*3; n+=9,nt+=6,pt++) {
|
|
28 xyz1[0] = node->vertex[n];
|
|
29 xyz1[1] = node->vertex[n+1];
|
|
30 xyz1[2] = node->vertex[n+2]*-1;
|
|
31 xyz1[3] = 1;
|
|
32 xyz2[0] = node->vertex[n+3];
|
|
33 xyz2[1] = node->vertex[n+3+1];
|
|
34 xyz2[2] = node->vertex[n+3+2]*-1;
|
|
35 xyz2[3] = 1;
|
|
36 xyz3[0] = node->vertex[n+6];
|
|
37 xyz3[1] = node->vertex[n+6+1];
|
|
38 xyz3[2] = node->vertex[n+6+2]*-1;
|
|
39 xyz3[3] = 1;
|
83
|
40
|
109
|
41 rotate(xyz1, node->translation);
|
|
42 rotate(xyz2, node->translation);
|
|
43 rotate(xyz3, node->translation);
|
83
|
44
|
109
|
45 pp->tri[pt].ver1.x = xyz1[0];
|
|
46 pp->tri[pt].ver1.y = xyz1[1];
|
|
47 pp->tri[pt].ver1.z = xyz1[2];
|
|
48 pp->tri[pt].ver1.tex_x = node->texture[nt];
|
|
49 pp->tri[pt].ver1.tex_y = node->texture[nt+1];
|
83
|
50
|
109
|
51 pp->tri[pt].ver2.x = xyz2[0];
|
|
52 pp->tri[pt].ver2.y = xyz2[1];
|
|
53 pp->tri[pt].ver2.z = xyz2[2];
|
|
54 pp->tri[pt].ver2.tex_x = node->texture[nt+2];
|
|
55 pp->tri[pt].ver2.tex_y = node->texture[nt+2+1];
|
83
|
56
|
109
|
57 pp->tri[pt].ver3.x = xyz3[0];
|
|
58 pp->tri[pt].ver3.y = xyz3[1];
|
|
59 pp->tri[pt].ver3.z = xyz3[2];
|
|
60 pp->tri[pt].ver3.tex_x = node->texture[nt+4];
|
|
61 pp->tri[pt].ver3.tex_y = node->texture[nt+4+1];
|
83
|
62
|
109
|
63 pp->tri[pt].tex_width = node->tex_width;
|
|
64 pp->tri[pt].tex_height = node->tex_height;
|
|
65 }
|
|
66 pp->info.size = pt;
|
|
67 pp->ssl = sgp->ssl;
|
|
68 }
|
83
|
69
|
109
|
70 return sizeof(PolygonPack);
|
83
|
71 }
|
|
72
|
109
|
73 void
|
|
74 CreatePolygonPack::write(void)
|
|
75 {
|
|
76 SchedTask::write();
|
|
77
|
|
78 free(readbuf);
|
|
79 free(writebuf);
|
|
80 }
|
105
|
81
|
|
82 void
|
83
|
83 CreatePolygonPack::rotate(float *xyz, float *matrix)
|
|
84 {
|
109
|
85 float abc[4];
|
106
|
86
|
109
|
87 abc[0] = xyz[0];
|
|
88 abc[1] = xyz[1];
|
|
89 abc[2] = xyz[2];
|
|
90 abc[3] = xyz[3];
|
|
91
|
|
92 // SIMD 使えるよね
|
|
93 for (int i=0; i<4; i++)
|
|
94 {
|
|
95 xyz[i] = abc[0]*matrix[i] + abc[1]*matrix[i+4]
|
|
96 + abc[2]*matrix[i+8] + abc[3]*matrix[i+12];
|
|
97 }
|
83
|
98 }
|
|
99
|
|
100 SchedTask*
|
|
101 createTask_createPolygonPack(TaskListPtr _taskList, TaskPtr _task,
|
|
102 void *rbuff, void *wbuff, DmaManager *dma)
|
|
103 {
|
109
|
104 rbuff = memalign(16, sizeof(SceneGraphPack));
|
|
105 wbuff = memalign(16, sizeof(PolygonPack));
|
|
106
|
|
107 return new CreatePolygonPack(_taskList, _task, rbuff, wbuff, dma);
|
83
|
108 }
|