Point TranslateCoordinates(Point p, Rect world, Rect view) { Point cw = world.Center(); Point slope = p.Add(cw).Sub(view.Center()); Point scaleFactor = world.ScaleFactorFor(view).Mul(1, -1); return scaleFactor.Mul(slope).Add(cw); // return Point( // sf.x * (p.x + cw.x - cv.x) + cw.x, // -sf.y * (p.y + cw.y - cv.y) + cw.y // ); }
Point TranslateMoreCoordinates(Point p, Rect world, Rect view) { Point p1; Point wd = world.Dimensions(); Point vd = view.Dimensions(); Point cw = world.Center(); Point cv = view.Center(); p1.x = vd.x + (+p.x * vd.x + wd.x * cw.x - wd.x * cv.x + cw.x * vd.x) / wd.x; p1.y = vd.y + (-p.y * vd.y + wd.y * cw.y - wd.y * cv.y + cw.y * vd.y) / wd.y; return p1; }
/** * Returns true if the given box is directly above the ground */ bool MovementMap::IsOnGround(const Rect box) { // Checks the lower limit if (!IsZero(box.Center().GetX(), box.GetY()+box.GetH()+1)) return true; // Checks the lower-right limit if (!IsZero(box.GetX()+box.GetW(), box.GetY()+box.GetH()+1)) return true; // Checks the lower-left limit if (!IsZero(box.GetX(), box.GetY()+box.GetH()+1)) return true; return false; }
/** * This method uses the new position of the given object, * its previous position and the map to determine whether * the object is colliding with the walls */ bool MovementMap::IsColliding(const Rect box) { // // Checks the center // if (!IsZero(box.Center().GetX(), box.Center().GetY())) return true; // Checks the above limit if (!IsZero(box.GetX()+box.GetW()/2, box.GetY())) return true; // Checks the right limit if (!IsZero(box.GetX() + box.GetW(), box.GetY() + box.GetH()/2)) return true; // Checks the left limit if (!IsZero(box.GetX(), box.GetY()+box.GetH()/2)) return true; // Checks the upper-right limit if (!IsZero(box.GetX()+box.GetW(), box.GetY())) return true; // Checks the upper-left limit if (!IsZero(box.GetX(), box.GetY())) return true; // Checks the lower limit if (!IsZero(box.Center().GetX(), box.Center().GetY() + box.GetH()/2)) return true; // Checks the lower-right limit if (!IsZero(box.GetX()+box.GetW(), box.GetY()+box.GetH())) return true; // Checks the lower-left limit if (!IsZero(box.GetX(), box.GetY()+box.GetH())) return true; return false; // return IsCollidingWithGround(box); }
void Window::VideoModeChange( void ) { Rect pos = *this; pos.Align( *view ); pos.Clip( *view ); if ( flags & WIN_CENTER ) pos.Center( *view ); if ( (pos.w != w) || (pos.h != h) ) { SetSize( pos.x, pos.y, pos.w, pos.h ); Draw(); } else { x = pos.x; y = pos.y; } }
void FillRhombMask(View & mask, const Rect & rect, uint8_t index) { assert(mask.format == View::Gray8 && Rect(mask.Size()).Contains(rect)); Simd::Fill(mask, 0); Point c = rect.Center(); for(ptrdiff_t row = rect.top; row < rect.bottom; ++row) { ptrdiff_t indent = std::abs(row - c.y)*rect.Width()/rect.Height(); ptrdiff_t left = rect.left + indent; ptrdiff_t right = rect.right - indent; ptrdiff_t offset = row*mask.stride + left; for(ptrdiff_t col = left; col < right; ++col, ++offset) mask.data[offset] = Random(2) ? index : 0; } }
// Create points to simulate ellipse using beziers // senses coordinate translation, generates CW (swap top and bottom for CCW) void ellipse2bezier(Rect &r, Line &out) { out.degree = 3; out.resize(13,Coord()); // MAGICAL CONSTANT to map ellipse to beziers // 2/3*(sqrt(2)-1) const double EToBConst = 0.2761423749154, translation = (r.b>r.t)?-1.0:1.0; Coord offset(r.Width() * EToBConst, r.Height() * EToBConst); Coord center(r.Center()); out[0].x = //------------------------/ out[1].x = // / out[11].x = // 2___3___4 / out[12].x = r.l; // 1 5 / out[5].x = // | | / out[6].x = // | | / out[7].x = r.r; // 0,12 6 / out[2].x = // | | / out[10].x = center.x - offset.x; // | | / out[4].x = // 11 7 / out[8].x = center.x + offset.x; // 10___9___8 / out[3].x = // / out[9].x = center.x; //------------------------* out[2].y = out[3].y = out[4].y = r.t; out[8].y = out[9].y = out[10].y = r.b; out[7].y = out[11].y = center.y - translation*offset.y; out[1].y = out[5].y = center.y + translation*offset.y; out[0].y = out[12].y = out[6].y = center.y; }
void Render(Context* pcontext) { Rect rect = GetViewRect()->GetValue(); pcontext->Translate(rect.Center()); pcontext->Scale2(0.5f * rect.XSize()); pcontext->Begin3DLayer(GetCamera(), false); #ifndef FixPermedia pcontext->SetShadeMode(ShadeModeCopy); #endif pcontext->SetShadeMode(ShadeModeGlobalColor); pcontext->SetGlobalColor( Color::White() ); pcontext->SetBlendMode( BlendModeAlphaStampThrough ); TList<PosterData, DefaultNoEquals>::Iterator iter(m_list); while (!iter.End()) { PosterData& data = iter.Value(); Point point; if (pcontext->TransformDirectionToImage(data.m_vec, point)) { pcontext->SetTexture(data.m_pimage->GetSurface()); pcontext->PushState(); pcontext->Multiply(data.m_mat); #ifdef FixPermedia Geo::GetWhiteEmissiveSquare()->Render(pcontext); #else Geo::GetSquare()->Render(pcontext); #endif pcontext->PopState(); } iter.Next(); } pcontext->End3DLayer(); }
bool MovementMap::SortCompare(Rect i, Rect j) { if (i.Center().Distance(previousPos.Center()) < j.Center().Distance(previousPos.Center())) return true; return false; }