Core::Point ShapeSegment::getPointA() const { return Core::Point ( cpSegmentShapeGetA(mShape).x, cpSegmentShapeGetA(mShape).y ); }
PDebugger::PDebugger(Ogre::SceneManager *mgr, PLevel *lv, PPlayer *pl) : mNode(NULL), mLevel(lv), mPlayer(pl) { mMObject = new Ogre::ManualObject("PLevelDebug"); Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().create("matDebug","Grup_prova"); mat->setReceiveShadows(false); mat->getTechnique(0)->setLightingEnabled(true); mat->getTechnique(0)->getPass(0)->setDiffuse(0,1,0,0); mat->getTechnique(0)->getPass(0)->setAmbient(0,1,0); mat->getTechnique(0)->getPass(0)->setSelfIllumination(0,1,0); mMObject->begin("matDebug", Ogre::RenderOperation::OT_LINE_LIST); //comencem indexacio cpShape *shape; cpSegmentShape *s; cpVect v; const Ogre::Real zeta = -7.0f; for(int i=0;; i++) { shape = mLevel->getSegment(i); if(shape==NULL) break; //ja hem acabat v = cpSegmentShapeGetA(shape); mMObject->position(v.x, v.y, zeta); std::cerr << v.x << " " << v.y << std::endl; v = cpSegmentShapeGetB(shape); mMObject->position(v.x, v.y, zeta); std::cerr << v.x << " " << v.y << std::endl; } mMObject->end(); mNode = mgr->getRootSceneNode()->createChildSceneNode("PLevelDebugNode"); mNode->attachObject(mMObject); }
void PhysicsShapeEdgePolygon::getPoints(cocos2d::Vec2 *outPoints) const { int i = 0; for(auto shape : _cpShapes) { outPoints[i++] = PhysicsHelper::cpv2point(cpSegmentShapeGetA(shape)); } }
static void draw_segment_shape(struct draw_options opts, cpShape* shape, cpBody* body) { cpVect vect_a = cpSegmentShapeGetA(shape); cpVect vect_b = cpSegmentShapeGetB(shape); draw_line(opts, vect_a, vect_b); }
void PhysicsShapeEdgeChain::getPoints(Vec2* outPoints) const { int i = 0; for(auto shape : _cpShapes) { outPoints[i++] = PhysicsHelper::cpv2point(cpSegmentShapeGetA(shape)); } outPoints[i++] = PhysicsHelper::cpv2point(cpSegmentShapeGetB(_cpShapes.back())); }
Vec2 PhysicsShapeEdgePolygon::getCenter() { int count = (int)_cpShapes.size(); cpVect* points = new (std::nothrow) cpVect[count]; int i = 0; for(auto shape : _cpShapes) { points[i++] = cpSegmentShapeGetA(shape); } Vec2 center = PhysicsHelper::cpv2point(cpCentroidForPoly(count, points)); delete[] points; return center; }
void PhysicsShapeEdgeSegment::updateScale() { cpFloat factorX = _newScaleX / _scaleX; cpFloat factorY = _newScaleY / _scaleY; cpShape* shape = _cpShapes.front(); cpVect a = cpSegmentShapeGetA(shape); a.x *= factorX; a.y *= factorY; cpVect b = cpSegmentShapeGetB(shape); b.x *= factorX; b.y *= factorY; cpSegmentShapeSetEndpoints(shape, a, b); PhysicsShape::updateScale(); }
void PhysicsShapeEdgeChain::updateScale() { cpFloat factorX = _newScaleX / _scaleX; cpFloat factorY = _newScaleY / _scaleY; for (auto shape : _cpShapes) { cpVect a = cpSegmentShapeGetA(shape); a.x *= factorX; a.y *= factorY; cpVect b = cpSegmentShapeGetB(shape); b.x *= factorX; b.y *= factorY; cpSegmentShapeSetEndpoints(shape, a, b); } PhysicsShape::updateScale(); }
void PhysicsShapeEdgePolygon::updateScale() { cpFloat factorX = PhysicsHelper::float2cpfloat(_newScaleX / _scaleX); cpFloat factorY = PhysicsHelper::float2cpfloat(_newScaleY / _scaleY); for (auto shape : _cpShapes) { cpVect a = cpSegmentShapeGetA(shape); a.x *= factorX; a.y *= factorY; cpVect b = cpSegmentShapeGetB(shape); b.x *= factorX; b.y *= factorY; cpSegmentShapeSetEndpoints(shape, a, b); } PhysicsShape::updateScale(); }
void Renderer::drawBar(const cpShape* shape) { const auto p1 = cpSegmentShapeGetA(shape); const auto p2 = cpSegmentShapeGetB(shape); const auto radius = static_cast<float>(cpSegmentShapeGetRadius(shape)); auto rect = RoundedBar(radius); rect.setOutlineColor(sf::Color::Green); rect.setOutlineThickness(1.0f); rect.setFillColor(sf::Color::Transparent); const auto sfp1 = Utils::toSfv(p1, mTargetSize); const auto sfp2 = Utils::toSfv(p2, mTargetSize); const auto len = static_cast<float>(cpvdist(p1, p2)); if (p1.x == p2.x) { rect.setLength(len); auto y = std::min(sfp1.y, sfp2.y); rect.setRotation(90); rect.setPosition(sfp1.x, y + len / 2 - radius); rect.adjustOrigin(); } else if (p1.y == p2.y) { rect.setLength(len); auto x = std::min(sfp1.x, sfp2.x); rect.setPosition(x + len / 2 - radius, sfp1.y); rect.adjustOrigin(); } { for (auto& target : mTargets) { auto view = target->getView(); auto center = view.getCenter(); auto pieceW = view.getSize().x * 1.0f; auto pieceH = view.getSize().y * 1.0f; auto x = center.x - pieceW / 2.0f; auto y = center.y - pieceH / 2.0f; auto vRect = sf::FloatRect(x, y, pieceW, pieceH); if (vRect.intersects(rect.getGlobalBounds())) { target->draw(rect); } } } }
Vec2 PhysicsShapeEdgeSegment::getCenter() { auto a = PhysicsHelper::cpv2point(cpSegmentShapeGetA(_cpShapes.front())); auto b = PhysicsHelper::cpv2point(cpSegmentShapeGetB(_cpShapes.front())); return ( a + b ) / 2; }
Vec2 PhysicsShapeEdgeSegment::getPointA() const { return PhysicsHelper::cpv2point(cpSegmentShapeGetA(_cpShapes.front())); }