Mercurial > hg > Game > Cerium
annotate Renderer/Test/spe/chain_move.cc @ 965:e0427cdee770 draft
removing user task from Renderer Engine
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 06 Aug 2010 19:59:23 +0900 |
parents | Renderer/Engine/spe/chain_move.cc@64d9bf02c7d3 |
children |
rev | line source |
---|---|
768
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
1 #include <stdio.h> |
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
2 #include <string.h> |
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
3 #include <math.h> |
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
4 #include "chain_move.h" |
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
5 #include "Func.h" |
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
6 #include "types.h" |
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
7 |
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
8 /* これは必須 */ |
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
9 SchedDefineTask(ChainTask); |
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
10 |
771
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
11 static const int PROPERTY_LENGTH = 50; |
772 | 12 static float m = 100.0; |
13 static float k = 7000.0; | |
14 static float g = 9.8; | |
15 static float dt = 0.003; | |
16 static float chain_width = 10; | |
17 static float safe = 0.995; | |
768
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
18 |
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
19 typedef struct { |
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
20 float xyz[3]; |
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
21 float angle[3]; |
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
22 float stack_xyz[3]; |
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
23 float next_xyz[3]; |
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
24 float v_xyz[3]; |
771
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
25 float next_v_xyz[3]; |
768
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
26 int property_index; |
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
27 int parent_index; |
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
28 int have_parent; |
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
29 int can_move; |
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
30 memaddr parent; |
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
31 memaddr children; |
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
32 memaddr node; |
771
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
33 int sgid; |
768
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
34 } *PropertyPtr, Property; |
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
35 |
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
36 static int |
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
37 run(SchedTask *s,void *rbuf, void *wbuf) |
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
38 { |
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
39 PropertyPtr property = (PropertyPtr)s->get_input(rbuf, 0); |
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
40 PropertyPtr update_property = (PropertyPtr)s->get_output(wbuf, 0); |
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
41 |
771
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
42 property[0].can_move = 0; |
772 | 43 //property[1].can_move = 0; |
771
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
44 |
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
45 for(int cnt = 0; cnt < 600; cnt++) { |
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
46 for(int i = 0; i < PROPERTY_LENGTH; i++) { |
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
47 if(property[i].can_move) { |
772 | 48 #if 0 |
49 vector float v_x1 __attribute__((aligned(16))) = { property[i-1].xyz[0], | |
50 property[i].xyz[0], | |
51 property[i+1].xyz[0], | |
52 property[i+2].xyz[0]}; | |
53 vector float v_x2 __attribute__((aligned(16))) = { property[i].xyz[0], | |
54 property[i+1].xyz[0], | |
55 property[i+2].xyz[0], | |
56 property[i+3].xyz[0]}; | |
57 vector float v_dx __attribute__((aligned(16))) = spu_sub(v_x1, v_x2); | |
58 | |
59 vector float v_y1 __attribute__((aligned(16))) = { property[i-1].xyz[1], | |
60 property[i].xyz[1], | |
61 property[i+1].xyz[1], | |
62 property[i+2].xyz[1]}; | |
63 vector float v_y2 __attribute__((aligned(16))) = { property[i].xyz[1], | |
64 property[i+1].xyz[1], | |
65 property[i+2].xyz[1], | |
66 property[i+3].xyz[1]}; | |
67 vector float v_dy __attribute__((aligned(16))) = spu_sub(v_x1, v_x2); | |
68 | |
69 dx = spu_mule(dx, dx); | |
773 | 70 dy = spu_mule(dy, dy); |
772 | 71 vector float v_l __attribute__((aligned(16))); |
72 | |
73 #else | |
74 float dx = property[i-1].xyz[0] - property[i].xyz[0]; | |
75 float dy = property[i-1].xyz[1] - property[i].xyz[1]; | |
76 float l = sqrt(dx * dx + dy * dy); | |
77 float a = k * (l - chain_width) / m; | |
78 float ax = a * dx / l; | |
79 float ay = a * dy / l; | |
771
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
80 if(i < PROPERTY_LENGTH - 1) { |
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
81 dx = property[i+1].xyz[0] - property[i].xyz[0]; |
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
82 dy = property[i+1].xyz[1] - property[i].xyz[1]; |
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
83 l = sqrt(dx * dx + dy * dy); |
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
84 a = k * (l - chain_width) / m; |
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
85 ax += a * dx / l; |
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
86 ay += a * dy / l; |
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
87 } |
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
88 ay += g; |
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
89 property[i].v_xyz[0] *= safe; |
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
90 property[i].v_xyz[1] *= safe; |
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
91 property[i].next_v_xyz[0] = property[i].v_xyz[0] + ax * dt; |
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
92 property[i].next_v_xyz[1] = property[i].v_xyz[1] + ay * dt; |
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
93 property[i].next_xyz[0] = property[i].xyz[0] + property[i].v_xyz[0] * dt; |
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
94 property[i].next_xyz[1] = property[i].xyz[1] + property[i].v_xyz[1] * dt; |
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
95 } else { |
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
96 property[i].next_xyz[0] = property[i].xyz[0]; |
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
97 property[i].next_xyz[1] = property[i].xyz[1]; |
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
98 } |
772 | 99 #endif |
771
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
100 } |
772 | 101 |
771
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
102 for(int i = 0; i < PROPERTY_LENGTH; i++) { |
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
103 property[i].v_xyz[0] = property[i].next_v_xyz[0]; |
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
104 property[i].v_xyz[1] = property[i].next_v_xyz[1]; |
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
105 property[i].xyz[0] = property[i].next_xyz[0]; |
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
106 property[i].xyz[1] = property[i].next_xyz[1]; |
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
107 } |
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
108 } |
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
109 |
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
110 for(int i = 0; i < PROPERTY_LENGTH; i++) { |
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
111 int id = property[i].property_index; |
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
112 int p, n; |
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
113 p = n = id; |
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
114 if(p != 0) { |
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
115 p--; |
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
116 } |
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
117 if(n != PROPERTY_LENGTH - 1) { |
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
118 n++; |
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
119 } |
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
120 property[i].angle[2-(id%2)*2] |
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
121 = 90 + atan((property[p].next_xyz[1] - property[n].next_xyz[1]) |
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
122 / (property[p].next_xyz[0] - property[n].next_xyz[0])) * 180 / M_PI; |
0ad733bd134a
Test/property_chain is work
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
768
diff
changeset
|
123 } |
768
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
124 |
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
125 memcpy((void*)update_property, (void*)property, sizeof(Property)*PROPERTY_LENGTH); |
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
126 |
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
127 return 0; |
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
128 } |