annotate Renderer/Test/viewer_2.cc @ 1343:e4a65e0be060 draft

minor changes.
author e095732 <e095732@ie.u-ryukyu.ac.jp>
date Fri, 13 Jan 2012 03:58:49 +0900
parents 90efd2aac2cb
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1207
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 /*
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 viewer.cc を、xmlファイルのsurface nameをわざわざ書き出さなくても
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 良いように改良しました。
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 ただxmlファイル内のsurface name行をプログラム内で抜き出せるようにしただけ
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 使い方:
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 ./viewer_2 -sg (読み込みたいxmlファイル名)
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 */
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 #include <math.h>
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 #include <stdlib.h>
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 #include "SceneGraphRoot.h"
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 #include "MainLoop.h"
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 #include "viewer.h"
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 // prototype
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 static void object_move_rotation(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h);
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 static void object_collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, SceneGraphPtr tree);
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 static void object_move_translation(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h);
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 /*
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 getStrFromFile関数
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 指定したテキストファイル内から,
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 ある文字列(searchStartStr)とある文字列(searchEndStr)の間の文字列を抜き出す.
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 抜き出した文字列の数を返す.
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 char **date に抜き出した文字列を二次元配列のポインタを渡す.
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 中でmallocしてるから、使い終わったら free(date)しないとダメかも
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 reallocとかでfree()しなくて良い方法も教えて下さい.
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 */
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 static int getStrFromFile( char **date, const char *fname, const char *searchStartStr, const char *searchEndStr );
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 int light_sysswitch = 1;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 int light_num = 4;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 void LightSysSwitch(Viewer *sgroot) {
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 if (light_sysswitch == 1) {
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 sgroot->OnLightSysSwitch();
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 } else if (light_sysswitch == 0) {
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 sgroot->OffLightSysSwitch();
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 }
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 }
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 static void
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 object_move_rotation(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h)
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 {
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 Pad *pad = sgroot->getController();
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 if (pad->circle.isPush()) {
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 node->set_move_collision(object_move_translation, object_collision);
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 }
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 if (pad->left.isHold()) {
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 node->angle[1] += 10;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 } else if (pad->right.isHold()) {
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 node->angle[1] -= 10;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 }
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 if (pad->up.isHold()) {
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 node->angle[0] += 10;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 } else if (pad->down.isHold()) {
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 node->angle[0] -= 10;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 }
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 }
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 static void
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 object_move_translation(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h)
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 {
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 Pad *pad = sgroot->getController();
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 if (pad->circle.isPush()) {
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 node->set_move_collision(object_move_rotation, object_collision);
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 }
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
73
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 if (pad->left.isHold()) {
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 node->xyz[0] -= 10;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 } else if (pad->right.isHold()) {
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 node->xyz[0] += 10;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 }
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 if (pad->up.isHold()) {
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 node->xyz[1] -= 10;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 } else if (pad->down.isHold()) {
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 node->xyz[1] += 10;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 }
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 }
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
85
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
86
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 static void
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 object_collision(SceneGraphPtr node, void *sgroot_, int screen_w,
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 int screen_h, SceneGraphPtr tree)
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 {
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 // if (node->xyz[1] > screen_h - object_radius) {
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 // node->xyz[1] = screen_h - object_radius;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
93
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 // vy *= e;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 // if (vy > -g && vy < 0) {
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 // vy = 0.0;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 // node->set_move_collision(object_move_idle, object_collision_idle);
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 // }
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 // }
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 }
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
101
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 char *xmlfile;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 #define MAX_ROOT 100
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 char *parts[MAX_ROOT ];
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
105 int parts_cnt;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
106
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 MainLoopPtr
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 viewer::init(Viewer *sgroot, int screen_w, int screen_h)
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 {
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
110
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 LightSysSwitch(sgroot);
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
112
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 SceneGraphPtr object;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
114
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 for (int i = 0; i < light_num; i++) {
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 SceneGraphPtr light = sgroot->getLight(i);
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 sgroot->OnLightSwitch(i);
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 light->xyz[0] = screen_w / 2;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 light->xyz[1] = screen_h / 2;
1292
90efd2aac2cb add matrix test and debug light vector
Yutaka_Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents: 1218
diff changeset
120 light->xyz[2] = 100;
1207
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 }
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
122
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 // 固定した値で srandom すると、毎回同じ、random() 列が生成される
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 // random な値が欲しいなら、man random に方法が書いてあります。
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 srandom(100);
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
126
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
127 object = sgroot->createSceneGraph();
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 object->set_move_collision(object_move_rotation, object_collision);
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
129
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 object->xyz[0] = screen_w/2;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 object->xyz[1] = screen_h/2;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
132 object->xyz[2] = 30.0f;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
133
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
134
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 // [128]ってのは取得する文字列の十分な大きさ。
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 char *getStrDate[128];
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
137
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
138 char *fn = xmlfile; // 読み込みたいテキストファイル
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
139 const char *sStr = "surface name=\""; // この文字列の直後の文字列を取得する
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
140 const char *eStr = "\" size="; // この文字列の直前までの文字列を抜き取る
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
141
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 sgroot->createFromXMLfile(fn);
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
143
1218
d95b10b711ad view_2 accepts -name again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1207
diff changeset
144 if (parts_cnt>0) {
d95b10b711ad view_2 accepts -name again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1207
diff changeset
145 for( int i = 0; i < parts_cnt; i ++ ){
d95b10b711ad view_2 accepts -name again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1207
diff changeset
146 object->addChild( sgroot->createSceneGraph( parts[i] ) );
d95b10b711ad view_2 accepts -name again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1207
diff changeset
147 }
d95b10b711ad view_2 accepts -name again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1207
diff changeset
148 sgroot->setSceneData(object);
d95b10b711ad view_2 accepts -name again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1207
diff changeset
149 } else {
d95b10b711ad view_2 accepts -name again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1207
diff changeset
150 int num = getStrFromFile( getStrDate, fn, sStr, eStr );
1207
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
151
1218
d95b10b711ad view_2 accepts -name again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1207
diff changeset
152 for( int i = 0; i < num; i ++ ){
d95b10b711ad view_2 accepts -name again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1207
diff changeset
153 object->addChild( sgroot->createSceneGraph( getStrDate[i] ) );
d95b10b711ad view_2 accepts -name again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1207
diff changeset
154 }
d95b10b711ad view_2 accepts -name again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1207
diff changeset
155 sgroot->setSceneData(object);
d95b10b711ad view_2 accepts -name again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1207
diff changeset
156
d95b10b711ad view_2 accepts -name again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1207
diff changeset
157 for( int i = 0; i < num; i ++ ){
d95b10b711ad view_2 accepts -name again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1207
diff changeset
158 free( getStrDate[i] );
d95b10b711ad view_2 accepts -name again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1207
diff changeset
159 }
d95b10b711ad view_2 accepts -name again
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1207
diff changeset
160
1207
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
161 }
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
162
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
163
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 return sgroot;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
165 }
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
166
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
167 extern Application *
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
168 application() {
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
169 return new viewer();
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 }
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
171
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
172 const char *usr_help_str = "Usage: ./test_nogl [OPTION]\n";
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
173
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
174 extern int init(TaskManager *manager, int argc, char *argv[]);
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
175 extern void task_initialize();
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
176 static void TMend(TaskManager *manager);
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
177
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
178 int
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
179 TMmain(TaskManager *manager, int argc, char *argv[])
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
180 {
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 task_initialize();
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
182 manager->set_TMend(TMend);
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
183
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
184
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
185 for(int i=0;i<argc;i++) {
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
186 if (strcmp(argv[i],"-sg") == 0 && i+1<=argc) {
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
187 xmlfile = argv[i+1];
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
188 }
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
189 else if (strcmp(argv[i],"-name") == 0 && i+1<=argc) {
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
190 parts[parts_cnt++] = argv[i+1];
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
191 }
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
192 else if (strcmp(argv[i],"-lightsys") == 0 && i+1<=argc) {
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
193 if (strcmp(argv[i],"on") == 0) {
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
194 light_sysswitch = 1;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 } else if (strcmp(argv[i],"off") == 0) {
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
196 light_sysswitch = 0;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
197 }
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
198 } else if (strcmp(argv[i],"-lightnum") == 0 && i+1<=argc) {
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
199 light_num = atoi(argv[i+1]);
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
200 }
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
201 }
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
202 return init(manager, argc, argv);
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
203
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
204 }
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
205
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
206 void
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
207 TMend(TaskManager *manager)
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
208 {
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
209 printf("test_nogl end\n");
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
210 }
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
211
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
212
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
213 int getStrFromFile( char **getStrDate, const char *fname, const char *searchStartStr, const char *searchEndStr )
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
214 {
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
215 const int BUFSIZE = 256;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
216
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
217 // [100]ってのは取得する文字列の十分な大きさ。
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
218 // ここも動的に確保したいケド、良い方法がわからん。
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
219 // char *getStrDate[100];
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
220 int num = 0;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
221
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
222 FILE *fp;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
223 // const char *fname = "xml_file/car/kart_cp.xml"; // 読み込みたいファイル名
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
224
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
225 char buf[BUFSIZE]; // 一行読み込み
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
226 //const char *searchStartStr = "surface name=\""; // この文字列の直後の文字列を取得する
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
227 //const char *searchEndStr = "\" size="; // この文字列の直前までの文字列を抜き取る
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
228
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
229 fp = fopen( fname, "r" );
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
230 if ( fp ==NULL ){
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
231 printf("fileNameError\n");
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
232 return 0;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
233 }
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
234
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
235 // ファイルの終端まで一行読み込みをループする
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
236 while( feof(fp) == 0 ){
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
237
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
238 fgets( buf, BUFSIZE, fp );
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
239
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
240 char *p1 = strstr( buf, searchStartStr ); // 文字列検索。
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
241 // 見つけた位置のポインタを返す
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
242 // 見つけれなかったらNULLを返す
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
243
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
244 if( p1 != NULL ){
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
245 int p1Len = strlen(p1);
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
246 char *p2 = strstr( p1, searchEndStr );
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
247 int p2Len = strlen(p2); //
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
248
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
249 // 余分なsearchEndStr以降の文字列を切り捨てるため空白文字(改行文字だっけ?'\0'ってなんだっけ)
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
250 p1[p1Len - p2Len] = '\0';
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
251
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
252 int searchStartStrLen = strlen(searchStartStr);
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
253
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
254 // +searchStartStrLenで最初の余分な文字列をカウントしないようにする
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
255 int lenNum = strlen(p1 + searchStartStrLen);
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
256
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
257 // 動的にメモリ確保したい。なんかオカしいってのはわかるケド、良い方法が思いつかん
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
258 getStrDate[num] = (char*)malloc(sizeof(char)*lenNum);
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
259
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
260 strcpy(getStrDate[num], p1+searchStartStrLen);
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
261
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
262 num ++;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
263 }
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
264 }
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
265
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
266 fclose( fp );
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
267
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
268 // 確認:抜き出した文字列の数
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
269 printf("num = %d\n",num);
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
270
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
271 // 確認:抜き出した文字列
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
272 for( int i = 0; i < num; i ++ ){
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
273 printf("getStrDate[%d] = %s\n", i, getStrDate[i]);
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
274 }
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
275
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
276 return num;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
277 }
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
278
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
279 /* end */