Mercurial > hg > Members > kono > Cerium
comparison Renderer/Test/SgRootChange.cc @ 727:aaaa0baeab89
fix SgChange.cc, SgRootChange.cc
author | aaa |
---|---|
date | Sat, 19 Dec 2009 17:11:43 +0900 |
parents | fc0227b5cb5a |
children | 4f77768d7a7f |
comparison
equal
deleted
inserted
replaced
726:9136cf9186b6 | 727:aaaa0baeab89 |
---|---|
2 #include <stdlib.h> | 2 #include <stdlib.h> |
3 #include "SceneGraphRoot.h" | 3 #include "SceneGraphRoot.h" |
4 #include "MainLoop.h" | 4 #include "MainLoop.h" |
5 #include "SgRootChange.h" | 5 #include "SgRootChange.h" |
6 | 6 |
7 static void ball_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h); | |
8 static void ball_collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, SceneGraphPtr tree); | |
9 static void ball_collision_idle(SceneGraphPtr, void *sgroot_, int w, int h, SceneGraphPtr tree); | |
10 | |
11 | |
12 static float vy = 0.0f; // y 方向速度 | |
13 static float dt = 1.0/1.0f; // frame rate | |
14 | |
15 static float e = -0.8f; // 反発係数 | |
16 static float g = 9.8f; // 重力加速度 | |
17 //static float v0 = 0.0f; // 初速は 0 | |
18 | |
19 static float h0; // 初期高さ | |
20 static float ball_radius = 100.0f; | |
21 | |
22 static float speed = 10.0f; | |
23 | |
24 static void | |
25 ball_move_idle2(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) | |
26 { | |
27 SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_; | |
28 Pad *pad = sgroot->getController(); | |
29 | |
30 if (pad->circle.isHold()) { | |
31 if (pad->left.isHold()) { | |
32 node->xyz[0] -= speed; | |
33 if(node->xyz[0] < ball_radius) | |
34 node->xyz[0] = ball_radius; | |
35 } else if (pad->right.isHold()) { | |
36 node->xyz[0] += speed; | |
37 if(node->xyz[0] > screen_w - ball_radius) | |
38 node->xyz[0] = screen_w - ball_radius; | |
39 } | |
40 | |
41 if (pad->up.isHold()) { | |
42 node->xyz[1] -= speed; | |
43 } else if (pad->down.isHold()) { | |
44 node->xyz[1] += speed; | |
45 if(node->xyz[1] > screen_h - ball_radius) | |
46 node->xyz[1] = screen_h - ball_radius; | |
47 } | |
48 } else { | |
49 node->set_move_collision(ball_move, ball_collision); | |
50 } | |
51 } | |
52 | |
53 static int time = 0; | |
54 | |
55 static void | |
56 ball_move_idle(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) | |
57 { | |
58 SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_; | |
59 Pad *pad = sgroot->getController(); | |
60 | |
61 if (pad->circle.isPush()) { | |
62 node->set_move_collision(ball_move_idle2, ball_collision_idle); | |
63 time = 0; | |
64 } | |
65 | |
66 time++; | |
67 | |
68 if (time > 90) { | |
69 float w = (float)random(); | |
70 | |
71 w = fmodf(w, screen_w - ball_radius*2); | |
72 node->xyz[0] = w + ball_radius; | |
73 node->xyz[1] = h0; | |
74 node->set_move_collision(ball_move, ball_collision); | |
75 time = 0; | |
76 } | |
77 } | |
78 | |
7 static void | 79 static void |
8 ball_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) | 80 ball_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) |
9 { | 81 { |
10 printf("test\n"); | 82 vy += g * dt; |
83 node->xyz[1] += vy * dt; | |
84 // node->xyz[0] += 10.0f; | |
85 } | |
86 | |
87 static void | |
88 ball_collision_idle(SceneGraphPtr, void *sgroot_, int w, int h, SceneGraphPtr tree) | |
89 { | |
11 } | 90 } |
12 | 91 |
13 static void | 92 static void |
14 ball_collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, | 93 ball_collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, |
15 SceneGraphPtr tree) | 94 SceneGraphPtr tree) |
16 { | 95 { |
17 printf("collision\n"); | 96 if (node->xyz[1] > screen_h - ball_radius) { |
97 node->xyz[1] = screen_h - ball_radius; | |
98 | |
99 vy *= e; | |
100 if (vy > -g && vy < 0) { | |
101 vy = 0.0; | |
102 node->set_move_collision(ball_move_idle, ball_collision_idle); | |
103 } | |
104 } | |
18 } | 105 } |
19 | 106 |
20 // prototype | 107 // prototype |
21 MainLoopPtr | 108 MainLoopPtr |
22 SgRootChange::init(Viewer *sgroot, int screen_w, int screen_h) | 109 SgRootChange::init(Viewer *sgroot, int screen_w, int screen_h) |
26 | 113 |
27 MainLoopPtr | 114 MainLoopPtr |
28 SgRootChange::init_only_sg(SgChange *sgroot, int screen_w, int screen_h) | 115 SgRootChange::init_only_sg(SgChange *sgroot, int screen_w, int screen_h) |
29 { | 116 { |
30 SceneGraphPtr ball; | 117 SceneGraphPtr ball; |
118 srandom(100); | |
119 | |
31 sgroot->createFromXMLfile("xml_file/Ball.xml"); | 120 sgroot->createFromXMLfile("xml_file/Ball.xml"); |
32 ball = sgroot->createSceneGraph("Ball"); | 121 ball = sgroot->createSceneGraph("Ball"); |
33 ball->set_move_collision(ball_move, ball_collision); | 122 ball->set_move_collision(ball_move, ball_collision); |
123 | |
124 h0 = screen_h/2; | |
125 h0 = -1000; | |
126 | |
127 ball->xyz[0] = screen_w/2; | |
128 ball->xyz[1] = h0; | |
129 ball->xyz[2] = 30.0f; | |
130 | |
34 sgroot->setSceneData(ball); | 131 sgroot->setSceneData(ball); |
35 | 132 |
36 return sgroot; | 133 return sgroot; |
37 } | 134 } |
38 | 135 |