515
|
1 #include <stdlib.h>
|
518
|
2 #include <stdio.h>
|
|
3 #include <string.h>
|
|
4 #include <fcntl.h>
|
|
5 #include <sys/types.h>
|
|
6 #include <sys/mman.h>
|
|
7 #include <sys/stat.h>
|
|
8 #include <unistd.h>
|
515
|
9 #include "SceneGraphRoot.h"
|
|
10
|
518
|
11 /*
|
|
12 typedef struct {
|
|
13 caddr_t file_mmap;
|
|
14 off_t size;
|
|
15 } st_mmap_t;
|
|
16 */
|
|
17
|
|
18 int
|
|
19 fix_byte(int size,int fix_byte_size)
|
|
20 {
|
|
21 size = (size/fix_byte_size)*fix_byte_size + ((size%fix_byte_size)!= 0)*fix_byte_size;
|
|
22
|
|
23 return size;
|
|
24 }
|
|
25
|
|
26 st_mmap_t
|
|
27 my_mmap(char *filename)
|
|
28 {
|
|
29 int fd = -1;
|
|
30 int map = MAP_PRIVATE;
|
|
31 st_mmap_t st_mmap;
|
|
32 struct stat sb;
|
|
33
|
|
34 if ((fd = open(filename, O_RDONLY, 0666)) == 0 ) {
|
|
35 fprintf(stderr, "Can't open %s\n", filename);
|
|
36 }
|
|
37
|
|
38 if (fstat(fd, &sb)) {
|
|
39 fprintf(stderr, "Can't fstat %s\n", filename);
|
|
40 }
|
|
41
|
|
42 printf("file size %d\n", (int)sb.st_size);
|
|
43
|
|
44 st_mmap.size = fix_byte(sb.st_size, 4096);
|
|
45
|
|
46 printf("fix 4096byte file size %d\n", (int)st_mmap.size);
|
|
47
|
|
48 st_mmap.file_mmap = (char *)mmap(NULL, st_mmap.size, PROT_READ, map, fd, (off_t)0);
|
|
49 if (st_mmap.file_mmap == (caddr_t)-1) {
|
|
50 fprintf(stderr, "Can't mmap file\n");
|
|
51 perror(NULL);
|
|
52 exit(0);
|
|
53 }
|
|
54
|
|
55 return st_mmap;
|
|
56 }
|
|
57
|
515
|
58 static void
|
|
59 earth_collision(SceneGraphPtr node, int screen_w, int screen_h,
|
|
60 SceneGraphPtr tree)
|
|
61 {
|
|
62 }
|
|
63
|
|
64 static void
|
|
65 moon_collision(SceneGraphPtr node, int screen_w, int screen_h,
|
|
66 SceneGraphPtr tree)
|
|
67 {
|
|
68 }
|
|
69
|
|
70 static void
|
|
71 moon_move(SceneGraphPtr node, int screen_w, int screen_h)
|
|
72 {
|
|
73 node->angle[0] += 3.0f;
|
|
74 node->xyz[1] += 1.0f;
|
|
75 }
|
|
76
|
|
77
|
|
78 static void
|
|
79 earth_move(SceneGraphPtr node, int screen_w, int screen_h)
|
|
80 {
|
|
81 node->angle[1] += 1.0f;
|
|
82 if (node->angle[1] > 360.0f) {
|
|
83 node->angle[1] = 0.0f;
|
|
84 }
|
|
85
|
|
86 node->xyz[0] += node->stack_xyz[0];
|
|
87 if ((int)node->xyz[0] > screen_w || (int)node->xyz[0] < 0) {
|
|
88 node->stack_xyz[0] = -node->stack_xyz[0];
|
|
89 }
|
|
90
|
|
91 node->xyz[1] += node->stack_xyz[1];
|
|
92 if ((int)node->xyz[1] > screen_h || (int)node->xyz[1] < 0) {
|
|
93 node->stack_xyz[1] = -node->stack_xyz[1];
|
|
94 }
|
|
95
|
|
96 Pad *pad = sgroot->getController();
|
518
|
97
|
515
|
98 if (pad->right.isPush()) {
|
518
|
99 SceneGraphPtr earth;
|
|
100
|
|
101 st_mmap_t m = my_mmap("xml_file/universe.xml");
|
|
102
|
|
103 //sgroot->createFromXMLmemory(sgroot->tmanager, "xml_file/universe.xml");
|
|
104 sgroot->createFromXMLmemory(sgroot->tmanager, m);
|
515
|
105 earth = sgroot->createSceneGraph("Earth");
|
|
106 earth->set_move_collision(moon_move, moon_collision);
|
|
107 node->addChild(earth);
|
|
108 }
|
|
109 }
|
|
110
|
518
|
111 /*
|
|
112 void
|
|
113 linda_init()
|
|
114 {
|
|
115 init_linda();
|
|
116 tspace = open_linda_java("localhost", PORT);
|
|
117 printf("open");
|
|
118 }
|
|
119 */
|
|
120
|
515
|
121 void
|
|
122 dynamic_init(TaskManager *manager)
|
|
123 {
|
|
124 SceneGraphPtr earth;
|
|
125 sgroot->tmanager = manager;
|
|
126
|
518
|
127
|
|
128
|
515
|
129 #if 0
|
|
130 // テスト用に mmap したデータを第2引数に渡す
|
|
131 sgroot->createFromXMLmemory(manager, "xml_file/universe.xml");
|
|
132
|
|
133 // sglist に登録されている name から sgid を引き、sg_src[sgid] からコピーして返す
|
|
134 earth = sgroot->createSceneGraph("Earth");
|
|
135 #else
|
|
136 SceneGraphPtr parent;
|
|
137 parent = sgroot->createSceneGraph();
|
|
138 parent->set_move_collision(earth_move, earth_collision);
|
|
139 #endif
|
|
140
|
|
141 // SceneGraphRoot に、使用する SceneGraph を設定する
|
|
142 // このとき、ユーザーが記述した SceneGraph の root を渡す。
|
|
143 sgroot->setSceneData(parent);
|
|
144 }
|