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); } }
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; }
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 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}); }
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()); }
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); } }
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; }
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; }
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_)); }
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; }
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; }
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; }
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)); } } }
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(); //} }
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); } }
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; }
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); } } } }
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; }
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(); }
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 ) ); }
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)); }
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(); } }
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); }
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); }
//============================================================================== 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; }
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(); }
void BulletRigidBody::setWorldTransform(const btTransform ¢erOfMassWorldTrans) { 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); }
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); }