comparison Renderer/Engine/spe/chain_move.cc @ 772:e53ae444ac6f

Test/property_chain is work
author hiroki@henri.cr.ie.u-ryukyu.ac.jp
date Mon, 15 Feb 2010 13:33:29 +0900
parents 2a00c1f470b7
children 8dd9fe36e206
comparison
equal deleted inserted replaced
771:720720e4e8df 772:e53ae444ac6f
6 #include "types.h" 6 #include "types.h"
7 7
8 /* これは必須 */ 8 /* これは必須 */
9 SchedDefineTask(ChainTask); 9 SchedDefineTask(ChainTask);
10 10
11 static const int PROPERTY_LENGTH = 51; 11 static const int PROPERTY_LENGTH = 50;
12 static double m = 100.0;
13 static double k = 7000.0;
14 static double g = 9.8;
15 static double dt = 0.003;
16 static double chain_width = 10;
17 static double safe = 0.995;
12 18
13 typedef struct { 19 typedef struct {
14 float xyz[3]; 20 float xyz[3];
15 float angle[3]; 21 float angle[3];
16 float stack_xyz[3]; 22 float stack_xyz[3];
17 float next_xyz[3]; 23 float next_xyz[3];
18 float v_xyz[3]; 24 float v_xyz[3];
25 float next_v_xyz[3];
19 int property_index; 26 int property_index;
20 int parent_index; 27 int parent_index;
21 int have_parent; 28 int have_parent;
22 int can_move; 29 int can_move;
23 memaddr parent; 30 memaddr parent;
24 memaddr children; 31 memaddr children;
25 memaddr node; 32 memaddr node;
26 const char *name; 33 int sgid;
27 } *PropertyPtr, Property; 34 } *PropertyPtr, Property;
28 35
29 static int 36 static int
30 run(SchedTask *s,void *rbuf, void *wbuf) 37 run(SchedTask *s,void *rbuf, void *wbuf)
31 { 38 {
32 PropertyPtr property = (PropertyPtr)s->get_input(rbuf, 0); 39 PropertyPtr property = (PropertyPtr)s->get_input(rbuf, 0);
33 PropertyPtr update_property = (PropertyPtr)s->get_output(wbuf, 0); 40 PropertyPtr update_property = (PropertyPtr)s->get_output(wbuf, 0);
34 41
35 int id = 0; 42 property[0].can_move = 0;
43
44 for(int cnt = 0; cnt < 600; cnt++) {
45 for(int i = 0; i < PROPERTY_LENGTH; i++) {
46 if(property[i].can_move) {
47 double dx = property[i-1].xyz[0] - property[i].xyz[0];
48 double dy = property[i-1].xyz[1] - property[i].xyz[1];
49 double l = sqrt(dx * dx + dy * dy);
50 double a = k * (l - chain_width) / m;
51 double ax = a * dx / l;
52 double ay = a * dy / l;
53 if(i < PROPERTY_LENGTH - 1) {
54 dx = property[i+1].xyz[0] - property[i].xyz[0];
55 dy = property[i+1].xyz[1] - property[i].xyz[1];
56 l = sqrt(dx * dx + dy * dy);
57 a = k * (l - chain_width) / m;
58 ax += a * dx / l;
59 ay += a * dy / l;
60 }
61 ay += g;
62 property[i].v_xyz[0] *= safe;
63 property[i].v_xyz[1] *= safe;
64 property[i].next_v_xyz[0] = property[i].v_xyz[0] + ax * dt;
65 property[i].next_v_xyz[1] = property[i].v_xyz[1] + ay * dt;
66 property[i].next_xyz[0] = property[i].xyz[0] + property[i].v_xyz[0] * dt;
67 property[i].next_xyz[1] = property[i].xyz[1] + property[i].v_xyz[1] * dt;
68 } else {
69 property[i].next_xyz[0] = property[i].xyz[0];
70 property[i].next_xyz[1] = property[i].xyz[1];
71 }
72 }
73 for(int i = 0; i < PROPERTY_LENGTH; i++) {
74 property[i].v_xyz[0] = property[i].next_v_xyz[0];
75 property[i].v_xyz[1] = property[i].next_v_xyz[1];
76 property[i].xyz[0] = property[i].next_xyz[0];
77 property[i].xyz[1] = property[i].next_xyz[1];
78 }
79 }
80
81 for(int i = 0; i < PROPERTY_LENGTH; i++) {
82 int id = property[i].property_index;
83 int p, n;
84 p = n = id;
85 if(p != 0) {
86 p--;
87 }
88 if(n != PROPERTY_LENGTH - 1) {
89 n++;
90 }
91 property[i].angle[2-(id%2)*2]
92 = 90 + atan((property[p].next_xyz[1] - property[n].next_xyz[1])
93 / (property[p].next_xyz[0] - property[n].next_xyz[0])) * 180 / M_PI;
94 }
36 95
37 memcpy((void*)update_property, (void*)property, sizeof(Property)*PROPERTY_LENGTH); 96 memcpy((void*)update_property, (void*)property, sizeof(Property)*PROPERTY_LENGTH);
38 97
39 return 0; 98 return 0;
40 } 99 }