int setPosition(TCan *can, int pos) { int rval; stopMotor(can); /* The motor must be stopped before any changes in the unit mode can be made. */ rval = setUnitMode(can, MODE_POS); rval |= startMotor(can); rval |= setAbsolutePosition(can, pos); rval |= beginMotion(can); return rval; }
void Object::rotateAround(float angle, Vector2 origin) { Vector2 oldPos = getAbsolutePosition(); Vector2 newPos = getAbsolutePosition(); newPos.rotateAround(angle,origin); setAbsolutePosition(newPos); translateChildren( newPos - oldPos ); }
void Object::setPosition(Vector2 newPosition) { if (m_parent) { newPosition.rotateAround( m_parent->getAbsoluteRotation(), Vector2(0,0) ); newPosition += m_parent->getAbsolutePosition(); } setAbsolutePosition( newPosition ); }
void GuiObject::sizeChanged(){ ob_type::Vector2* newPos = calculateRenderPosision(new ob_type::Vector2()); if(newPos){ setAbsolutePosition(newPos); delete newPos; } ob_type::Vector2* newSize = calculateRenderSize(new ob_type::Vector2()); if(newSize){ setAbsoluteSize(newSize); delete newSize; } }
void Object::translate(Vector2 delta) { if (!m_independent) { setAbsolutePosition( getAbsolutePosition() + delta ); for (unsigned i = 0; i < m_children.size(); ++i) { Object* child = m_children.at(i); child->translate( delta ); } } }
void Object::syncWithParent() { float deltaRotation = m_parent->getAbsoluteRotation() - parentPrimalRotation; Vector2 deltaPosition = m_parent->getAbsolutePosition() - parentPrimalPosition; setAbsoluteRotation(getAbsoluteRotation() + deltaRotation); // the rotation will affect the position Vector2 rotatedPosition = getAbsolutePosition() + deltaPosition; rotatedPosition.rotateAround(deltaRotation,m_parent->getAbsolutePosition()); setAbsolutePosition(rotatedPosition); parentPrimalRotation = m_parent->getAbsoluteRotation(); parentPrimalPosition = m_parent->getAbsolutePosition(); }
Meuble::Meuble(sf::Sprite &sprite, sf::Vector2f pos, sf::FloatRect hitBox, sf::FloatRect interactBox, GameContext& context) : m_sn(10), m_hitBox(hitBox), m_interactBox(interactBox) { m_entity = context.entityPool->createEntity(); auto node = context.scene->bindEntity(m_entity); auto body = context.physic->bindEntity(m_entity); body->setNode(node); body->setHitbox(hitBox); node->setAbsolutePosition(pos); m_sn.attachParent(*node); m_sn.setSprite(sprite); }