本文整理汇总了C++中Polygon2类的典型用法代码示例。如果您正苦于以下问题:C++ Polygon2类的具体用法?C++ Polygon2怎么用?C++ Polygon2使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Polygon2类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: rasterize
void BlockPhysicsComponent::rasterize(Polygon2 const &polygon)
{
Polygon2 localPolygon;
for (int i = 0; i < polygon.getSize(); ++i) {
b2Vec2 worldPoint(polygon.vertices[i].x, polygon.vertices[i].y);
b2Vec2 localPoint = body_->GetLocalPoint(worldPoint);
localPolygon.vertices.push_back(Vector2(localPoint.x, localPoint.y));
}
Box2 bounds = localPolygon.getBoundingBox();
int minX = int(10.0f * bounds.p1.x + 0.05f);
int minY = int(10.0f * bounds.p1.y + 0.05f);
int maxX = int(10.0f * bounds.p2.x + 0.05f);
int maxY = int(10.0f * bounds.p2.y + 0.05f);
for (int y = minY; y <= maxY; ++y) {
for (int x = minX; x <= maxX; ++x) {
Vector2 localPoint(0.1f * float(x), 0.1f * float(y));
if (localPolygon.containsPoint(localPoint)) {
for (int dy = -1; dy <= 1; ++dy) {
for (int dx = -1; dx <= 1; ++dx) {
if (dx == 0 || dy == 0) {
setElement(x + dx, y + dy, 1);
}
}
}
}
}
}
}
示例2: Sprite
void SpriteTests::testTrickyIntersections()
{
AutoreleasePool::begin();
Sprite* space_ship = new Sprite(new MockView);
space_ship->setPosition(Vector2(0.0f, 0.0f));
// Obstacle
Polygon2 points;
points.push_back(Vector2(36.714285714286f, 29.857142857143f));
points.push_back(Vector2(40.285714285714f, 29.714285714286f));
points.push_back(Vector2(40.142857142857f, 1.0f));
points.push_back(Vector2(30.0f, 0.85714285714286f));
points.push_back(Vector2(30.428571428571f, 13.285714285714f));
Sprite* obstacle = new Sprite(new MockView(points));
CPTAssert(!space_ship->collide(obstacle, t, dt));
CPTAssert(!obstacle->collide(space_ship, t, dt));
space_ship->setPosition(Vector2(9.7f, -2.7f));
CPTAssert(!space_ship->collide(obstacle, t, dt));
CPTAssert(!obstacle->collide(space_ship, t, dt));
space_ship->setPosition(Vector2(11.9f, 7.71f));
CPTAssert(!space_ship->collide(obstacle, t, dt));
CPTAssert(!obstacle->collide(space_ship, t, dt));
space_ship->setPosition(Vector2(11.99f, 7.89f));
CPTAssert(!space_ship->collide(obstacle, t, dt));
CPTAssert(!obstacle->collide(space_ship, t, dt));
Group* g = new Group;
g->addKid(obstacle);
ShapeGroup* group = new ShapeGroup(g->iterator());
CPTAssert(!space_ship->collide(group, t, dt));
CPTAssert(!group->collide(space_ship, t, dt));
space_ship->setPosition(Vector2(9.7f, -2.7f));
CPTAssert(!space_ship->collide(group, t, dt));
CPTAssert(!group->collide(space_ship, t, dt));
space_ship->setPosition(Vector2(11.9f, 7.71f));
CPTAssert(!space_ship->collide(group, t, dt));
CPTAssert(!group->collide(space_ship, t, dt));
g->release();
group->release();
space_ship->release();
obstacle->release();
AutoreleasePool::end();
}
示例3: edge
bool Polygon2::containsAllOf(const Polygon2 &polygon) const
{
// If any vertex of @polygon is outside the boundary of @this, then
// @polygon is not wholly inside @this
for (int polyI = 0; polyI < polygon.size(); polyI++)
{
if ( !contains( polygon[polyI] ) )
{
return false;
}
}
// If any edge of @polygon intersects @this, then
// @polygon is not wholly contained within @this
int edgeIPrev = polygon.size() - 1;
for (int edgeI = 0; edgeI < polygon.size(); edgeI++)
{
Segment2 edge( polygon[edgeIPrev], polygon[edgeI] );
if ( checkEdgeIntersection( edge ) )
{
return false;
}
edgeIPrev = edgeI;
}
return true;
}
示例4: doIntersect
bool doIntersect(const Polygon2& p, const Line2& line) {
for (auto edge = p.edges_begin(); edge != p.edges_end(); ++edge) {
if (do_intersect(*edge, line)) {
return true;
}
}
return false;
}
示例5: pathFrom
static bool pathFrom(const Graph& g, Vertex t, const Vertices& p, Polygon2& path)
{
while (t != p[t]) {
path.push_back(g[t]);
t = p[t];
}
path.push_back(g[t]);
return true;
}
示例6: TEST_CASE_F
TEST_CASE_F(ComputePolygonOrientation_GivenLowestLeftmostTriangleIsDegenerate_ReturnsCorrectOrientation, Fixture)
{
Polygon2 polygon;
polygon.push_back(Vector2Type(0.0, 1.0));
polygon.push_back(Vector2Type(1.0, 1.0));
polygon.push_back(Vector2Type(0.0, 0.0));
polygon.push_back(Vector2Type(0.0, 0.0));
TriangulatorType triangulator;
const TriangulatorType::Orientation orientation =
triangulator.compute_polygon_orientation(polygon);
EXPECT_EQ(TriangulatorType::CW, orientation);
}
示例7: ProjectPolygon
void Collisions::ProjectPolygon(const Vector2 & axis, Polygon2 & poly, float32 & min, float32 & max)
{
Vector2 * points = poly.GetPoints();
float32 proj = DotProduct(points[0], axis);
min = proj;
max = proj;
for (int32 pi = 1; pi < poly.GetPointCount(); ++pi)
{
proj = DotProduct(points[pi], axis);
if (proj < min)
min = proj;
if (proj > max)
max = proj;
}
}
示例8:
/*!
Find number of times ray intersects polygon defined by iterators
*/
int Line2::noIntersections(const Polygon2& poly) const
{
int n = 0;
Vector2 v, v_prev;
Point2 p, p_prev;
ConstPointIterator2 begin = poly.begin();
ConstPointIterator2 end = poly.end();
ConstPointIterator2 it;
for (it = begin+1; it != end; ++it) {
if (intersect(Segment2(*(it-1), *it)))
++n;
}
if (intersect(Segment2(*(end-1), *begin)))
++n;
return n;
}
示例9: UIHoleTransition
void RenderTargetTestScreen::Update(float32 timeElapsed)
{
ftime += timeElapsed;
if (ftime > 5.0f)
{
UIHoleTransition *ft = new UIHoleTransition();
Polygon2 testPoly;
testPoly.AddPoint(Vector2(50, 85));
testPoly.AddPoint(Vector2(size.x - 50, 50));
testPoly.AddPoint(Vector2(size.x - 25, size.y - 85));
testPoly.AddPoint(Vector2(80, size.y - 50));
Matrix3 t, invT, r;
t.BuildTranslation(size/-2);
invT.BuildTranslation(size/2);
r.BuildRotation(DegToRad(10));
Matrix3 res = t * r * invT;
testPoly.Transform(res);
testPoly.Scale(size/2, 2.0f);
ft->SetDuration(10.f);
ft->SetPolygon(testPoly);
UIScreenManager::Instance()->SetScreen(SCREEN_STATIC_TEXT, ft);
SafeRelease(ft);
ftime = 0;
}
}
示例10: DrawPolygon
void RenderHelper::DrawPolygon( const Polygon2 & polygon, bool closed)
{
int ptCount = polygon.pointCount;
if (ptCount >= 2)
{
vertexStream->Set(TYPE_FLOAT, 2, 0, polygon.GetPoints());
RenderManager::Instance()->SetRenderEffect(RenderManager::FLAT_COLOR);
RenderManager::Instance()->SetRenderData(renderDataObject);
RenderManager::Instance()->DrawArrays(PRIMITIVETYPE_LINESTRIP, 0, ptCount);
if (closed)
{
Vector2 line[2] = {Vector2(polygon.GetPoints()[0]), Vector2(polygon.GetPoints()[ptCount-1])};
vertexStream->Set(TYPE_FLOAT, 2, 0, line);
RenderManager::Instance()->DrawArrays(PRIMITIVETYPE_LINESTRIP, 0, 2);
}
}
}
示例11: DrawCircle
void RenderHelper::DrawCircle(const Vector2 & center, float32 radius)
{
Polygon2 pts;
float32 angle = SEGMENT_LENGTH / radius;
int ptsCount = (int)(2 * PI / angle) + 1;
for (int k = 0; k < ptsCount; ++k)
{
float32 angle = ((float)k / (ptsCount - 1)) * 2 * PI;
float32 sinA = sinf(angle);
float32 cosA = cosf(angle);
Vector2 pos = center - Vector2(sinA * radius, cosA * radius);
pts.AddPoint(pos);
}
DrawPolygon(pts, false);
}
示例12: iPoints
/*!
The collision polygon calculated isn't optimal. We do it because it is used
for drawing. For collision handling it is poor.
\todo Refactor so collision and drawing polygon don't need to be the same
*/
PointsView::PointsView(Points2::iterator begin, Points2::iterator end) : iPoints(begin, end)
{
// Find rectangular polygon that will enclose all
// added points
Rect2 r;
Points2::iterator it;
for (it = begin; it != end; ++it) {
r = r.surround(*it);
}
Polygon2 p;
p.push_back(r.bottomLeft());
p.push_back(r.bottomRight());
p.push_back(r.topRight());
p.push_back(r.topLeft());
setCollisionPolygon(p);
}
示例13: getPolygon
/*!
Gets polygon from array of points stored at index t in
lua stack. We assume array is a table of the form
{{x = 1, y = 2}, {x = 3, y = 4}}. Polygon is returned in p.
*/
void getPolygon(lua_State* L, int t, Polygon2& p)
{
luaL_checktype(L, t, LUA_TTABLE); // Make sure we get a table with points as first argument
lua_pushnil(L); // first key (ready traversal of table)
while (lua_next(L, t) != 0) {
// ‘key’ is at index -2 and ‘value’ at index -1
p.push_back(Vector2_pull(L,-1));
lua_pop(L, 1); // removes ‘value’; keeps ‘key’ for next iteration
}
}
示例14: addPockets
void CueTable::addPockets(Polygon2& shape, int numOfHoles){
vector< Edge2 > edges = shape.getEdges();
for(int i = 0; i < numOfHoles; ){
Edge2 edge = edges[rand() % edges.size()];
float alpha = linearRand(0.0f, 1.0f);
if(insertPocket(shape, lerp(edge[0],edge[1],alpha))){
i++;
}
}
}
示例15: CreateTranslatorForPolygon
void CreateTranslatorForPolygon(
const Polygon2& poly,
CoordTranslator2& trans)
{
if (poly.empty()) return;
trans.mSrcMin = poly[0];
trans.mSrcMax = poly[0];
for (int n = 1; n < poly.size(); ++n)
{
trans.mSrcMin.x_ = min(trans.mSrcMin.x(), poly[n].x());
trans.mSrcMin.y_ = min(trans.mSrcMin.y(), poly[n].y());
trans.mSrcMax.x_ = max(trans.mSrcMax.x(), poly[n].x());
trans.mSrcMax.y_ = max(trans.mSrcMax.y(), poly[n].y());
}
trans.mDstMin.x_ = 0.0;
trans.mDstMax.y_ = 0.0;
trans.mDstMax.x_ = (trans.mSrcMax.x() - trans.mSrcMin.x()) * DEG_TO_MTR_LAT * cos((trans.mSrcMin.y() + trans.mSrcMax.y()) * 0.5 * DEG_TO_RAD);
trans.mDstMax.y_ = (trans.mSrcMax.y() - trans.mSrcMin.y()) * DEG_TO_MTR_LAT;
}