annotate Renderer/Test/spe/ChainCal.cc @ 965:1089f24bc86a

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