void Camera::initialize() { Vector3d goalPos = getGoalPosition(); Quaternion goalOrient = getGoalOrientation(); mSceneNode->setPosition(toOgre(goalPos, mScene->getOffset())); mSceneNode->setOrientation(toOgre(goalOrient)); setMode(FirstPerson); }
void Camera::tick(const Time& t, const Duration& dt) { if (!haveGoal()) return; Vector3d goalPos = getGoalPosition(); Quaternion goalOrient = getGoalOrientation(); Vector3d pos; Quaternion orient; if (mMode == FirstPerson) { // In first person mode we are tied tightly to the position of // the object. pos = goalPos; orient = goalOrient; } else { // In third person mode, the target is offset so we'll be behind and // above ourselves and we need to interpolate to the target. // Offset the goal. BoundingSphere3f following_bounds = getGoalBounds(); goalPos += Vector3d(following_bounds.center()); // > 1 factor gets us beyond the top of the object goalPos += mOffset * (following_bounds.radius()); // Restore the current values from the scene node. pos = fromOgre(mSceneNode->getPosition(), mScene->getOffset()); orient = fromOgre(mSceneNode->getOrientation()); // And interpolate. Vector3d toGoal = goalPos-pos; double toGoalLen = toGoal.length(); if (toGoalLen < 1e-06) { pos = goalPos; orient = goalOrient; } else { double step = exp(-dt.seconds()*2.f); pos = goalPos - (toGoal/toGoalLen)*(toGoalLen*step); orient = (goalOrient*(1.f-step) + orient*step).normal(); } } mSceneNode->setPosition(toOgre(pos, mScene->getOffset())); mSceneNode->setOrientation(toOgre(orient)); }
void GfxNode::doUpdateWorldTransform (void) { if (par.isNull()) { worldTransform = Transform(localPos, localOrientation, localScale); } else { GfxFertileNode *fertile_node = static_cast<GfxFertileNode*>(&*par); fertile_node->updateWorldTransform(); Transform parentTransform; if (parentBoneId < 0) { parentTransform = fertile_node->getWorldTransform(); } else { GfxBody *pbody = static_cast<GfxBody*>(fertile_node); parentTransform = pbody->getBoneWorldTransform(parentBoneId); } worldTransform = parentTransform * Transform(localPos, localOrientation, localScale); } node->overrideCachedTransform(toOgre()); //dirtyWorldTransform = false; }
void Camera::onSetTarget(const GameHandle& target) { //! \hack const offset for camera v3 offset(0.0f, 3.0f, -14); Ogre::SceneManager* sceneMgr = Ogre::Root::getSingleton().getSceneManager(BFG_SCENEMANAGER); if (!sceneMgr->hasSceneNode(stringify(target))) { errlog << "Target (" << stringify(target) << ") for camera (" << mHandle << ") does not exist!"; return; } Ogre::SceneNode* newParent = sceneMgr->getSceneNode(stringify(target)); Ogre::SceneNode* oldParent = mCameraNode->getParentSceneNode(); oldParent->removeChild(mCameraNode); newParent->addChild(mCameraNode); mCameraNode->setPosition(toOgre(offset)); }
void Entity::setOgrePosition(const Vector3d &pos) { Ogre::Vector3 ogrepos = toOgre(pos, getScene()->getOffset()); const Ogre::Vector3 &scale = mSceneNode->getScale(); mSceneNode->setPosition(ogrepos); }
Camera::Camera(Event::Lane& lane, GameHandle cameraHandle, Ogre::SceneNode* camNode, Ogre::RenderTarget* renderTarget, u32 width, u32 height, const v3& position, const qv4& orientation, GameHandle parent) : mSubLane(lane.createSubLane()), mCameraNode(camNode), mRenderTarget(renderTarget), mHandle(cameraHandle), mNodeCreated(false), mRenderTargetCreated(false) { Ogre::SceneManager* sceneMgr = Ogre::Root::getSingleton().getSceneManager(BFG_SCENEMANAGER); if (mCameraNode == NULL) // Create SceneNode { if (sceneMgr->hasSceneNode(stringify(mHandle))) { mCameraNode = sceneMgr->getSceneNode(stringify(mHandle)); } else { mCameraNode = sceneMgr->getRootSceneNode()->createChildSceneNode(stringify(mHandle)); mNodeCreated = true; } } mCameraNode->setOrientation(toOgre(orientation)); mCameraNode->setPosition(toOgre(position)); v3 target = toBFG(mCameraNode->getOrientation().zAxis()); norm(target); Ogre::Camera* cam; cam = sceneMgr->createCamera(stringify(mHandle)); cam->setFOVy(Ogre::Degree(60.0f)); cam->setNearClipDistance(0.1f); cam->setFarClipDistance(250000.0f); cam->lookAt(toOgre(target)*10); mCameraNode->attachObject(cam); infolog << "Camera: " << stringify(mHandle) << " created."; if (mRenderTarget == NULL) { // Create renderToTexture RenderTarget if (width == 0 || height == 0) { throw std::logic_error("Too few information to create a render target."); } cam->setAspectRatio((f32)width / (f32)height); Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().createManual ( stringify(mHandle), Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, width, height, 0, Ogre::PF_R8G8B8, Ogre::TU_RENDERTARGET ); mRenderTarget = texture->getBuffer()->getRenderTarget(); prepareRenderTarget(); mRenderTarget->addViewport(cam); mRenderTarget->getViewport(0)->setClearEveryFrame(true); mRenderTarget->getViewport(0)->setBackgroundColour(Ogre::ColourValue::Black); mRenderTarget->getViewport(0)->setOverlaysEnabled(false); Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName(stringify(mHandle)); if (mat.isNull()) { mat = Ogre::MaterialManager::getSingleton().create( stringify(mHandle), Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); } Ogre::Technique* tech = mat->getTechnique(0); if (!tech) { tech = mat->createTechnique(); } Ogre::Pass* pass = tech->getPass(0); if (!pass) { pass = tech->createPass(); } pass->setLightingEnabled(false); if (pass->getNumTextureUnitStates() > 0) { Ogre::TextureUnitState* txState = NULL; txState = pass->getTextureUnitState(0); txState->setTextureName(stringify(mHandle)); } else { pass->createTextureUnitState(stringify(mHandle)); } mRenderTarget->setAutoUpdated(true); mRenderTargetCreated = true; infolog << "Rendertarget: " << stringify(mHandle) << " created."; } else { prepareRenderTarget(); f32 width = static_cast<f32>(mRenderTarget->getWidth()); f32 height = static_cast<f32>(mRenderTarget->getHeight()); cam->setAspectRatio(width / height); mRenderTarget->addViewport(cam); } // mSubLane->connect(ID::VE_UPDATE_POSITION, this, &Camera::updatePosition, mHandle); // mSubLane->connect(ID::VE_UPDATE_ORIENTATION, this, &Camera::updateOrientation, mHandle); mSubLane->connect(ID::VE_SET_CAMERA_TARGET, this, &Camera::onSetTarget, mHandle); if (parent != NULL_HANDLE) { onSetTarget(parent); } }
void Camera::updateOrientation(const qv4& ori) { mCameraNode->setOrientation(toOgre(ori)); }
void Camera::updatePosition(const v3& pos) { mCameraNode->setPosition(toOgre(pos)); }
const Ogre::Vector3 PhysicsActor::world_position() { return toOgre(rigid_body_->getCenterOfMassPosition()); }
Ogre::Vector3 PhysicsActor::position() { return toOgre(position_); }
Ogre::Matrix4 PhysicsActor::transform() { return toOgre(rigid_body_->getCenterOfMassTransform()); }
Ogre::AxisAlignedBox PhysicsActor::world_bounding_box() { btVector3 aabbMin, aabbMax; rigid_body_->getAabb(aabbMin, aabbMax); Ogre::AxisAlignedBox bounding_box(toOgre(aabbMin), toOgre(aabbMax)); return bounding_box; }
Ogre::Vector3 PhysicsActor::angular_velocity() { return toOgre(rigid_body_->getAngularVelocity()); }
Ogre::Vector3 PhysicsActor::linear_velocity() { return toOgre(rigid_body_->getLinearVelocity()); }
void Entity::setOgreOrientation(const Quaternion &orient) { mSceneNode->setOrientation(toOgre(orient)); }
void setScale(const Vector3f &scale) { mSceneNode->setScale(toOgre(scale)); }
Ogre::Quaternion PhysicsActor::orientation() { return toOgre(orientation_); }