Vec3 BallManager::calculateRealWorldPosition(MoveBall* ball, Kalman& filter) { float x,y,size; x=ball->position.x; y=ball->position.y; size=ball->ballSize; img->drawCircle(Vec2((int)x,(int)y),(int)(size/2),ColorRgb(255,0,255)); Vec3 position; position.z=filter.update(2500/size); //position.z=2500/size; position.x=(x-((float)img->w/2))*position.z/400; position.y=(y-((float)img->h/2))*position.z/-400; return position; }
void VisualEngine::onPaintAlt(IDrawableArea* drawable) { #if 0 Graphics ^g = e->Graphics; Pen ^p = gcnew Pen(Color::Red); int width = form->ClientRectangle.Width; int height = form->ClientRectangle.Height; if (backBuffer == nullptr) { backBuffer = gcnew Bitmap(width, height); } //Bitmap ^ localBitmap = gcnew Bitmap(width, height); //Graphics ^ bitmapGraphics = Graphics::FromImage( localBitmap ); Graphics ^ bitmapGraphics = Graphics::FromImage(backBuffer); bitmapGraphics->Clear(Color::Black); // Begin drawing of scene Serpents::Serpent &serpent = engine->getSerpent(); for (int i = 0; i<serpent.getLength(); i++) { BodyPart * bodyPart = serpent.getBodyPart(i); if (bodyPart != NULL) { bool vis = serpent.getBodyPart(i)->isSpawned(); double x = (int)(serpent.getBodyPart(i)->getLocation().x - serpent.getBodyPart(i)->getSizeFromCenter()); double y = (int)(serpent.getBodyPart(i)->getLocation().y - serpent.getBodyPart(i)->getSizeFromCenter()); double w = (int)serpent.getBodyPart(i)->getSize().x; double h = (int)serpent.getBodyPart(i)->getSize().y; //System::Diagnostics::Trace::WriteLine("index=" + i + "; pos=" // + x + "," // + y + "," // + w + "," // + h + ";" // + " visible=" + vis // ); if (vis) { bitmapGraphics->DrawEllipse(p, (float)x, (float)y, (float)w, (float)h); //bitmapGraphics->DrawRectangle(p, (float)x, (float)y, (float)w, (float)h); } } } for (int i = 0; i< serpent.path->getLength(); i++) { PathStrip *myStrip = serpent.path->getStrip(i); p->Color = Color::Gray; bitmapGraphics->DrawLine(p, (float)myStrip->getHeadLocation().x, (float)myStrip->getHeadLocation().y, (float)myStrip->getTailLocation().x, (float)myStrip->getTailLocation().y); p->Color = Color::GreenYellow; DPOINT myPoint = serpent.path->getCoords(i); float x = (float)myPoint.x; float y = (float)myPoint.y; bitmapGraphics->DrawLine(p, x - 1, y - 1, x + 1, y + 1); bitmapGraphics->DrawLine(p, x - 1, y + 1, x + 1, y - 1); } for (int i = 0; i<engine->getBonusController().getNumberOfItems(); i++) { Bonus * myBonus = engine->getBonusController().getItemAt(i); double x = (int)(myBonus->getLocation().x - myBonus->getSizeFromCenter()); double y = (int)(myBonus->getLocation().y - myBonus->getSizeFromCenter()); double w = (int)myBonus->getSize().x; double h = (int)myBonus->getSize().y; //System::Diagnostics::Trace::WriteLine("bonus, index=" + i + "; pos=" // + x + "," // + y + "," // + w + "," // + h + ";" // ); p->Color = Color::YellowGreen; bitmapGraphics->DrawRectangle(p, (float)x, (float)y, (float)w, (float)h); } // End drawing of scene Brush ^ myBrush = System::Drawing::Brushes::Beige; System::Drawing::Font ^myfont = gcnew Font(System::Drawing::FontFamily::GenericSansSerif, 10); drawable->drawText("up/down = increase/decrease speed; left/right = turn left/right", ColorRgb(0.5, 0.5, 0.5), 0, 0); bitmapGraphics->DrawString("up/down = increase/decrease speed; left/right = turn left/right", myfont, myBrush, 0, 0); bitmapGraphics->SmoothingMode = System::Drawing::Drawing2D::SmoothingMode::AntiAlias; //g->DrawImage( localBitmap, 0, 0 ); e->Graphics->DrawImageUnscaled(backBuffer, 0, 0); #endif }