Пример #1
0
	void TileMap::Layer::onDraw(sf::RenderTarget& target, sf::RenderStates states) const
	{
		states.transform *= getWorldTransform() * getWorld().getPixelToWorldTransform();

		for (auto iter = mVertexArrays.begin(); iter != mVertexArrays.end(); ++iter)
		{
			states.texture = (*mTextures)[iter - mVertexArrays.begin()];
			target.draw(*iter, states);
		}
	}
Пример #2
0
math::Jacobian
TemplatedJacobianNode<NodeType>::getWorldJacobian(
    const Eigen::Vector3d& _offset) const
{
  math::Jacobian J = static_cast<const NodeType*>(this)->getWorldJacobian();
  J.bottomRows<3>() += J.topRows<3>().colwise().cross(
                                      getWorldTransform().linear() * _offset);

  return J;
}
Пример #3
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);

}
Пример #4
0
void Weapon::fireHitscan(WeaponData* weapon, CharacterObject* owner) {
    auto handFrame = owner->getClump()->findFrame("srhand");
    glm::mat4 handMatrix = handFrame->getWorldTransform();

    const auto& raydirection = owner->getLookDirection();
    const auto rayend = owner->getPosition() + raydirection * weapon->hitRange;
    auto fireOrigin = glm::vec3(handMatrix[3]);
    float dmg = weapon->damage;

    owner->engine->doWeaponScan({dmg, fireOrigin, rayend, weapon});
}
Пример #5
0
void PhysicsObject::handleOutOfBounds()
{
	btTransform transform;
	btVector3 newPosition = btVector3(0.0f, 10.0f, 0.0f);

	transform = getWorldTransform();
	transform.setOrigin(newPosition);
	setWorldTransform(transform);

	DEBUGPRINT("A physics object was out of bounds. It was moved to a new position " << newPosition.x() << " " << newPosition.y() << " " << newPosition.z());
}
Пример #6
0
void VehicleObject::setPosition(const glm::vec3& pos)
{
	GameObject::setPosition(pos);
	if( collision->getBulletBody() ) {
		auto bodyOrigin = btVector3(position.x, position.y, position.z);
		for(auto& part : dynamicParts)
		{
			if( part.second.body == nullptr ) continue;
			auto body = part.second.body;
			auto rel = body->getWorldTransform().getOrigin() -
					bodyOrigin;
			body->getWorldTransform().setOrigin(
				btVector3(pos.x + rel.x(), pos.y + rel.y(), pos.z + rel.z()));
		}

		auto t = collision->getBulletBody()->getWorldTransform();
		t.setOrigin(btVector3(pos.x, pos.y, pos.z));
		collision->getBulletBody()->setWorldTransform(t);
	}
}
Пример #7
0
Transform DynamicsComputations::getWorldTransform(std::string frameName)
{
    int frameIndex = getFrameIndex(frameName);
    if( frameIndex < 0 )
    {
        return Transform::Identity();
    }
    else
    {
        return getWorldTransform(frameIndex);
    }
}
QMatrix4x4 MotionState::getWorldTransformAsQMatrix4x4(){
    btTransform matrix;
    getWorldTransform(matrix);
    btScalar* m=new btScalar[16];
    matrix.getOpenGLMatrix(m);
    QMatrix4x4 worldTranform(m[0],m[4],m[8],m[12],
                            m[1],m[5],m[9],m[13],
                            m[2],m[6],m[10],m[14],
                            m[3],m[7],m[11],m[15]);
    delete m;
    return worldTranform;
}
Пример #9
0
void GfxLight::update (const Vector3 &cam_pos)
{
    if (dead) THROW_DEAD(className);
    light->setPosition(to_ogre(getWorldTransform().pos));
    light->setDirection(to_ogre(getWorldTransform().removeTranslation()*Vector3(0,1,0)));
    corona->pos = getWorldTransform() * coronaLocalPos;
    Vector3 col = enabled ? fade * coronaColour : Vector3(0,0,0);
    corona->dimensions = Vector3(coronaSize, coronaSize, coronaSize);

    Vector3 light_dir_ws = (cam_pos - getWorldTransform().pos).normalisedCopy();
    Vector3 light_aim_ws_ = getWorldTransform().removeTranslation() * Vector3(0,1,0);

    float angle = light_aim_ws_.dot(light_dir_ws);
    float inner = gritcos(coronaInnerAngle);
    float outer = gritcos(coronaOuterAngle);
    if (outer != inner) {
            float occlusion = std::min(std::max((angle-inner)/(outer-inner), 0.0f), 1.0f);
            col *= (1-occlusion);
    }
    corona->diffuse = Vector3(0, 0, 0);
    corona->emissive = col;
}
Пример #10
0
btVector3 btRigidBody::computeGyroscopicForceExplicit(btScalar maxGyroscopicForce) const
{
	btVector3 inertiaLocal = getLocalInertia();
	btMatrix3x3 inertiaTensorWorld = getWorldTransform().getBasis().scaled(inertiaLocal) * getWorldTransform().getBasis().transpose();
	btVector3 tmp = inertiaTensorWorld*getAngularVelocity();
	btVector3 gf = getAngularVelocity().cross(tmp);
	btScalar l2 = gf.length2();
	if (l2>maxGyroscopicForce*maxGyroscopicForce)
	{
		gf *= btScalar(1.)/btSqrt(l2)*maxGyroscopicForce;
	}
	return gf;
}
void FrustumPhysicsObject::onUpdate(float delta)
{
	btMatrix3x3 view = convert(itrCamera_3.at(attributeIndex_)->mat_view);
	btVector3 pos =  convert(itrCamera_3.at(attributeIndex_)->ptr_spatial->ptr_position->position);
	btQuaternion q;
	view.getRotation(q);
	btTransform world = getWorldTransform();
	world.setRotation(q);
	world.setOrigin(pos);
	setWorldTransform(world);
	
	setCollisionShape(CollisionShapes::Instance()->getFrustumShape(attributeIndex_));
}
Пример #12
0
std::vector<sf::FloatRect> Planet::getBoundingRect() const
{
	std::vector<sf::FloatRect> rects;
	if (mType == Earth || mType == Pluton)
	{
		sf::FloatRect bounds = mSprite.getGlobalBounds();

		// Because center of the origin in (100.f, 100.f)
		bounds.left = -mSprite.getTextureRect().width / 2.f;
		bounds.top = -mSprite.getTextureRect().height / 2.f;

		// Add Collision Rectangles
		addRect(bounds, 4.f, 60.f, 80.f, 30.f);
		rects.push_back(getWorldTransform().transformRect(bounds));
		addRect(bounds, 30.f, -35.f, 150.f, 30.f);
		rects.push_back(getWorldTransform().transformRect(bounds));
		addRect(bounds, 30.f, -22.f, 194.f, 30.f);
		rects.push_back(getWorldTransform().transformRect(bounds));
		addRect(bounds, 30.f, 0.f, 194.f, 30.f);
		rects.push_back(getWorldTransform().transformRect(bounds));
		addRect(bounds, 30.f, 10.f, 175.f, 30.f);
		rects.push_back(getWorldTransform().transformRect(bounds));
		addRect(bounds, 30.f, 15.f, 145.f, 15.f);
		rects.push_back(getWorldTransform().transformRect(bounds));
		addRect(bounds, 15.f, 15.f, 115.f, 15.f);
		rects.push_back(getWorldTransform().transformRect(bounds));
		addRect(bounds, 16.f, 20.f, 74.f, 12.f);
		rects.push_back(getWorldTransform().transformRect(bounds));
	}
	else
	{
		static sf::FloatRect bounds;

		bounds.left = -mSprite.getTextureRect().width / 2.f;
		bounds.top = -mSprite.getTextureRect().height / 2.f;
		bounds.width = mSprite.getTextureRect().width * 1.f;
		bounds.height = mSprite.getTextureRect().height * 1.f;

		rects.push_back(getWorldTransform().transformRect(bounds));
	}

	return rects;
}
Пример #13
0
	DReal DRenderable::getSquaredViewDepthToCamera( const DCamera* cam )
	{
		if (mCacheCamera == cam )
		{
			return mCacheDepth;
		}
		mCacheCamera = cam;
		DMatrix4 t = DMatrix4::IDENTITY;
		getWorldTransform(t);
		DVector3 p;
		t.getTranslate(p);
		mCacheDepth = (p-cam->getEyePosition()).dotProduct(cam->getDirection());
		return mCacheDepth;
	}
