Changeset 29750 for other-projects/fft-ddr/summer-2014/trunk/FFDDR/Form1.cs
- Timestamp:
- 2015-02-18T17:29:19+13:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
other-projects/fft-ddr/summer-2014/trunk/FFDDR/Form1.cs
r29736 r29750 14 14 using MicroLibrary; 15 15 using System.IO; 16 16 using System.Diagnostics; 17 18 using System.Drawing.Drawing2D; 17 19 18 20 namespace FFDDR 19 21 { 22 23 20 24 public partial class FFDDR : Form 21 25 { … … 43 47 44 48 private PictureBox[] pboxShowCalibrated; 45 49 46 50 private Vector4 centreScreen; 47 51 private bool twoPlayer = false; 48 52 private float deadspotSize = 50; 49 53 private int circleRadius = 400; 54 55 private float footSize = 30, defaultFootSize = 20, enlargedFootSize = 70; 56 57 float defaultScreenHeight; 58 float backgroundScaler = 0.4f; 59 60 int quadrentLeft, quadrentRight; 61 62 63 64 int blueScore = 0, redScore = 0, yellowScore = 0, greenScore = 0; 65 66 private float xCoordLeft, yCoordLeft, xCoordRight, yCoordRight; 67 List<FootStep> footstepList; 68 BeatPicturebox mainScreen; 69 int colourChanger = 0; 50 70 51 71 public FFDDR() … … 57 77 { 58 78 #region Beat detect 79 80 defaultScreenHeight = this.Height; 81 //scoreLabel.Left = (int)(0.7f * (float)this.Width); 82 //scoreLabel. 83 //label1.Font.SizeInPoints = 5; 59 84 60 85 // The song to convert + read … … 62 87 output = new WaveOut(); 63 88 output.Init(reader); 64 output.Play(); 65 graphics = mainScreen.CreateGraphics(); 66 89 //output.Play(); 90 //graphics = mainScreen.CreateGraphics(); 91 mainScreen = new BeatPicturebox(); 92 mainScreen.Left = 0; 93 mainScreen.Top = 0; 94 mainScreen.Width = mainScreen1.Width; 95 mainScreen.Height = mainScreen1.Height; 96 this.Controls.Add(mainScreen); 97 98 mainScreen.BringToFront(); 99 mainScreen.BackColor = Color.Transparent;//(Color)ColorTranslator.FromHtml("#353535"); 100 101 67 102 this.DoubleBuffered = true; 68 103 … … 70 105 wavInfo = WavProcessor.ReadWav(@"C:\Users\Chris\Downloads\", "become", 1024, 30); 71 106 72 107 73 108 74 109 // Play one buffer every (songLength/temp.length(numbuffer)) milliseconds. Both values are contained in the Json string[] … … 81 116 // timer.IgnoreEventIfLateBy = (int)((temp.songLength / wavInfo.Length) )/ 4; 82 117 83 timer.Enabled = true;118 //timer.Enabled = true; 84 119 timer.MicroTimerElapsed += new MicroTimer.MicroTimerElapsedEventHandler(timerTick); 120 121 footstepList = new List<FootStep>(); 85 122 86 123 #endregion … … 123 160 124 161 skeletonManager = new SkeletonManager(6); 125 graphics = screen.CreateGraphics(); 126 centreScreen.X = screen.Width / 2; 127 centreScreen.Z = screen.Height / 2; 162 graphics = mainScreen.CreateGraphics(); 163 centreScreen.X = mainScreen.Width / 2; 164 centreScreen.Z = mainScreen.Height / 2; 165 166 mainScreen.Paint += screen1_Paint; 128 167 129 168 #region Display pictureboxes showing calibration information … … 142 181 } 143 182 #endregion 144 } 145 146 private void timerTick(object sender, MicroTimerEventArgs args) 147 { 148 timeSinceLastBeat++; 149 wavFrameIncrement++; 150 151 if (mainScreen.InvokeRequired) 152 { 153 //mainScreen.Invoke(new MethodInvoker(delegate { mainScreen.Refresh(); })); 154 mainScreen.Invoke(new MethodInvoker(delegate { mainScreen.CreateGraphics().FillRectangle(new SolidBrush(Color.White), 0, 0, mainScreen.Width, mainScreen.Height); })); 155 } 156 157 158 183 184 redLabel.BringToFront(); 185 blueLabel.BringToFront(); 186 greenLabel.BringToFront(); 187 yellowLabel.BringToFront(); 188 /* 189 blueLabel = new Label(); 190 redLabel = new Label(); 191 greenLabel = new Label(); 192 yellowLabel = new Label(); 193 194 blueLabel.Font = new Font("Microsoft Sans Serif", 20); 195 redLabel.Font = new Font("Microsoft Sans Serif", 20); 196 greenLabel.Font = new Font("Microsoft Sans Serif", 20); 197 yellowLabel.Font = new Font("Microsoft Sans Serif", 20); 198 redLabel.BackColor = Color.Red; 199 200 redLabel.Left = (int)(10); 201 blueLabel.Left = (int)(0.8f * mainScreen.Width); 202 yellowLabel.Left = (int)(0.2f * mainScreen.Width); 203 greenLabel.Left = (int)(0.8f * mainScreen.Width); 204 205 redLabel.Top = (int)(10); 206 blueLabel.Top = (int)(0.1 * mainScreen.Height); 207 yellowLabel.Top = (int)(0.85 * mainScreen.Height); 208 greenLabel.Top = (int)(0.85 * mainScreen.Height); 209 210 redLabel.BringToFront(); 211 redLabel.Visible = true; 212 redLabel.Enabled = true; 213 label1.BringToFront(); 214 redLabel.Text = "Test"; 215 216 217 redLabel.Location = new System.Drawing.Point(10,10 ); 218 redLabel.Name = "redLabel"; 219 redLabel.Size = new System.Drawing.Size(173, 20); 220 159 221 // When song finished this is out of bounds. fix this. 160 222 WavFrame currentFrame = (WavFrame)JsonConvert.DeserializeObject<WavFrame>(wavInfo[wavFrameIncrement]); 161 223 for (int j = 0; j < currentFrame.bandPowers.Length; j++) 162 224 { 163 // Calling control change drawing beat visualizer bands) from another thread. 225 colourChanger++; 226 timeSinceLastBeat++; 227 wavFrameIncrement++; 228 /* 164 229 if (mainScreen.InvokeRequired) 165 230 { 166 mainScreen.Invoke(new MethodInvoker(delegate { mainScreen.CreateGraphics().DrawRectangle(new Pen(Color.DarkBlue), j * 15, 0, 10, 6 * currentFrame.bandPowers[j]); })); 167 } 168 } 169 170 // If a beat exists on the current frame, display it via BeatBox 171 if (currentFrame.beatExists == true) 172 { 173 if (beatBox.InvokeRequired) 174 { 175 beatBox.Invoke(new MethodInvoker(delegate { ChangeBeatBox(); })); 176 177 } 178 231 //mainScreen.Invoke(new MethodInvoker(delegate { mainScreen.Refresh(); })); 232 mainScreen.Invoke(new MethodInvoker(delegate { mainScreen.CreateGraphics().FillRectangle(new SolidBrush(Color.White), 0, 0, mainScreen.Width, mainScreen.Height); })); 233 } 234 235 236 */ 237 238 if (colourChanger >= 75) 239 { 240 241 colourChanger = 0; 242 Random random = new Random(); 243 if (random.Next(0, 2) == 1) 244 { 245 quadrentRight = random.Next(0, 5); 246 } 247 else 248 { 249 quadrentLeft = random.Next(0, 5); 250 } 251 252 } 253 254 if (footSize > defaultFootSize) 255 { 256 footSize *= 0.92f; 257 if (footSize < defaultFootSize) footSize = defaultFootSize; 258 } 259 260 for (int i = 0; i < footstepList.Count; i++) 261 { 262 footstepList[i].radius *= 1.05f; 263 if (footstepList[i].radius > enlargedFootSize) footstepList.Remove(footstepList[i]); 264 } 265 266 267 if (wavInfo.Length > wavFrameIncrement) 268 { 269 WavFrame currentFrame = (WavFrame)JsonConvert.DeserializeObject<WavFrame>(wavInfo[wavFrameIncrement]); 270 271 /* 272 for (int j = 0; j < currentFrame.bandPowers.Length; j++) 273 { 274 // Calling control change drawing beat visualizer bands) from another thread. 275 if (mainScreen.InvokeRequired) 276 { 277 mainScreen.Invoke(new MethodInvoker(delegate { mainScreen.CreateGraphics().DrawRectangle(new Pen(Color.DarkBlue), j * 15, 0, 10, 6 * currentFrame.bandPowers[j]); })); 278 } 279 } 280 */ 281 // If a beat exists on the current frame, display it via BeatBox 282 283 if (currentFrame.beatExists == true) 284 { 285 ChangeBeatBox(); 286 287 } 288 289 } 290 else System.Environment.Exit(1); 291 } 292 catch 293 { 294 System.Environment.Exit(1); 179 295 } 180 296 } … … 184 300 185 301 // Alternate the box which chanhges to the beat. 186 graphics = mainScreen.CreateGraphics(); 302 //graphics = mainScreen.CreateGraphics(); 303 304 187 305 188 306 if (timeSinceLastBeat >= 20) 189 307 { 308 309 310 /* 190 311 beatBoxChanger++; 191 312 timeSinceLastBeat = 0; … … 202 323 } 203 324 else p.BackColor = Color.DarkBlue; 325 */ 326 327 //footSize = enlargedFootSize; 328 footstepList.Add(new FootStep((float)defaultFootSize, xCoordLeft, yCoordLeft)); 329 footstepList.Add(new FootStep((float)defaultFootSize, xCoordRight, yCoordRight)); 330 timeSinceLastBeat = 0; 204 331 } 205 332 } … … 208 335 { 209 336 skeletonArray = new Skeleton[0]; 210 337 211 338 using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) 212 339 { … … 223 350 //screen2.Refresh(); 224 351 225 352 226 353 twoPlayer = false; 227 354 for (int i = 0; i < skeletonArray.Length; i++) 228 355 { 229 if (skeletonManager.calibrated[i] == false) skeletonManager.Calibrate(i); 356 if (skeletonManager.calibrated[i] == false) 357 { 358 if (skeletonManager.Calibrate(i) == 1) 359 { 360 output.Play(); 361 timer.Enabled = true; 362 } 363 } 230 364 231 365 if (skeletonManager.calibrated[i] == true) … … 235 369 { 236 370 skeletonManager.calibrated[i] = false; 237 pboxShowCalibrated[i].BackColor = Color.DarkGray;371 //pboxShowCalibrated[i].BackColor = Color.DarkGray; 238 372 } 239 373 else 240 374 { 241 242 pboxShowCalibrated[i].BackColor = Color.Cyan; 243 if (twoPlayer == false) graphics = screen.CreateGraphics(); 244 else graphics = screen2.CreateGraphics(); 245 375 376 //pboxShowCalibrated[i].BackColor = Color.Cyan; 377 //if (twoPlayer == false) graphics = screen.CreateGraphics(); 378 //else graphics = screen2.CreateGraphics(); 379 //graphics = mainScreen.CreateGraphics(); 380 //mainScreen.g 246 381 twoPlayer = true; 247 248 int quadrentLeft = skeletonManager.FindQuadrant(skeletonManager.leftFoot[i].Z, skeletonManager.leftFoot[i].X, skeletonManager.centre[i]); 249 int quadrentRight = skeletonManager.FindQuadrant(skeletonManager.rightFoot[i].Z, skeletonManager.rightFoot[i].X, skeletonManager.centre[i]); 250 251 graphics.FillRectangle(new SolidBrush(Color.White), 0, 0, screen.Width, screen.Height); 252 253 DrawQuadrent(quadrentLeft, graphics); 254 DrawQuadrent(quadrentRight, graphics); 255 256 float xCoordLeft = centreScreen.X + (skeletonManager.leftFoot[i].X - skeletonManager.centre[i].X) * (screen.Width / 2) / 0.8f; 257 float yCoordLeft = centreScreen.Z + (skeletonManager.leftFoot[i].Z - skeletonManager.centre[i].Z) * (screen.Height / 2) / 0.8f; 258 float xCoordRight = centreScreen.X + (skeletonManager.rightFoot[i].X - skeletonManager.centre[i].X) * (screen.Width / 2) / 0.8f; 259 float yCoordRight = centreScreen.Z + (skeletonManager.rightFoot[i].Z - skeletonManager.centre[i].Z) * (screen.Height / 2) / 0.8f; 260 261 262 263 graphics.DrawRectangle(new Pen(Color.Black), 264 (int)(xCoordLeft), 265 (int)(yCoordLeft), 266 20, 20); 267 268 graphics.DrawRectangle(new Pen(Color.Black), 269 (int)(xCoordRight), 270 (int)(yCoordRight), 271 20, 20); 272 273 382 383 int playerQuadrentLeft = skeletonManager.FindQuadrant(skeletonManager.leftFoot[i].Z, skeletonManager.leftFoot[i].X, skeletonManager.centre[i]); 384 int playerQuadrentRight = skeletonManager.FindQuadrant(skeletonManager.rightFoot[i].Z, skeletonManager.rightFoot[i].X, skeletonManager.centre[i]); 385 386 387 388 xCoordLeft = (centreScreen.X - footSize / 2) + (skeletonManager.leftFoot[i].X - skeletonManager.centre[i].X) * (mainScreen.Width / 2) / 1f; 389 yCoordLeft = (centreScreen.Z- footSize / 2) + (skeletonManager.leftFoot[i].Z - skeletonManager.centre[i].Z) * (mainScreen.Height / 2) / 1f; 390 xCoordRight = (centreScreen.X- footSize / 2) + (skeletonManager.rightFoot[i].X - skeletonManager.centre[i].X) * (mainScreen.Width / 2) / 1f; 391 yCoordRight = (centreScreen.Z- footSize / 2) + (skeletonManager.rightFoot[i].Z - skeletonManager.centre[i].Z) * (mainScreen.Height / 2) / 1f; 392 393 mainScreen.Invalidate(); 394 395 //drawBackground(); 274 396 275 397 } … … 293 415 private void DrawQuadrent(int num, Graphics graphics) 294 416 { 417 418 295 419 if (num == 1) 296 420 { 297 graphics.FillRectangle(new SolidBrush(Color.Red), 0, 0, screen.Width / 2, screen.Height / 2); 421 drawSegment(graphics, mainScreen.Width, mainScreen.Height, circleRadius, 180, 90, "#FFFFFF", "#DE00C0"); 422 //graphics.FillRectangle(new SolidBrush(Color.Red), 0, 0, screen.Width / 2, screen.Height / 2); 298 423 } 299 424 else if (num == 2) 300 425 { 301 graphics.FillRectangle(new SolidBrush(Color.Blue), screen.Width / 2, 0, screen.Width / 2, screen.Height / 2); 426 drawSegment(graphics, mainScreen.Width, mainScreen.Height, circleRadius, 270, 90, "#FFFFFF", "#00DCE8"); 427 //graphics.FillRectangle(new SolidBrush(Color.Blue), screen.Width / 2, 0, screen.Width / 2, screen.Height / 2); 302 428 } 303 429 else if (num == 3) 304 430 { 305 graphics.FillRectangle(new SolidBrush(Color.Green), screen.Height / 2, screen.Width / 2, screen.Width / 2, screen.Height / 2); 431 drawSegment(graphics, mainScreen.Width, mainScreen.Height, circleRadius, 0, 90, "#FFFFFF", "#00E800"); 432 433 //graphics.FillRectangle(new SolidBrush(Color.Green), screen.Height / 2, screen.Width / 2, screen.Width / 2, screen.Height / 2); 306 434 } 307 435 else if (num == 4) 308 436 { 309 graphics.FillRectangle(new SolidBrush(Color.Yellow), 0, screen.Height / 2, screen.Width / 2, screen.Height / 2); 310 } 311 graphics.FillEllipse(new SolidBrush(Color.Black), screen.Width / 2 - (deadspotSize / 2), screen.Height / 2 - (deadspotSize / 2), deadspotSize, deadspotSize); 312 313 314 315 } 316 437 drawSegment(graphics, mainScreen.Width, mainScreen.Height, circleRadius, 90, 90, "#FFFFFF", "#E8E800"); 438 //graphics.FillRectangle(new SolidBrush(Color.Yellow), 0, screen.Height / 2, screen.Width / 2, screen.Height / 2); 439 } 440 441 //graphics.FillEllipse(new SolidBrush(Color.Black), screen.Width / 2 - (deadspotSize / 2), screen.Height / 2 - (deadspotSize / 2), deadspotSize, deadspotSize); 442 443 444 445 } 446 447 448 public void screen1_Paint(object sender, PaintEventArgs e) 449 { 450 Graphics graphics = e.Graphics; 451 GraphicsPath path = new GraphicsPath(); 452 //test = e.Graphics; 453 path.AddEllipse(0, -((mainScreen.Width - mainScreen.Height) / 2), mainScreen.Width, mainScreen.Width); 454 455 // Create a path gradient brush based on the elliptical path. 456 PathGradientBrush pthGrBrush = new PathGradientBrush(path); 457 458 // Set the color along the entire boundary to 459 Color[] color = { (Color)ColorTranslator.FromHtml("#353535") }; 460 pthGrBrush.SurroundColors = color; 461 462 // Set the center color to aqua. 463 pthGrBrush.CenterColor = (Color)ColorTranslator.FromHtml("#E8E8E8"); ; 464 465 // Use the path gradient brush to fill the ellipse. 466 //graphics.FillPath(pthGrBrush, path); 467 468 // Set the focus scales for the path gradient brush. 469 pthGrBrush.FocusScales = new PointF(0.4f, 0.4f); 470 471 // Use the path gradient brush to fill the ellipse again. 472 // Show this filled ellipse to the right of the first filled ellipse. 473 //graphics.TranslateTransform(220.0f, 0.0f); 474 //e.Graphics.FillPath(pthGrBrush, path); 475 476 // Debug.Write("h"); 477 478 redLabel.Text = redScore.ToString(); 479 blueLabel.Text = blueScore.ToString(); 480 yellowLabel.Text = yellowScore.ToString(); 481 greenLabel.Text = greenScore.ToString(); 482 483 if (quadrentLeft != 1 && quadrentRight != 1) drawSegment(graphics, mainScreen.Width, mainScreen.Height, circleRadius, 180, 90, "#DE00C0", "#780068"); 484 if (quadrentLeft != 2 && quadrentRight != 2) drawSegment(graphics, mainScreen.Width, mainScreen.Height, circleRadius, 270, 90, "#000087", "#0000E8"); 485 if (quadrentLeft != 3 && quadrentRight != 3) drawSegment(graphics, mainScreen.Width, mainScreen.Height, circleRadius, 0, 90, "#008700", "#00E800"); 486 if (quadrentLeft != 4 && quadrentRight != 4) drawSegment(graphics, mainScreen.Width, mainScreen.Height, circleRadius, 90, 90, "#878700", "#E8E800"); 487 488 489 DrawQuadrent(quadrentLeft, graphics); 490 DrawQuadrent(quadrentRight, graphics); 491 492 for (int n = 0; n < footstepList.Count; n++) 493 { 494 if (n < footstepList.Count) 495 { 496 graphics.DrawEllipse(new Pen(Color.Black), footstepList[n].xPos - (footstepList[n].radius / 2), 497 footstepList[n].yPos - (footstepList[n].radius / 2), footstepList[n].radius, footstepList[n].radius); 498 } 499 } 500 501 graphics.FillEllipse(new SolidBrush(Color.Black), 502 (int)(xCoordLeft), 503 (int)(yCoordLeft), 504 footSize, footSize); 505 506 graphics.FillEllipse(new SolidBrush(Color.Black), 507 (int)(xCoordRight), 508 (int)(yCoordRight), 509 footSize, footSize); 510 511 512 513 } 514 515 private void drawBackground() 516 { 517 Graphics graphics = mainScreen.CreateGraphics(); 518 GraphicsPath path = new GraphicsPath(); 519 520 path.AddEllipse(0, -((mainScreen.Width - mainScreen.Height) / 2), mainScreen.Width, mainScreen.Width); 521 522 // Create a path gradient brush based on the elliptical path. 523 PathGradientBrush pthGrBrush = new PathGradientBrush(path); 524 525 // Set the color along the entire boundary to 526 Color[] color = { (Color)ColorTranslator.FromHtml("#353535") }; 527 pthGrBrush.SurroundColors = color; 528 529 // Set the center color to aqua. 530 pthGrBrush.CenterColor = (Color)ColorTranslator.FromHtml("#E8E8E8"); ; 531 532 // Use the path gradient brush to fill the ellipse. 533 //graphics.FillPath(pthGrBrush, path); 534 535 // Set the focus scales for the path gradient brush. 536 pthGrBrush.FocusScales = new PointF(backgroundScaler, backgroundScaler); 537 538 // Use the path gradient brush to fill the ellipse again. 539 // Show this filled ellipse to the right of the first filled ellipse. 540 //graphics.TranslateTransform(220.0f, 0.0f); 541 // graphics.FillPath(pthGrBrush, path); 542 543 544 545 } 546 547 private void drawSegment(Graphics graphics, float width, float height, int radius, int startAngle, int finAngle, string innerColour, string outerColour) 548 { 549 550 //graphics.FillPie(new SolidBrush(colour), (width / 2) - (radius / 2), (height / 2) - (radius / 2), radius, radius, startAngle, finAngle); 551 552 // Create a path that consists of a single ellipse. 553 GraphicsPath path = new GraphicsPath(); 554 path.AddEllipse((width / 2) - (radius / 2), (height / 2) - (radius / 2), 140, 70); 555 path.AddPie((width / 2) - (radius / 2), (height / 2) - (radius / 2), radius, radius, startAngle, finAngle); 556 557 // Use the path to construct a brush. 558 PathGradientBrush pthGrBrush = new PathGradientBrush(path); 559 560 // Set the center point to a location that is not 561 // the centroid of the path. 562 pthGrBrush.CenterPoint = new PointF((width / 2), (height / 2)); 563 564 //orange 565 566 // Set the color at the center of the path to blue. 567 568 pthGrBrush.CenterColor = (Color)ColorTranslator.FromHtml(innerColour); 569 570 // Set the color along the entire boundary 571 // of the path to aqua. 572 Color[] colors = { (Color)ColorTranslator.FromHtml(outerColour) }; 573 pthGrBrush.SurroundColors = colors; 574 575 //graphics.FillEllipse(pthGrBrush, 0, 0, 140, 70); 576 graphics.FillPie(pthGrBrush, (width / 2) - (radius / 2), (height / 2) - (radius / 2), radius, radius, startAngle, finAngle); 577 578 } 579 /* 580 private void FFDDR_ResizeEnd(object sender, EventArgs e) 581 { 582 mainScreen.Left = 0; 583 mainScreen.Height = this.Height; 584 mainScreen.Top = 0; 585 mainScreen.Width = this.Width; 586 587 drawBackground(); 588 } 589 */ 590 private void FFDDR_Resize(object sender, EventArgs e) 591 { 592 mainScreen.Left = 0; 593 mainScreen.Height = this.Height; 594 mainScreen.Top = 0; 595 mainScreen.Width = this.Width; 596 597 drawBackground(); 598 } 599 } 600 public class FootStep 601 { 602 public float radius; 603 public float xPos, yPos; 604 605 public FootStep(float Radius, float XPos, float YPos) 606 { 607 radius = Radius; 608 xPos = XPos; 609 yPos = YPos; 610 } 317 611 } 318 612 }
Note:
See TracChangeset
for help on using the changeset viewer.