// Update position void Car::updatePosition() { // Did we arrive to the next position? switch (mDirection) { case Tile::EAST: if (getCenterPosition().x >= mNextCheckpoint.x) { nextTile(); } break; case Tile::SOUTH: if (getCenterPosition().y >= mNextCheckpoint.y) { nextTile(); } break; case Tile::WEST: if (getCenterPosition().x <= mNextCheckpoint.x) { nextTile(); } break; case Tile::NORTH: if (getCenterPosition().y <= mNextCheckpoint.y) { nextTile(); } break; default: break; } // Traffic light check TrafficLight* light = mNextTile->getTrafficLight(); // Resetting greenlight (avoid stopping IN an intersection) if (mCurrentIntersection) { // Gone past intersection if (!mCurrentIntersection->isInside(getRect())) { mCurrentIntersection = NULL; mGreenlit = false; } } // Do not drive past a red light // (Drive if: no light, green light or not yet inside next tile) if (!light || light->getStatus(mDirection) || !mNextTile->isInside(getRect()) || mGreenlit) { // Set greenlight (avoid stopping IN an intersection) if (light && mNextTile->isInside(getRect()) && light->getStatus(mDirection)) { mCurrentIntersection = mNextTile; mGreenlit = true; } move(mDirection); } }
bool ShapeEntityItem::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction, bool& keepSearching, OctreeElementPointer& element, float& distance, BoxFace& face, glm::vec3& surfaceNormal, void** intersectedObject, bool precisionPicking) const { // determine the ray in the frame of the entity transformed from a unit sphere glm::mat4 entityToWorldMatrix = getEntityToWorldMatrix(); glm::mat4 worldToEntityMatrix = glm::inverse(entityToWorldMatrix); glm::vec3 entityFrameOrigin = glm::vec3(worldToEntityMatrix * glm::vec4(origin, 1.0f)); glm::vec3 entityFrameDirection = glm::normalize(glm::vec3(worldToEntityMatrix * glm::vec4(direction, 0.0f))); float localDistance; // NOTE: unit sphere has center of 0,0,0 and radius of 0.5 if (findRaySphereIntersection(entityFrameOrigin, entityFrameDirection, glm::vec3(0.0f), 0.5f, localDistance)) { // determine where on the unit sphere the hit point occured glm::vec3 entityFrameHitAt = entityFrameOrigin + (entityFrameDirection * localDistance); // then translate back to work coordinates glm::vec3 hitAt = glm::vec3(entityToWorldMatrix * glm::vec4(entityFrameHitAt, 1.0f)); distance = glm::distance(origin, hitAt); bool success; surfaceNormal = glm::normalize(hitAt - getCenterPosition(success)); if (!success) { return false; } return true; } return false; }
void LoadingScene::initContent() { SpriteFrameCache::getInstance()->addSpriteFramesWithFile("ui/loadingScene/loadingScene.plist"); SpriteFrameCache::getInstance()->addSpriteFramesWithFile("ui/loadingScene/loading_fire.plist"); auto role = Sprite::createWithSpriteFrameName("loadingScene_role.png"); addChild(role); role->setPosition(Vec2(240,0)); auto logo = Sprite::createWithSpriteFrameName("loadingScene_logo.png"); addChild(logo); logo->setPosition(Vec2(0,20)); frame = Sprite::createWithSpriteFrameName("loadingScene_frame.png"); addChild(frame); frame->setPosition(Vec2(0,-150)); loadingBar = ProgressTimer::create(Sprite::createWithSpriteFrameName("loadingScene_bar.png")); loadingBar->setType(ProgressTimer::Type::BAR); loadingBar->setBarChangeRate(Vec2::ANCHOR_BOTTOM_RIGHT); loadingBar->setMidpoint(Vec2::ZERO); loadingBar->setPercentage(0.0f); frame->addChild(loadingBar); loadingBar->setPosition(getCenterPosition(frame)); fire = Sprite::createWithSpriteFrameName("loading_fire_0000.png"); fire->setAnchorPoint(Vec2::ANCHOR_MIDDLE_RIGHT); frame->addChild(fire); fire->setPosition(Vec2(50,frame->getContentSize().height/2)); auto animate = Animate::create( INSTANCE(AnimationUtils)->getCommonAnimation("ui/loadingScene/loading_fire.plist","loading_fire",0.07f)); auto repeat = RepeatForever::create(animate); fire->runAction(repeat); }
void NewChapterOpen::initContent() { CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("ui/fightUI/newChapter.plist"); CCSprite *sp_bg = CCSprite::createWithSpriteFrameName("newChapter_bg.png"); CCString *miniMapStr = CCString::createWithFormat("ui/chapter/miniMaps/mini_%d.png",sceneId); CCSprite *miniMap = CCSprite::create(miniMapStr->getCString()); sp_bg->addChild(miniMap); miniMap->setPosition(getCenterPosition(sp_bg)); CCSprite* sp_2 = CCSprite::createWithSpriteFrameName("newChapter_other.png"); sp_bg->addChild(sp_2); sp_2->setPosition(ccp(sp_bg->getContentSize().width,sp_bg->getContentSize().height/2)); CCLabelBMFont *label = CCLabelBMFont::create("恭喜开启新关卡", "font/font_ui.fnt"); sp_bg->addChild(label); label->setPosition(ccp(sp_bg->getContentSize().width/2, sp_bg->getContentSize().height)); CCScrollView* view = CCScrollView::create(); view->setContainer(sp_bg); view->setTouchEnabled(false); view->setContentOffset(ccp(-425, 20)); view->setViewSize(CCSizeMake(537, 370)); view->setContentSize(view->getViewSize()); view->setPosition(ccp(-view->getContentSize().width/2 + 40, -view->getContentSize().height/2)); addChild(view); CCSprite *sp_1 = CCSprite::createWithSpriteFrameName("newChapter_other.png"); addChild(sp_1); sp_1->setPosition(ccp(-225, 2)); view->setContentOffsetInDuration(ccp(0, 20), 0.2); }
void AnimatableSprite::setSprite(sf::Sprite sprite) { sf::Vector2f center = getCenterPosition(); sf::Vector2f scale = _sprite.getScale(); sf::Color color = _sprite.getColor(); sprite.setScale(scale); sprite.setColor(color); _sprite = sprite; setCenterPosition(center); }
std::string CollisionCapsuleObject::toString() const { std::stringstream ss; ss.precision(std::numeric_limits<float>::max_digits10); ss << "Collision capsule:" << std::endl; ss << std::setw(20) << std::left << " - Outer margin: " << getOuterMargin() << std::endl; ss << std::setw(20) << std::left << " - Radius: " << capsuleObject.getRadius() << std::endl; ss << std::setw(20) << std::left << " - Cylinder height: " << getCylinderHeight() << std::endl; ss << std::setw(20) << std::left << " - Orientation type: " << getCapsuleOrientation() << std::endl; ss << std::setw(20) << std::left << " - Center position: " << getCenterPosition() << std::endl; ss << std::setw(20) << std::left << " - Orientation: " << getOrientation() << std::endl; return ss.str(); }
glm::mat4 PolyVoxEntityItem::voxelToLocalMatrix() const { glm::vec3 voxelVolumeSize; withReadLock([&] { voxelVolumeSize = _voxelVolumeSize; }); glm::vec3 dimensions = getScaledDimensions(); glm::vec3 scale = dimensions / voxelVolumeSize; // meters / voxel-units bool success; // TODO -- Does this actually have to happen in world space? glm::vec3 center = getCenterPosition(success); // this handles registrationPoint changes glm::vec3 position = getWorldPosition(success); glm::vec3 positionToCenter = center - position; positionToCenter -= dimensions * Vectors::HALF - getSurfacePositionAdjustment(); glm::mat4 centerToCorner = glm::translate(glm::mat4(), positionToCenter); glm::mat4 scaled = glm::scale(centerToCorner, scale); return scaled; }
void ComboLayer::onEnter() { CCLayer::onEnter(); setPosition(getCenterPosition(this)); }
bool GameObject::onCollision(GameObject &gameObject)const { return(getCenterPosition().distance(gameObject.getCenterPosition()) < size.get_X()/2 + gameObject.size.get_X()/2); }
void AnimatableSprite::setScale(float x, float y) { sf::Vector2f center = getCenterPosition(); _sprite.setScale(x, y); setCenterPosition(center); }
SoundShape *SoundBox::clone() const { return new SoundBox(getHalfSizes(), getCenterPosition(), getOrientation(), getMargin()); }
const Capsule<float> CollisionCapsuleObject::retrieveCapsule() const { return Capsule<float>(getRadius(), getCylinderHeight(), getCapsuleOrientation(), getCenterPosition(), getOrientation()); }