annotate Renderer/Test/collision_effect.cc @ 2069:26aa08c9a1de draft default tip

cuda example fix
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 12 Feb 2017 10:04:55 +0900
parents 5f12d99e95ac
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1389
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include <math.h>
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #include <stdlib.h>
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 #include "SceneGraphRoot.h"
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 #include "MainLoop.h"
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 #include "collision_effect.h"
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 // prototype
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 static void ball_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h);
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 static void ball_collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, SceneGraphPtr tree);
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 static void jump_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h);
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 static void fall_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h);
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 static void effect_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h);
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 static const float ball_radius = 88.0f;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 static const float target_radius = 88.0f;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 static int targetID;//targetのオブジェクトのIDを保存
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 /*
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 * 変数stat でボールの状態を表す。
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 * 0:地上
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 * 1:ジャンプ
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 * 2:左方向へジャンプ
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 * 3:右方向へジャンプ
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 */
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 static int stat;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 static void
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 ball_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h)
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 {
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 Pad *pad = sgroot->getController();
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 const float player_speed = 24.0f;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 if ( pad->up.isPush() || pad->up.isHold()) {
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 if ( pad->left.isPush() || pad->left.isHold() ){
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 stat = 2;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 }else if ( pad->right.isPush() || pad->right.isHold() ){
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 stat = 3;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 }
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 node->set_move_collision(jump_move,ball_collision);
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 }
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 if ( pad->left.isPush() || pad->left.isHold() ) {
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 node->xyz[0] -= player_speed;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 }else if ( pad->right.isPush() || pad->right.isHold() ) {
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 node->xyz[0] += player_speed;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 }else if ( pad->down.isPush() || pad->down.isHold() ) {
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 // node->xyz[1] += player_speed;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 }
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 }
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 static void
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 jump_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h)
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 {
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 float vy = 0.0f;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 const float g = 9.8f;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 const float player_speed = 30.0f;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 float dt = 2.0f;//frame rate
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 if ( stat == 2 ){
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 node->xyz[0] -= player_speed;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 }else if ( stat == 3 ){
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 node->xyz[0] += player_speed;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 }
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 vy += g * dt;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 node->xyz[1] -= vy * dt;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 if ( node->xyz[1] < 0 ){
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 node->set_move_collision(fall_move,ball_collision);
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 }
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 }
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
74
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
75
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 static void fall_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h)
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 {
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 float vy = 0.0f;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 const float g = -9.8f;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 const float dt = 2.0f;//frame rate
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 const float player_speed = 30.0f;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
82
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 if ( stat == 2 ){
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 node->xyz[0] -= player_speed;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 }else if ( stat == 3 ){
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 node->xyz[0] += player_speed;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 }
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 vy += g * dt;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 node->xyz[1] -= vy * dt;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 if (node->xyz[1] >= screen_h/2){
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 node->xyz[1] = screen_h/2;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 node->set_move_collision(ball_move,ball_collision);
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 }
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 }
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
95
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 static void
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 effect_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h)
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 {
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 node->remove();
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 }
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
101
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
102
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 static void
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 ball_collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h,
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
105 SceneGraphPtr tree)
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 {
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 SceneGraphIteratorPtr it = sgroot->getIterator(tree);
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
109
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 float x_distance,y_distance,distance;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
111
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 float target_speed = 48.0f;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
113
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
114
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 //IDが"target"のSceneGraphまですすめる
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 it->next(targetID);
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
117
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 //targetのシーングラフを取得
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 SceneGraphPtr target = it->get();
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 x_distance = node->xyz[0] - target->xyz[0];
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 y_distance = node->xyz[1] - target->xyz[1];
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
122
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 //二点間の距離を求める
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 distance = hypotf(x_distance,y_distance);
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
125
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 //二点間の距離が2つの半径の合計以下なら、衝突
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
127 if(distance <= (ball_radius + target_radius)){
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
128
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
129
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 /*
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 * 交点でエフェクト発生
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
132 * 接点の座標を(x,y)としたとき、
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
133 * (x - target->xyz[0]) : (x_distance) = target_radius : distance
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
134 * (x - target->xyz[0]) = (target_radius / distance)*(x_distance)
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 * 同様に、
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 * (y - target->xyz[1]) = (target_radius / distance)*(y_distance)
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
137 */
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
138
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
139 float rate = target_radius / distance;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
140 float x = rate * x_distance + target->xyz[0];
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
141 float y = rate * y_distance + target->xyz[1];
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
142
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
143 SceneGraphPtr effect = sgroot->createSceneGraph("BLAST3");
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
144 effect->set_move_collision(effect_move);
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
145 node->addBrother(effect);
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
146
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 //点(x,y)にエフェクト
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
148 effect->xyz[0] = x;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
149 effect->xyz[1] = y;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
150 effect->xyz[3] = -30.0f;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
151
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
152 if (node->xyz[1] > target->xyz[1]){
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 //上からぶつかられた場合はのけぞりを大きく
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
154 target_speed += ball_radius;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
155 }
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
156
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
157 if ( node->xyz[0] > target->xyz[0] ){
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 //右からぶつかられた場合
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 target->xyz[0] -= target_speed;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
160 } else{
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
161 //左からぶつかられた場合
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
162 target->xyz[0] += target_speed;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
163 }
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 }
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
165 }
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
166
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
167 MainLoopPtr
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
168 collision_effect::init(Viewer *sgroot, int screen_w, int screen_h)
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
169 {
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 sgroot->OnLightSysSwitch();
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
171
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
172 //ライト設置
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
173 SceneGraphPtr light = sgroot->getLight(0);
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
174 sgroot->OnLightSwitch(0);
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
175 light->xyz[0] = screen_w / 2;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
176 light->xyz[1] = screen_h / 2;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
177 light->xyz[2] = -100;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
178
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
179 SceneGraphPtr root = sgroot->createSceneGraph();
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
180
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 //effectのシーングラフ作成
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
182 sgroot->createFromXMLfile("xml_file/blast.xml");
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
183
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
184 //ボールのシーングラフ作成
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
185 SceneGraphPtr ball;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
186 sgroot->createFromXMLfile("xml_file/ball.xml");
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
187 ball = sgroot->createSceneGraph("Ball");
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
188
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
189
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
190 // ball_moveは最初、絶対地上にいるのでstatを0(地上判定)に更新
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
191 stat = 0;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
192
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
193 //初期化
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
194 ball->xyz[0] = screen_w;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 ball->xyz[1] = screen_h/2;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
196 ball->xyz[2] = 60.0f;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
197
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
198 //rootの子に追加
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
199 root->addChild(ball);
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
200
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
201
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
202 //targetのシーングラフ作成
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
203 SceneGraphPtr target = sgroot->createSceneGraph("Ball");
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
204 //IDの登録
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
205 targetID = target->sgid;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
206
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
207 target->xyz[0] = screen_w/2;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
208 target->xyz[1] = screen_h/2;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
209 target->xyz[2] = 60.f;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
210
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
211
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
212 //ボールの動きと当たり判定をセット
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
213 ball->set_move_collision(ball_move, ball_collision);
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
214
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
215 root->addChild(target);
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
216
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
217 sgroot->setSceneData(root);
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
218 return sgroot;
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
219 }
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
220
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
221 extern Application *
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
222 application() {
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
223 return new collision_effect();
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
224 }
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
225
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
226 const char *usr_help_str = "Usage: ./test_nogl [OPTION]\n";
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
227
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
228 extern int init(TaskManager *manager, int argc, char *argv[]);
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
229 extern void task_initialize();
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
230 static void TMend(TaskManager *manager);
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
231
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
232 int
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
233 TMmain(TaskManager *manager, int argc, char *argv[])
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
234 {
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
235 task_initialize();
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
236 manager->set_TMend(TMend);
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
237 return init(manager, argc, argv);
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
238
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
239 }
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
240
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
241 void
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
242 TMend(TaskManager *manager)
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
243 {
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
244 printf("test_nogl end\n");
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
245 }
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
246
5f12d99e95ac create test routine collision_effect.cc
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
diff changeset
247 /* end */