annotate TaskManager/Test/test_render/ball_bound.cpp @ 238:443c7ae1c7a7 draft

warning clean
author admin@mcbk.cr.ie.u-ryukyu.ac.jp
date Fri, 29 May 2009 13:43:52 +0900
parents 8ac35507094d
children 69a9d1f91dc9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
212
gongo@localhost.localdomain
parents: 210
diff changeset
1 #include <math.h>
213
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
2 #include <stdlib.h>
208
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
3 #include "SceneGraphRoot.h"
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
4 #include "SGList.h"
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
5
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
6 // prototype
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
7 static void ball_move(SceneGraphPtr node, int screen_w, int screen_h);
213
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
8 static void ball_collision(SceneGraphPtr node, int screen_w, int screen_h, SceneGraphPtr tree);
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
9 static void ball_collision_idle(SceneGraphPtr, int w, int h, SceneGraphPtr tree);
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
10
208
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
11
212
gongo@localhost.localdomain
parents: 210
diff changeset
12 static float vy = 0.0f; // y 方向速度
gongo@localhost.localdomain
parents: 210
diff changeset
13 static float dt = 1.0/1.0f; // frame rate
gongo@localhost.localdomain
parents: 210
diff changeset
14
gongo@localhost.localdomain
parents: 210
diff changeset
15 static float e = -0.8f; // 反発係数
gongo@localhost.localdomain
parents: 210
diff changeset
16 static float g = 9.8f; // 重力加速度
238
443c7ae1c7a7 warning clean
admin@mcbk.cr.ie.u-ryukyu.ac.jp
parents: 213
diff changeset
17 //static float v0 = 0.0f; // 初速は 0
212
gongo@localhost.localdomain
parents: 210
diff changeset
18
gongo@localhost.localdomain
parents: 210
diff changeset
19 static float h0; // 初期高さ
gongo@localhost.localdomain
parents: 210
diff changeset
20 static float ball_radius = 100.0f;
gongo@localhost.localdomain
parents: 210
diff changeset
21
213
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
22 static int speed = 10.0f;
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
23
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
24 static void
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
25 ball_move_idle2(SceneGraphPtr node, int screen_w, int screen_h)
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
26 {
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
27 Pad *pad = sgroot->getController();
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
28
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
29 if (pad->circle.isHold()) {
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
30 if (pad->left.isHold()) {
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
31 node->xyz[0] -= speed;
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
32 if(node->xyz[0] < ball_radius)
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
33 node->xyz[0] = ball_radius;
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
34 } else if (pad->right.isHold()) {
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
35 node->xyz[0] += speed;
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
36 if(node->xyz[0] > screen_w - ball_radius)
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
37 node->xyz[0] = screen_w - ball_radius;
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
38 }
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
39
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
40 if (pad->up.isHold()) {
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
41 node->xyz[1] -= speed;
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
42 } else if (pad->down.isHold()) {
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
43 node->xyz[1] += speed;
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
44 if(node->xyz[1] > screen_h - ball_radius)
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
45 node->xyz[1] = screen_h - ball_radius;
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
46 }
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
47 } else {
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
48 node->set_move_collision(ball_move, ball_collision);
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
49 }
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
50 }
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
51
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
52 static int time = 0;
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
53
212
gongo@localhost.localdomain
parents: 210
diff changeset
54 static void
gongo@localhost.localdomain
parents: 210
diff changeset
55 ball_move_idle(SceneGraphPtr node, int screen_w, int screen_h)
gongo@localhost.localdomain
parents: 210
diff changeset
56 {
213
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
57 Pad *pad = sgroot->getController();
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
58
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
59 if (pad->circle.isPush()) {
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
60 node->set_move_collision(ball_move_idle2, ball_collision_idle);
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
61 time = 0;
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
62 }
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
63
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
64 time++;
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
65
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
66 if (time > 90) {
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
67 float w = (float)random();
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
68
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
69 w = fmodf(w, screen_w - ball_radius*2);
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
70 node->xyz[0] = w + ball_radius;
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
71 node->xyz[1] = h0;
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
72 node->set_move_collision(ball_move, ball_collision);
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
73 time = 0;
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
74 }
212
gongo@localhost.localdomain
parents: 210
diff changeset
75 }
gongo@localhost.localdomain
parents: 210
diff changeset
76
208
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
77 static void
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
78 ball_move(SceneGraphPtr node, int screen_w, int screen_h)
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
79 {
212
gongo@localhost.localdomain
parents: 210
diff changeset
80 vy += g * dt;
gongo@localhost.localdomain
parents: 210
diff changeset
81 node->xyz[1] += vy * dt;
213
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
82 // node->xyz[0] += 10.0f;
212
gongo@localhost.localdomain
parents: 210
diff changeset
83 }
gongo@localhost.localdomain
parents: 210
diff changeset
84
gongo@localhost.localdomain
parents: 210
diff changeset
85 static void
gongo@localhost.localdomain
parents: 210
diff changeset
86 ball_collision_idle(SceneGraphPtr, int w, int h, SceneGraphPtr tree)
gongo@localhost.localdomain
parents: 210
diff changeset
87 {
208
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
88 }
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
89
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
90 static void
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
91 ball_collision(SceneGraphPtr node, int screen_w, int screen_h,
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
92 SceneGraphPtr tree)
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
93 {
212
gongo@localhost.localdomain
parents: 210
diff changeset
94 if (node->xyz[1] > screen_h - ball_radius) {
gongo@localhost.localdomain
parents: 210
diff changeset
95 node->xyz[1] = screen_h - ball_radius;
gongo@localhost.localdomain
parents: 210
diff changeset
96
gongo@localhost.localdomain
parents: 210
diff changeset
97 vy *= e;
gongo@localhost.localdomain
parents: 210
diff changeset
98 if (vy > -g && vy < 0) {
gongo@localhost.localdomain
parents: 210
diff changeset
99 vy = 0.0;
gongo@localhost.localdomain
parents: 210
diff changeset
100 node->set_move_collision(ball_move_idle, ball_collision_idle);
gongo@localhost.localdomain
parents: 210
diff changeset
101 }
gongo@localhost.localdomain
parents: 210
diff changeset
102 }
208
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
103 }
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
104
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
105
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
106 void
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
107 ball_bound_init(int screen_w, int screen_h)
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
108 {
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
109 SceneGraphPtr ball;
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
110
213
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
111 srandom(100);
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
112
210
e75f9eb97180 fix DrawSpan
gongo@localhost.localdomain
parents: 208
diff changeset
113 sgroot->createFromXMLfile("xml_file/Ball.xml");
208
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
114 ball = sgroot->createSceneGraph(Ball);
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
115 ball->set_move_collision(ball_move, ball_collision);
212
gongo@localhost.localdomain
parents: 210
diff changeset
116
gongo@localhost.localdomain
parents: 210
diff changeset
117 h0 = screen_h/2;
gongo@localhost.localdomain
parents: 210
diff changeset
118 h0 = -1000;
gongo@localhost.localdomain
parents: 210
diff changeset
119
208
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
120 ball->xyz[0] = screen_w/2;
213
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
121 //ball->xyz[0] = 0.0f;
212
gongo@localhost.localdomain
parents: 210
diff changeset
122 ball->xyz[1] = h0;
gongo@localhost.localdomain
parents: 210
diff changeset
123 ball->xyz[2] = 30.0f;
208
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
124
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
125 sgroot->setSceneData(ball);
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
126 }