Пример #14
0
void the::camera::onRender(render::state &state)
{
    if(!_needUpdate) return;
    auto rot = getWorldTransform().getEuler(); 
    logger::debug("[Camera ] set 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);

    state.eyePosition       = eyePosition;
    state.projectionMatrix  = prjMatrix;
    state.viewMatrix        = viewMatrix;
    state.inverseViewMatrix = viewMatrix.inverse();
    state.prjViewMatrix     = prjViewMatrix;
    _needUpdate = false;
}
Пример #15
0
void PhysicsObject::hover(float delta, float hoverHeight)
{
	btVector3 from = getWorldTransform().getOrigin();
	btVector3 to = from - btVector3(0.0f,hoverHeight*2.0f,0.0f);
	btCollisionWorld::ClosestRayResultCallback ray(from,to);
	ray.m_collisionFilterGroup = XKILL_Enums::PhysicsAttributeType::RAY;
	ray.m_collisionFilterMask = XKILL_Enums::PhysicsAttributeType::WORLD;
	dynamicsWorld_->rayTest(from,to,ray); //cast ray from player position straight down
	if(ray.hasHit())
	{
		btVector3 point = from.lerp(to,ray.m_closestHitFraction);
		float length = (point - from).length();
		float something = hoverHeight-length;
		if(something > 0.0f)
		{
			btTransform worldTransform;
			worldTransform = getWorldTransform();
			worldTransform.setOrigin(worldTransform.getOrigin() + btVector3(0.0f,something,0.0f)*delta/0.25f);
			setWorldTransform(worldTransform);

			setLinearVelocity(getLinearVelocity()+btVector3(0.0f,-getLinearVelocity().y(),0.0f));
		}
	}
}
Пример #16
0
void PhysicsObject::onUpdate(float delta)
{	
	AttributePtr<Attribute_Physics> physicsAttribute = itrPhysics_.at(attributeIndex_);
	Float3 position = physicsAttribute->ptr_spatial->ptr_position->position;
	if(position.y < outOfBoundsIfYIsLowerThanThis)
	if(getWorldTransform().getOrigin().y() < outOfBoundsIfYIsLowerThanThis)
	{
		handleOutOfBounds();
	}

	//if(getWorldTransform().getOrigin().y() < outOfBoundsIfYIsLowerThanThis)
	//{
	//	handleOutOfBounds();
	//}
}
Пример #17
0
	void TileMap::onDraw(sf::RenderTarget& target, sf::RenderStates states) const
	{
		states.transform *= getWorldTransform();

		states.texture = NULL;
		if ((mDrawFlags & COLLIDER) > 0)
		{
			target.draw(*mpCollider, states);
		}

		if ((mDrawFlags & NAV_GRAPH) > 0)
		{
			target.draw(*mpNavGraph, states);
		}
	}
Пример #18
0
void PxCloth::processTick( const Move *move )
{
   // Make sure the cloth is created.
   if ( !mCloth )
      return;

   // TODO: Remove this hack!
   const bool enableWind = Con::getBoolVariable( "$PxCloth::enableWind", false );

   if ( enableWind )
   {
      NxVec3 windVec(   25.0f + NxMath::rand(-5.0f, 5.0f),
			                     NxMath::rand(-5.0f, 5.0f),
			                     NxMath::rand(-5.0f, 5.0f) );

      mCloth->setWindAcceleration( windVec );

      // Wake the cloth!
      mCloth->wakeUp();
   }
   else
      mCloth->setWindAcceleration( NxVec3( 0, 0, 0 ) );

   // Update bounds.
   if ( mWorld->getEnabled() )
   {
      NxBounds3 box;
      mCloth->getWorldBounds( box ); 

      Point3F min = pxCast<Point3F>( box.min );
      Point3F max = pxCast<Point3F>( box.max );

      mWorldBox.set( min, max );
      mObjBox = mWorldBox;

      getWorldTransform().mul( mObjBox );
   }
   else
   {
      mObjBox.set(   0, mThickness * -0.5f, 0, 
                     mPatchSize.x, mThickness * 0.5f, mPatchSize.y );
   }

   resetWorldBox();

   // Update the VB on the next render.
   mIsVBDirty = true;
}
Пример #19
0
void World::
reset()
{
	btCollisionObjectArray a = dynamicsWorld->getCollisionObjectArray();
	for (int i = 0; i < a.size(); i++) {
		auto o = a[i];
		if (!o->isStaticOrKinematicObject()) {
			std::cout << "Object: " << o->getUserPointer() << std::endl;

			btTransform t = o->getWorldTransform();
			btVector3 v = t.getOrigin();

			if (v.getY() < -10) {

				std::shared_ptr<app::gl::AppObject> new_object;

				dynamicsWorld->removeCollisionObject(o);
				for (auto i = objects.begin(); i != objects.end(); ++i) {
					if (i->get() == o->getUserPointer()) {
						new_object = std::make_shared<app::gl::AppObject>(*(i->get()));
						v.setX(disx(gen));
						v.setY(disy(gen));
						v.setZ(disz(gen));
						t.setOrigin(v);
						new_object->setWorldTransform(t);
						objects.erase(i);
						break;
					}
				}
				addToWorld(new_object,
						btRigidBody::btRigidBodyConstructionInfo(new_object->getMass(),
								nullptr, nullptr, new_object->getInitialInertia()));
			} else {

				v.setX(disx(gen));
				v.setY(disy(gen));
				v.setZ(disz(gen));
				t.setOrigin(v);
				o->setWorldTransform(t);
				o->setInterpolationLinearVelocity(btVector3(0,0,0));
				o->setInterpolationAngularVelocity(btVector3(0,0,0));
				o->setActivationState(1);
				o->activate(true);
			}

		}
	}
}
Пример #20
0
bool TreentNode::deepMouseUp( ci::app::MouseEvent &event )
{
  bool captured = false;
  auto gui_component = component<GuiComponent>();
  if( gui_component )
    captured = gui_component->mouseUp( event, getWorldTransform() );

  for( TreentNodeRef &child : mChildren )
  { // stop evaluation if event was captured by self or a child
    if( captured )
      break;

    captured = child->deepMouseUp( event );
  }
  return captured;
}
Пример #21
0
void RectShape::DrawSelf(Renderer *r)
{
    auto sh = static_cast<PrimitiveShader_PC*>(getShader());
    r->Use(sh);
    auto const &an = getAnchor();
    auto const &pos = getPosition();
    auto const &sz = getSize();
    Vec2 arrs[4];
    arrs[0] = Vec2(pos.x - sz.x*an.x, pos.y - sz.y*an.y);
    arrs[1] = Vec2(arrs[0].x+sz.x, arrs[0].y);
    arrs[2] = Vec2(arrs[0].x, arrs[0].y+sz.y);
    arrs[3] = Vec2(arrs[0].x+sz.x, arrs[0].y+sz.y);
    sh->pushColor(getColor());
    sh->drawTriangleStrip(getWorldTransform(), &arrs[0], 4);
    sh->popColor();
}
Пример #22
0
bool SceneObject::containsPoint( const Point3F& point )
{
   // If it's not in the AABB, then it can't be in the OBB either,
   // so early out.

   if( !mWorldBox.isContained( point ) )
      return false;

   // Transform point into object space and test it against
   // our object space bounding box.

   Point3F objPoint( 0, 0, 0 );
   getWorldTransform().mulP( point, &objPoint );
   objPoint.convolveInverse( getScale() );

   return ( mObjBox.isContained( objPoint ) );
}
Пример #23
0
void BodyNode::addContactForce(const Eigen::Vector3d& _force,
                               const Eigen::Vector3d& _offset,
                               bool _isOffsetLocal, bool _isForceLocal) {
  Eigen::Isometry3d T = Eigen::Isometry3d::Identity();
  Eigen::Vector6d F = Eigen::Vector6d::Zero();

  if (_isOffsetLocal)
    T.translation() = _offset;
  else
    T.translation() = getWorldTransform().inverse() * _offset;

  if (_isForceLocal)
    F.tail<3>() = _force;
  else
    F.tail<3>() = mW.linear().transpose() * _force;

  mContactForces.push_back(math::dAdInvT(T, F));
}
Пример #24
0
void SE_NewGeometry::updateWorldTransform()
{
    SE_Spatial::updateWorldTransform();
    SE_Matrix4f localM;
    localM.set(getLocalRotate().toMatrix3f(), getLocalScale(), getLocalTranslate());
    mWorldTransform = getPrevMatrix().mul(localM).mul(getPostMatrix());
    SE_NewGeometry::_Impl::SimObjectList::iterator it;
    for(it = mImpl->attachObject.begin() ; it != mImpl->attachObject.end() ; it++)
    {
        (*it)->doTransform(getWorldTransform());
    }
    std::list<SE_Spatial*>::iterator itchild = mImplchild->children.begin();
    for(; itchild != mImplchild->children.end() ; itchild++)
    {
        SE_Spatial* s = *itchild;
        s->updateWorldTransform();
    }
}
Пример #25
0
void
PhysicsBodyComponent::_buildRigibody() noexcept
{
	_body->close();

	auto collisionShape = this->getComponent<PhysicsShapeComponent>();
	if (!collisionShape)
		return;

	auto shape = collisionShape->getCollisionShape();
	if (!shape)
		return;

	auto gameObject = this->getGameObject();

	_body->setLayer(gameObject->getLayer());
	_body->setWorldTransform(gameObject->getWorldTransform());
	_body->setup(shape);
}
Пример #26
0
void ObjectRenderer::renderCutsceneObject(CutsceneObject* cutscene,
                                          RenderList& outList) {
    if (!m_world->state->currentCutscene) return;
    const auto& clump = cutscene->getClump();

    auto cutsceneOffset = m_world->state->currentCutscene->meta.sceneOffset +
                          glm::vec3(0.f, 0.f, 1.f);
    glm::mat4 cutscenespace;

    cutscenespace = glm::translate(cutscenespace, cutsceneOffset);
    if (cutscene->getParentActor()) {
        auto parent = cutscene->getParentFrame();
        cutscenespace *= parent->getWorldTransform();
        cutscenespace =
            glm::rotate(cutscenespace, glm::half_pi<float>(), {0.f, 1.f, 0.f});
    }

    renderClump(clump.get(), cutscenespace, nullptr, outList);
}
Пример #27
0
//==============================================================================
void EndEffector::updateWorldJacobianClassicDeriv() const
{
  const math::Jacobian& dJ_parent = mBodyNode->getJacobianClassicDeriv();
  const math::Jacobian& J_parent = mBodyNode->getWorldJacobian();

  const Eigen::Vector3d& v_local =
      getLinearVelocity(mBodyNode, Frame::World());

  const Eigen::Vector3d& w_parent = mBodyNode->getAngularVelocity();
  const Eigen::Vector3d& p = (getWorldTransform().translation()
                  - mBodyNode->getWorldTransform().translation()).eval();

  mWorldJacobianClassicDeriv = dJ_parent;
  mWorldJacobianClassicDeriv.bottomRows<3>().noalias() +=
      J_parent.topRows<3>().colwise().cross(v_local + w_parent.cross(p))
      + dJ_parent.topRows<3>().colwise().cross(p);

  mIsWorldJacobianClassicDerivDirty = false;
}
Пример #28
0
void	btRigidBody::internalWritebackVelocity(btScalar timeStep)
{
    (void) timeStep;
	if (m_inverseMass)
	{
		setLinearVelocity(getLinearVelocity()+ m_deltaLinearVelocity);
		setAngularVelocity(getAngularVelocity()+m_deltaAngularVelocity);
		
		//correct the position/orientation based on push/turn recovery
		btTransform newTransform;
		btTransformUtil::integrateTransform(getWorldTransform(),m_pushVelocity,m_turnVelocity,timeStep,newTransform);
		setWorldTransform(newTransform);
		//m_originalBody->setCompanionId(-1);
	}
//	m_deltaLinearVelocity.setZero();
//	m_deltaAngularVelocity .setZero();
//	m_pushVelocity.setZero();
//	m_turnVelocity.setZero();
}
Пример #29
0
void BulletRigidBody::setWorldTransform(const btTransform &centerOfMassWorldTrans) {
    Transform* trans = owner_object()->transform();
    btTransform aux; getWorldTransform(aux);

    if(std::abs(aux.getOrigin().getX() - prevPos.getOrigin().getX()) >= 0.1f ||
       std::abs(aux.getOrigin().getY() - prevPos.getOrigin().getY()) >= 0.1f ||
       std::abs(aux.getOrigin().getZ() - prevPos.getOrigin().getZ()) >= 0.1f)
    {
        mRigidBody->setWorldTransform(aux);
        prevPos = aux;
        //TODO: incomplete solution
    }
    else
    {
        btTransform physicBody = (centerOfMassWorldTrans  * m_centerOfMassOffset);
        convertBtTransform2Transform(physicBody, trans);
        prevPos = physicBody;
    }
    //convertBtTransform2Transform(centerOfMassWorldTrans * m_centerOfMassOffset, trans);
}
Пример #30
0
	void Player::onDraw(sf::RenderTarget& target, sf::RenderStates states) const
	{
		states.transform *= getWorldTransform();
		//sf::CircleShape shape(mRadius);
		//shape.setOrigin(mRadius, mRadius);
		//shape.setFillColor(sf::Color::Blue);
		//target.draw(shape, states);

		states.transform *= getWorld().getPixelToWorldTransform();
		target.draw(*mpSpriteRenderer, states);

		// Draw collider
		//b2AABB aabb = mpFixture->GetAABB(0);
		//sf::RectangleShape rectShape(sf::Vector2f(aabb.GetExtents().x * 2, aabb.GetExtents().y * 2));
		//rectShape.setOrigin(rectShape.getSize().x / 2.f, rectShape.getSize().y / 2.f);
		//sf::Color color = sf::Color::Red;
		//color.a = 128;
		//rectShape.setFillColor(color);

		//target.draw(rectShape, states);
	}