Example #1
0
void Physics::FixedUpdate() {
	mRigidBody->setGravity(mGravity);
	btVector3 pos = btVector3(getWorldPosition().x,getWorldPosition().y,getWorldPosition().z);
	btVector3 scale = mRigidBody->getCollisionShape()->getLocalScaling();
	// std::cout << "position in fixedupdate: " << pos.x() << " " << pos.y() << " " << pos.z() << " SCALE IN FIXEDUPDATE: " << scale.x() << " " << scale.y() << " " << scale.z()<< std::endl;
	mTransform->sceneNode->setPosition(Ogre::Vector3(pos.x(), pos.y(), pos.z()));
}
std::pair<btScalar, btVector3> tgBulletSpringCableAnchor::getManifoldDistance(btPersistentManifold* m) const
{
	bool useB = true;
	
	btScalar length = INFINITY;
	btVector3 newNormal = contactNormal;
	
	if (m->getBody0() != attachedBody)
	{
		useB = false;			
	}
	if(useB || m->getBody1() == attachedBody)
	{	
			
		int n = m->getNumContacts();
		
		btVector3 contactPos = getWorldPosition();
		btScalar dist = 0.0;
		for (int p = 0; p < n; p++)
		{
			const btManifoldPoint& pt = m->getContactPoint(p);
			
			// Original position picked at beginning
			btVector3 pos = useB ? pt.m_positionWorldOnA : pt.m_positionWorldOnB;
			
			btScalar contactDist = (pos - getWorldPosition()).length();
			
			if (contactDist < length)
			{
				length = contactDist;
				contactPos = pos;
				
				btScalar directionSign = useB ? btScalar(1.0) : btScalar(-1.0);
				
				if (length < 0.1)
				{
					#ifdef USE_BASIS
					newNormal = attachedBody->getWorldTransform().inverse().getBasis() * pt.m_normalWorldOnB * directionSign;
					#else
					newNormal = pt.m_normalWorldOnB * directionSign;
					#endif
				}
				
				dist = pt.getDistance();
#ifdef VERBOSE				
				if (n >= 2)
				{
					std::cout << "Extra contacts!! " << p << " length " << length << " dist: " << dist << std::endl;
				}
#else
                    // Suppress compiler warning for unused variable
                    (void) dist;
#endif
			}
		}
	}
	
	return std::make_pair<btScalar, btVector3> (length, newNormal);
}
Example #3
0
void ModelOverlay::setProperties(const QVariantMap& properties) {
    auto origPosition = getWorldPosition();
    auto origRotation = getWorldOrientation();
    auto origDimensions = getDimensions();
    auto origScale = getSNScale();

    Base3DOverlay::setProperties(properties);

    auto scale = properties["scale"];
    if (scale.isValid()) {
        setSNScale(vec3FromVariant(scale));
    }

    auto dimensions = properties["dimensions"];
    if (!dimensions.isValid()) {
        dimensions = properties["size"];
    }
    if (dimensions.isValid()) {
        _scaleToFit = true;
        setDimensions(vec3FromVariant(dimensions));
    } else if (scale.isValid()) {
        // if "scale" property is set but "dimensions" is not.
        // do NOT scale to fit.
        _scaleToFit = false;
    }

    if (origPosition != getWorldPosition() || origRotation != getWorldOrientation() || origDimensions != getDimensions() || origScale != getSNScale()) {
        _updateModel = true;
    }

    auto loadPriorityProperty = properties["loadPriority"];
    if (loadPriorityProperty.isValid()) {
        _loadPriority = loadPriorityProperty.toFloat();
        _model->setLoadingPriority(_loadPriority);
    }

    auto urlValue = properties["url"];
    if (urlValue.isValid() && urlValue.canConvert<QString>()) {
        _url = urlValue.toString();
        _updateModel = true;
        _isLoaded = false;
        _texturesLoaded = false;
    }

    auto texturesValue = properties["textures"];
    if (texturesValue.isValid() && texturesValue.canConvert(QVariant::Map)) {
        _texturesLoaded = false;
        QVariantMap textureMap = texturesValue.toMap();
        QMetaObject::invokeMethod(_model.get(), "setTextures", Qt::AutoConnection,
                                  Q_ARG(const QVariantMap&, textureMap));
    }
Example #4
0
	void SceneNode::applyTransform_() {
		if(dirtyTransform_) {
			glMatrixMode( GL_MODELVIEW );
			glPushMatrix();
				glLoadIdentity();
				getWorldRotation().toMatrix(transform_);
				glTranslatef(getWorldPosition().x,getWorldPosition().y,getWorldPosition().z);
				glMultMatrixf(transform_);
				
				glGetFloatv(GL_MODELVIEW_MATRIX,transform_);
			glPopMatrix();
			dirtyTransform_ = false;
		}
		glMultMatrixf(transform_);
	}
void Hidden_Wall::CreateCollision(){

	b2BodyDef myBodyDef;
	myBodyDef.type = b2_staticBody; //this will be a dynamic body
	myBodyDef.angle = 0; //set the starting angle
	
	mBBody = mBWorld->CreateBody(&myBodyDef);
	mBBody->SetTransform( b2Vec2( getWorldPosition().x / 32.f, (getWorldPosition().y - 100.f) / 32.f ), 0.f );

	b2PolygonShape mBShape;
	mBShape.SetAsBox( 1, mWallWidth / 2.f / 32.f );
	
	b2FixtureDef mBFixtureDef;
	mBFixtureDef.shape = &mBShape;
	mBBody->CreateFixture(&mBFixtureDef);
}
bool Collision::isCollision()
{
    CCSize spipe = parent->boundingBox().size;
    CCPoint ppipe = getWorldPosition();
    
    CCSize sbird = bird->boundingBox().size;
    CCPoint pbird = bird->getPosition();
    
    float d = 6; 
    
    //the collision area is just like the symbol "#"
    
    //first get the # of those two areas, pipe and bird.
    
    float maxx1 = ppipe.x + spipe.width/2 - d;
    float minx1 = ppipe.x - spipe.width/2 + d;
    float maxy1 = ppipe.y + spipe.height/2 - d;
    float miny1 = ppipe.y - spipe.height/2 + d;
    
    float maxx2 = pbird.x + sbird.width/2 - d;
    float minx2 = pbird.x - sbird.width/2 + d;
    float maxy2 = pbird.y + sbird.height/2 - d;
    float miny2 = pbird.y - sbird.height/2 + d;
    
    //so here is the situation that the bird has no possibility to collision with the pipe
    //just need to return the opposite of this.
    return !(
             maxx1 < minx2 ||
             maxx2 < minx1 ||
             maxy1 < miny2 ||
             maxy2 < miny1
             );
    
}
Example #7
0
AABox Volume3DOverlay::getBounds() const {
    auto extents = Extents{_localBoundingBox};
    extents.rotate(getWorldOrientation());
    extents.shiftBy(getWorldPosition());

    return AABox(extents);
}
Example #8
0
bool WebEntityItem::findDetailedParabolaIntersection(const glm::vec3& origin, const glm::vec3& velocity, const glm::vec3& acceleration,
                                                     OctreeElementPointer& element, float& parabolicDistance,
                                                     BoxFace& face, glm::vec3& surfaceNormal,
                                                     QVariantMap& extraInfo, bool precisionPicking) const {
    glm::vec3 dimensions = getScaledDimensions();
    glm::vec2 xyDimensions(dimensions.x, dimensions.y);
    glm::quat rotation = getWorldOrientation();
    glm::vec3 position = getWorldPosition() + rotation * (dimensions * (ENTITY_ITEM_DEFAULT_REGISTRATION_POINT - getRegistrationPoint()));

    glm::quat inverseRot = glm::inverse(rotation);
    glm::vec3 localOrigin = inverseRot * (origin - position);
    glm::vec3 localVelocity = inverseRot * velocity;
    glm::vec3 localAcceleration = inverseRot * acceleration;

    if (findParabolaRectangleIntersection(localOrigin, localVelocity, localAcceleration, xyDimensions, parabolicDistance)) {
        float localIntersectionVelocityZ = localVelocity.z + localAcceleration.z * parabolicDistance;
        glm::vec3 forward = rotation * Vectors::FRONT;
        if (localIntersectionVelocityZ > 0.0f) {
            face = MIN_Z_FACE;
            surfaceNormal = forward;
        } else {
            face = MAX_Z_FACE;
            surfaceNormal = -forward;
        }
        return true;
    } else {
        return false;
    }
}
Example #9
0
Vector RenderObject::getWorldPositionAndRotation()
{
	Vector up = getWorldCollidePosition(Vector(0,1));
	Vector orig = getWorldPosition();
	MathFunctions::calculateAngleBetweenVectorsInDegrees(orig, up, orig.z);
	return orig;
}
Example #10
0
bool Collision::isCollision()
{
    Size spipe = parent->boundingBox().size;
    Point ppipe = getWorldPosition();
    
    Size sbird = bird->boundingBox().size;
    Point pbird = bird->getPosition();
    
    float d = 6;
    
    float maxx1 = ppipe.x + spipe.width/2 - d;
    float minx1 = ppipe.x - spipe.width/2 + d;
    float maxy1 = ppipe.y + spipe.height/2 - d;
    float miny1 = ppipe.y - spipe.height/2 + d;
    
    float maxx2 = pbird.x + sbird.width/2 - d;
    float minx2 = pbird.x - sbird.width/2 + d;
    float maxy2 = pbird.y + sbird.height/2 - d;
    float miny2 = pbird.y - sbird.height/2 + d;
    
    return !(maxx1 < minx2 ||
             maxx2 < minx1 ||
             maxy1 < miny2 ||
             maxy2 < miny1);
    
}
Example #11
0
const LLVector3	LLDrawable::getPositionAgent() const
{
	if (getVOVolume())
	{
		if (isActive())
		{
			if (!isRoot())
			{
				LLVector4a pos;
				pos.load3(mVObjp->getPosition().mV);
				getRenderMatrix().affineTransform(pos,pos);
				return LLVector3(pos.getF32ptr());
			}
			else
			{
				return LLVector3(getRenderMatrix().getRow<3>().getF32ptr());
			}
		}
		else
		{
			return mVObjp->getPositionAgent();
		}
	}
	else
	{
		return getWorldPosition();
	}
}
Example #12
0
void PolyVoxEntityItem::debugDump() const {
    quint64 now = usecTimestampNow();
    qCDebug(entities) << "   POLYVOX EntityItem id:" << getEntityItemID() << "---------------------------------------------";
    qCDebug(entities) << "            position:" << debugTreeVector(getWorldPosition());
    qCDebug(entities) << "          dimensions:" << debugTreeVector(getScaledDimensions());
    qCDebug(entities) << "       getLastEdited:" << debugTime(getLastEdited(), now);
}
Example #13
0
void Tile::updateCurrent(sf::Time dt, CommandQueue& commands)
{
	// Entity has been destroyed: Possibly drop pickup, mark for removal
	if (isDestroyed())
	{
		checkPickupDrop(commands);
		mExplosion.update(dt);
		// Play explosion sound only once
		if (!mExplosionBegan)
		{
			// Play sound effect
			SoundEffect::ID soundEffect = (randomInt(2) == 0) ? SoundEffect::Explosion1 : SoundEffect::Explosion2;
			playLocalSound(commands, soundEffect);

			// Emit network game action for explosions
			if (isBlock())
			{
				sf::Vector2f position = getWorldPosition();

				Command command;
				command.category = Category::Network;
				command.action = derivedAction<NetworkNode>([position] (NetworkNode& node, sf::Time)
															{
																node.notifyGameAction(GameActions::EnemyExplode, position);
															});

				commands.push(command);
				mExplosionBegan = true;
			}
		}
		return;
	}

	Entity::updateCurrent(dt, commands);
}
Example #14
0
bool AquariaMenuItem::isCursorInMenuItem()
{
	Vector v = dsq->mouse.position;
	int hw = font->getWidthOnScreen()/2;
	int hh = 20;
	if (hw < 64)
		hw = 64;
	if (glow)
	{
		hw = glow->getWidth()/2.0f;
		hh = glow->getHeight()/2.0f;
	}
	if (rotation.z == 90)
	{
		std::swap(hw, hh);
	}
	Vector pos = getWorldPosition();
	if (v.y > pos.y - hh && v.y < pos.y + hh)
	{
		if (v.x > pos.x - hw && v.x < pos.x + hw)
		{
			return true;
		}
	}
	return false;
}
Example #15
0
bool Image3DOverlay::findParabolaIntersection(const glm::vec3& origin, const glm::vec3& velocity, const glm::vec3& acceleration,
                                              float& parabolicDistance, BoxFace& face, glm::vec3& surfaceNormal, bool precisionPicking) {
    if (_texture && _texture->isLoaded()) {
        Transform transform = getTransform();

        // Produce the dimensions of the overlay based on the image's aspect ratio and the overlay's scale.
        bool isNull = _fromImage.isNull();
        float width = isNull ? _texture->getWidth() : _fromImage.width();
        float height = isNull ? _texture->getHeight() : _fromImage.height();
        float maxSize = glm::max(width, height);
        glm::vec2 dimensions = _dimensions * glm::vec2(width / maxSize, height / maxSize);
        glm::quat rotation = transform.getRotation();
        glm::vec3 position = getWorldPosition();

        glm::quat inverseRot = glm::inverse(rotation);
        glm::vec3 localOrigin = inverseRot * (origin - position);
        glm::vec3 localVelocity = inverseRot * velocity;
        glm::vec3 localAcceleration = inverseRot * acceleration;

        if (findParabolaRectangleIntersection(localOrigin, localVelocity, localAcceleration, dimensions, parabolicDistance)) {
            float localIntersectionVelocityZ = localVelocity.z + localAcceleration.z * parabolicDistance;
            glm::vec3 forward = rotation * Vectors::FRONT;
            if (localIntersectionVelocityZ > 0.0f) {
                face = MIN_Z_FACE;
                surfaceNormal = forward;
            } else {
                face = MAX_Z_FACE;
                surfaceNormal = -forward;
            }
            return true;
        }
    }

    return false;
}
Example #16
0
MatrixF VPathNode::getWorldTransform( void ) const
{
    MatrixF mat;
    getWorldRotation().setMatrix( &mat );
    mat.setPosition( getWorldPosition() );

    return mat;
}
Example #17
0
void PolyLineEntityItem::debugDump() const {
    quint64 now = usecTimestampNow();
    qCDebug(entities) << "   QUAD EntityItem id:" << getEntityItemID() << "---------------------------------------------";
    qCDebug(entities) << "               color:" << _color[0] << "," << _color[1] << "," << _color[2];
    qCDebug(entities) << "            position:" << debugTreeVector(getWorldPosition());
    qCDebug(entities) << "          dimensions:" << debugTreeVector(getScaledDimensions());
    qCDebug(entities) << "       getLastEdited:" << debugTime(getLastEdited(), now);
}
float RenderObject::getWorldRotation()
{
	Vector up = getWorldCollidePosition(Vector(0,1));
	Vector orig = getWorldPosition();
	float rot = 0;
	MathFunctions::calculateAngleBetweenVectorsInDegrees(orig, up, rot);
	return rot;
}
Example #19
0
CCRect UIWidget::getRect()
{
    CCPoint wPos = getWorldPosition();
    float width = m_size.width;
    float height = m_size.height;
    float offset_width = m_anchorPoint.x * width;
    float offset_height = m_anchorPoint.y * height;
    return CCRectMake(wPos.x - offset_width, wPos.y - offset_height, width, height);
}
Example #20
0
void the::camera::update()
{
    the::node::update();
    eyePosition   = getWorldPosition();
    prjMatrix     = mat4::perspective(_fov, _aspect, _zNear, _zFar);
    viewMatrix    = getLocalTransform().inverse();
    prjViewMatrix = prjMatrix * viewMatrix;
    _needUpdate = true;
}
Example #21
0
void Aircraft::createPickup(SceneNode& node, const TextureHolder& textures) const
{
	auto type = static_cast<Pickup::Type>(randomInt(Pickup::TypeCount));

	std::unique_ptr<Pickup> pickup(new Pickup(type, textures));
	pickup->setPosition(getWorldPosition());
	pickup->setVelocity(0.f, 1.f);
	node.attachChild(std::move(pickup));
}
Example #22
0
//Update the spaceship
void Spaceship::updateCurrent(sf::Time dt)
{
    Entity::updateCurrent(dt);
    //If we don't have a target, stay where we are
    if(target == sf::Vector2f(0, 0))
        target = getWorldPosition();
    sf::Vector2f velocity = getVelocity();
    velocity += normalize((target-getWorldPosition()))*deltaV*dt.asSeconds();
    if(sqrt(velocity.x*velocity.x+velocity.y*velocity.y) > maxV)
        velocity = normalize(velocity)*maxV;
    setVelocity(velocity);
    if(velocity.x != 0||velocity.y != 0)
    {
        float rotation = atan2(velocity.y, velocity.x)*180/3.1415+90;
        while(rotation > 360)
            rotation -= 360;
        setRotation(rotation);
    }
}
Example #23
0
the::camera::camera(const pugi::xml_node &n) :
    the::node("render::camera")
{
    eyePosition   = getWorldPosition();
    deserialize(n);
    auto rot = getWorldTransform().getEuler(); 
    logger::debug("[Camera ] create fov: %.2f, aspect: %.2f, pos: [%.1f:%.1f:%.1f] rot: [%.1f:%.1f:%.1f]",
                _fov,_aspect, eyePosition.x, eyePosition.y,eyePosition.z,rot.x, rot.y, rot.z);

}
void LLViewerJointAttachment::setupDrawable(LLViewerObject *object)
{
	if (!object->mDrawable)
		return;
	if (object->mDrawable->isActive())
	{
		object->mDrawable->makeStatic(FALSE);
	}

	object->mDrawable->mXform.setParent(getXform()); // LLViewerJointAttachment::lazyAttach
	object->mDrawable->makeActive();
	LLVector3 current_pos = object->getRenderPosition();
	LLQuaternion current_rot = object->getRenderRotation();
	LLQuaternion attachment_pt_inv_rot = ~(getWorldRotation());

	current_pos -= getWorldPosition();
	current_pos.rotVec(attachment_pt_inv_rot);

	current_rot = current_rot * attachment_pt_inv_rot;

	object->mDrawable->mXform.setPosition(current_pos);
	object->mDrawable->mXform.setRotation(current_rot);
	gPipeline.markMoved(object->mDrawable);
	gPipeline.markTextured(object->mDrawable); // face may need to change draw pool to/from POOL_HUD
	object->mDrawable->setState(LLDrawable::USE_BACKLIGHT);
	
	if(mIsHUDAttachment)
	{
		for (S32 face_num = 0; face_num < object->mDrawable->getNumFaces(); face_num++)
		{
			object->mDrawable->getFace(face_num)->setState(LLFace::HUD_RENDER);
		}
	}

	LLViewerObject::const_child_list_t& child_list = object->getChildren();
	for (LLViewerObject::child_list_t::const_iterator iter = child_list.begin();
		 iter != child_list.end(); ++iter)
	{
		LLViewerObject* childp = *iter;
		if (childp && childp->mDrawable.notNull())
		{
			childp->mDrawable->setState(LLDrawable::USE_BACKLIGHT);
			gPipeline.markTextured(childp->mDrawable); // face may need to change draw pool to/from POOL_HUD
			gPipeline.markMoved(childp->mDrawable);

			if(mIsHUDAttachment)
			{
				for (S32 face_num = 0; face_num < childp->mDrawable->getNumFaces(); face_num++)
				{
					childp->mDrawable->getFace(face_num)->setState(LLFace::HUD_RENDER);
				}
			}
		}
	}
}
Example #25
0
LLVector3 LLViewerJointCollisionVolume::getVolumePos(LLVector3 &offset)
{
	mUpdateXform = TRUE;
	
	LLVector3 result = offset;
	result.scaleVec(getScale());
	result.rotVec(getWorldRotation());
	result += getWorldPosition();

	return result;
}
Example #26
0
void
RocketLauncher::keyDown(unsigned int key) {
    if ( ' ' == (char)key ) {
        for ( auto it = mRockets.begin(); it != mRockets.end(); ++it ) {
            if ( (*it)->isFree() ) {
                (*it)->fire(getWorldPosition(), getWorldDirection());
                break;
            }
        }
    }
}
Example #27
0
void EmitterNode::emittParticles(sf::Time dt){
	const float emissionRate = 30.f;
	const sf::Time interval = sf::seconds(1.f) / emissionRate;

	mAccumulatedTime += dt;

	while (mAccumulatedTime > interval){
		mAccumulatedTime -= interval;
		mParticleSystem->addParticle(getWorldPosition());
	}
}
Example #28
0
Transform Shape3DOverlay::evalRenderTransform() {
    // TODO: handle registration point??
    glm::vec3 position = getWorldPosition();
    glm::vec3 dimensions = getDimensions();
    glm::quat rotation = getWorldOrientation();

    Transform transform;
    transform.setScale(dimensions);
    transform.setTranslation(position);
    transform.setRotation(rotation);
    return transform;
}
Example #29
0
void Aircraft::createProjectile(SceneNode& node, Projectile::Type type, float xOffset, float yOffset, const TextureHolder& textures) const
{
	std::unique_ptr<Projectile> projectile(new Projectile(type, textures));

	sf::Vector2f offset(xOffset * mSprite.getGlobalBounds().width, yOffset * mSprite.getGlobalBounds().height);
	sf::Vector2f velocity(0, projectile->getMaxSpeed());

	float sign = isAllied() ? -1.f : +1.f;
	projectile->setPosition(getWorldPosition() + offset * sign);
	projectile->setVelocity(velocity * sign);
	node.attachChild(std::move(projectile));
}
Example #30
0
void AvatarManager::handleCollisionEvents(const CollisionEvents& collisionEvents) {
    bool playedCollisionSound { false };
    for (Collision collision : collisionEvents) {
        // TODO: The plan is to handle MOTIONSTATE_TYPE_AVATAR, and then MOTIONSTATE_TYPE_MYAVATAR. As it is, other
        // people's avatars will have an id that doesn't match any entities, and one's own avatar will have
        // an id of null. Thus this code handles any collision in which one of the participating objects is
        // my avatar. (Other user machines will make a similar analysis and inject sound for their collisions.)
        if (collision.idA.isNull() || collision.idB.isNull()) {
            auto myAvatar = getMyAvatar();
            myAvatar->collisionWithEntity(collision);

            if (!playedCollisionSound) {
                playedCollisionSound = true;
                auto collisionSound = myAvatar->getCollisionSound();
                if (collisionSound) {
                    const auto characterController = myAvatar->getCharacterController();
                    const float avatarVelocityChange =
                        (characterController ? glm::length(characterController->getVelocityChange()) : 0.0f);
                    const float velocityChange = glm::length(collision.velocityChange) + avatarVelocityChange;
                    const float MIN_AVATAR_COLLISION_ACCELERATION = 2.4f;  // walking speed
                    const bool isSound =
                        (collision.type == CONTACT_EVENT_TYPE_START) && (velocityChange > MIN_AVATAR_COLLISION_ACCELERATION);

                    if (!isSound) {
                        return;  // No sense iterating for others. We only have one avatar.
                    }
                    // Your avatar sound is personal to you, so let's say the "mass" part of the kinetic energy is already accounted for.
                    const float energy = velocityChange * velocityChange;
                    const float COLLISION_ENERGY_AT_FULL_VOLUME = 10.0f;
                    const float energyFactorOfFull = fmin(1.0f, energy / COLLISION_ENERGY_AT_FULL_VOLUME);

                    // For general entity collisionSoundURL, playSound supports changing the pitch for the sound based on the size of the object,
                    // but most avatars are roughly the same size, so let's not be so fancy yet.
                    const float AVATAR_STRETCH_FACTOR = 1.0f;

                    _collisionInjectors.remove_if([](const AudioInjectorPointer& injector) { return !injector; });

                    static const int MAX_INJECTOR_COUNT = 3;
                    if (_collisionInjectors.size() < MAX_INJECTOR_COUNT) {
                        AudioInjectorOptions options;
                        options.stereo = collisionSound->isStereo();
                        options.position = myAvatar->getWorldPosition();
                        options.volume = energyFactorOfFull;
                        options.pitch = 1.0f / AVATAR_STRETCH_FACTOR;

                        auto injector = DependencyManager::get<AudioInjectorManager>()->playSound(collisionSound, options, true);
                        _collisionInjectors.emplace_back(injector);
                    }
                }
            }
        }
    }
}