Skip to content

Commit 9389e9a

Browse files
authored
Merge pull request #4 from ParsianRoboticLab/GOD
God
2 parents c0394b8 + 7b7fb67 commit 9389e9a

File tree

7 files changed

+1012
-204
lines changed

7 files changed

+1012
-204
lines changed

src/coach.rs

Lines changed: 0 additions & 49 deletions
This file was deleted.

src/dan.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl DAN {
8080
- _rules.arena.goal_top_radius,
8181
_rules.arena.goal_height - _rules.arena.goal_top_radius);
8282
if point.x >= (_rules.arena.goal_width / 2.0) + _rules.arena.goal_side_radius
83-
|| point.y >= _rules.arena.goal_height + _rules.arena.goal_side_radius
83+
|| point.h >= _rules.arena.goal_height + _rules.arena.goal_side_radius
8484
|| (v.x > 0.0 && v.y > 0.0 && v.len() >= _rules.arena.goal_top_radius
8585
+ _rules.arena.goal_side_radius) {
8686
dan = Self::min_dan(dan , Self::dan_to_plane(point, &Vec3::new(0.0, 0.0, _rules.arena.depth / 2.0), &Vec3::new(0.0, 0.0, -1.0)));

src/def.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,7 @@ impl VEC for Action {
117117
}
118118
}
119119
}
120+
121+
impl Copy for Ball {
122+
123+
}

src/draw.rs

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
2+
#[derive(Copy, Clone, Debug, Default)]
3+
struct Sphere {
4+
rad:f64,
5+
center:Vec3,
6+
color:(f64,f64,f64),
7+
}
8+
impl Sphere{
9+
fn new(rad : f64, center : Vec3, color : (f64,f64,f64)) -> Self {
10+
Self { rad, center, color }
11+
}
12+
}
13+
#[derive(Copy, Clone, Debug, Default)]
14+
struct Seg3 {
15+
p1:Vec3,
16+
p2:Vec3,
17+
color:(f64,f64,f64),
18+
}
19+
impl Seg3{
20+
fn new(p1 : Vec3, p2 : Vec3, color : (f64,f64,f64)) -> Self {
21+
Self { p1, p2, color }
22+
}
23+
}
24+
25+
// impl Default for sphere{
26+
// fn default() -> Self {
27+
// Self {
28+
// rad: 0.0,
29+
// center:Vec3::default(),
30+
// color:(0,0,0),
31+
// }
32+
// }
33+
// }
34+
#[derive(Clone, Debug, Default)]
35+
struct drawer {
36+
sphereList : Vec<Sphere>,
37+
lineList : Vec<Seg3>,
38+
debugTxt : String
39+
}
40+
impl drawer {
41+
fn createFinalString(&mut self) -> String {
42+
43+
let mut finalRes = String::new();
44+
if CAN_DRAW {
45+
finalRes.push_str("[
46+
");
47+
for i in 0..self.sphereList.len() {
48+
49+
finalRes.push_str(&format!(" {{ \"Sphere\": {{
50+
\"x\": {},
51+
\"y\": {},
52+
\"z\": {},
53+
\"radius\": {},
54+
\"r\": {},
55+
\"g\": {},
56+
\"b\": {},
57+
\"a\": 0.5
58+
}}
59+
}}
60+
",self.sphereList[i].center.x,self.sphereList[i].center.h,self.sphereList[i].center.y,self.sphereList[i].rad,self.sphereList[i].color.0,self.sphereList[i].color.1,self.sphereList[i].color.2)[..]);
61+
if i < self.sphereList.len() - 1 {
62+
finalRes.push_str(",");
63+
}
64+
}
65+
if self.sphereList.len() >= 1 && self.lineList.len() >= 1{
66+
finalRes.push_str(",");
67+
}
68+
69+
for i in 0..self.lineList.len() {
70+
71+
finalRes.push_str(&format!(" {{ \"Line\": {{
72+
\"x1\": {},
73+
\"y1\": {},
74+
\"z1\": {},
75+
\"x2\": {},
76+
\"y2\": {},
77+
\"z2\": {},
78+
\"width\": 1.0,
79+
\"r\": {},
80+
\"g\": {},
81+
\"b\": {},
82+
\"a\": 1.0
83+
}}
84+
}}
85+
",self.lineList[i].p1.x,self.lineList[i].p1.h,self.lineList[i].p1.y,self.lineList[i].p2.x,self.lineList[i].p2.h,self.lineList[i].p2.y,self.lineList[i].color.0,self.lineList[i].color.1,self.lineList[i].color.2)[..]);
86+
if i < self.lineList.len() - 1 {
87+
finalRes.push_str(",");
88+
}
89+
}
90+
91+
92+
finalRes.push_str (&format!(",{{
93+
\"Text\": \"{} \"
94+
}}",self.debugTxt));
95+
96+
97+
finalRes.push_str ("
98+
]");
99+
100+
101+
self.lineList.clear();
102+
self.sphereList.clear();
103+
}
104+
finalRes
105+
}
106+
107+
fn draw(&mut self, pos : Vec3, rad : f64, color : (f64,f64,f64)) {
108+
self.sphereList.push(Sphere::new(rad,pos,color));
109+
}
110+
111+
fn drawLine(&mut self, p1 : Vec3, p2 : Vec3, color : (f64,f64,f64)) {
112+
self.lineList.push(Seg3::new(p1,p2,color));
113+
}
114+
115+
fn drawText(&mut self, input : String) {
116+
self.debugTxt = input;
117+
}
118+
119+
120+
121+
}

src/entity3.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ trait Entity3 {
1414
fn set_position(&mut self, p : &Vec3);
1515
fn set_velocity(&mut self, v : &Vec3);
1616
fn set_height(&mut self, h: f64);
17+
fn set_velocity_h(&mut self, h: f64);
1718
fn set_touch_normal(&mut self, v : &Vec3);
1819

1920

@@ -72,6 +73,9 @@ impl Entity3 for Robot {
7273
self.touch_normal_y = Some(v.h);
7374
self.touch_normal_z = Some(v.y);
7475
}
76+
fn set_velocity_h(&mut self, h: f64){
77+
self.velocity_y = h;
78+
}
7579

7680
}
7781

@@ -117,5 +121,8 @@ impl Entity3 for Ball {
117121
fn set_touch_normal(&mut self, v: &Vec3) {
118122

119123
}
124+
fn set_velocity_h(&mut self, h: f64){
125+
self.velocity_y = h;
126+
}
120127

121128
}

0 commit comments

Comments
 (0)