Mercurial > hg > Game > Cerium
annotate Renderer/Engine/spe/ChainCal.cc @ 898:302ebfc75a79 draft
merge
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 16 Jul 2010 19:00:49 +0900 |
parents | 8aaa29d3e874 |
children |
rev | line source |
---|---|
539 | 1 #include <stdio.h> |
2 #include <string.h> | |
3 #include <math.h> | |
4 #include "ChainCal.h" | |
5 #include "Func.h" | |
6 #include "types.h" | |
7 | |
8 /* これは必須 */ | |
9 SchedDefineTask(ChainCal); | |
10 | |
755
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
11 #define CHAIN_LEN 50 |
539 | 12 |
755
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
13 static const double m = 100.0; |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
14 static const double k = 7000.0; |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
15 static const double g = 9.8; |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
16 static const double dt = 0.003; |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
17 static const double chain_width = 10; |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
18 static const double safe = 0.995; |
539 | 19 |
20 typedef struct { | |
755
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
21 double x, y, next_x, next_y; |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
22 double vx, vy, next_vx, next_vy; |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
23 double angle[3]; |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
24 int can_move; |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
25 uint32 parent; |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
26 int id; |
539 | 27 //int parent; |
28 } ChainProperty, *ChainPropertyPtr; | |
29 | |
30 static int | |
31 run(SchedTask *s,void *rbuf, void *wbuf) | |
32 { | |
755
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
33 ChainPropertyPtr property = (ChainPropertyPtr)s->get_input(rbuf, 0); |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
34 ChainPropertyPtr update_property = (ChainPropertyPtr)s->get_output(wbuf, 0); |
539 | 35 |
36 // ChainPropertyPtr property = (ChainPropertyPtr)rbuf; | |
755
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
37 // int id = get_param(0); |
539 | 38 |
39 //ChainPropertyPtr o_property = (ChainPropertyPtr)wbuf; | |
40 | |
41 for(int cnt = 0; cnt < 600; cnt++) { | |
755
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
42 for(int i = 0; i < CHAIN_LEN; i++) { |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
43 if(property[i].can_move) { |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
44 double dx = property[i-1].x - property[i].x; |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
45 double dy = property[i-1].y - property[i].y; |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
46 double l = sqrt(dx * dx + dy * dy); |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
47 double a = k * (l - chain_width) / m; |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
48 double ax = a * dx / l; |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
49 double ay = a * dy / l; |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
50 if(i < CHAIN_LEN - 1) { |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
51 dx = property[i+1].x - property[i].x; |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
52 dy = property[i+1].y - property[i].y; |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
53 l = sqrt(dx * dx + dy * dy); |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
54 a = k * (l - chain_width) / m; |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
55 ax += a * dx / l; |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
56 ay += a * dy / l; |
539 | 57 } |
755
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
58 ay += g; |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
59 property[i].vx *= safe; |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
60 property[i].vy *= safe; |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
61 property[i].next_vx = property[i].vx + ax * dt; |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
62 property[i].next_vy = property[i].vy + ay * dt; |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
63 property[i].next_x = property[i].x + property[i].vx * dt; |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
64 property[i].next_y = property[i].y + property[i].vy * dt; |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
65 } else { |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
66 property[i].next_x = property[i].x; |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
67 property[i].next_y = property[i].y; |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
68 } |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
69 } |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
70 for(int i = 0; i < CHAIN_LEN; i++) { |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
71 property[i].vx = property[i].next_vx; |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
72 property[i].vy = property[i].next_vy; |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
73 property[i].x = property[i].next_x; |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
74 property[i].y = property[i].next_y; |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
75 } |
539 | 76 } |
77 | |
78 for (int j = 0; j < CHAIN_LEN; j++) { | |
755
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
79 int p, n; |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
80 int id = property[j].id; |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
81 p = n = id; |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
82 if(p != 0) { |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
83 p--; |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
84 } |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
85 if(n != CHAIN_LEN - 1) { |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
86 n++; |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
87 } |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
88 property[j].angle[2-(id%2)*2] |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
89 = 90 + atan((property[p].next_y - property[n].next_y) / (property[p].next_x - property[n].next_x)) * 180 / M_PI; |
539 | 90 } |
755
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
91 |
8aaa29d3e874
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
539
diff
changeset
|
92 memcpy((void*)update_property, (void*)property, sizeof(ChainProperty) * CHAIN_LEN); |
539 | 93 return 0; |
94 } |