Exemplo n.º 1
0
 void PlanetFilter::initRenderOp() {    
     mRenderOp.operationType = RenderOperation::OT_TRIANGLE_STRIP;
     mRenderOp.useIndexes = FALSE;
     mRenderOp.vertexData = new VertexData();
     
     setBoundingBox(AxisAlignedBox(Vector3(-getBoundingRadius()), Vector3(getBoundingRadius())));
 }
Exemplo n.º 2
0
	//-----------------------------------------------------------------------
	void MovableObject::_notifyCurrentCamera(Camera* cam)
	{
		if (mParentNode)
		{
			if (cam->getUseRenderingDistance() && mUpperDistance > 0)
			{
				Real rad = getBoundingRadius();
				Real squaredDepth = mParentNode->getSquaredViewDepth(cam->getLodCamera());
				// Max distance to still render
				Real maxDist = mUpperDistance + rad;
				if (squaredDepth > Math::Sqr(maxDist))
				{
					mBeyondFarDistance = true;
				}
				else
				{
					mBeyondFarDistance = false;
				}
			}
			else
			{
				mBeyondFarDistance = false;
			}
		}

        mRenderingDisabled = mListener && !mListener->objectRendering(this, cam);
	}
Exemplo n.º 3
0
    //-----------------------------------------------------------------------
	const Sphere& MovableObject::getWorldBoundingSphere(bool derive) const
	{
		if (derive)
		{
			mWorldBoundingSphere.setRadius(getBoundingRadius());
			mWorldBoundingSphere.setCenter(mParentNode->_getDerivedPosition());
		}
		return mWorldBoundingSphere;
	}
Exemplo n.º 4
0
const Sphere& RenderTransformElement::getWorldBoundingSphere( bool derive /*= false*/ ) const
{
	if (derive)
	{
		const Vector3& scl = m_parentNode->_getDerivedScale();
		scalar factor = Math::Max(Math::Max(scl.x, scl.y), scl.z);
		mWorldBoundingSphere.setRadius(getBoundingRadius() * factor);
		mWorldBoundingSphere.setCenter(m_parentNode->_getDerivedPosition());
	}
	return mWorldBoundingSphere;
}
    //-----------------------------------------------------------------------
	const Sphere& MovableObject::getWorldBoundingSphere(bool derive) const
	{
		if (derive)
		{
			const Vector3& scl = mParentNode->_getDerivedScale();
			Real factor = std::max(std::max(scl.x, scl.y), scl.z);
			mWorldBoundingSphere.setRadius(getBoundingRadius() * factor);
			mWorldBoundingSphere.setCenter(mParentNode->_getDerivedPosition());
		}
		return mWorldBoundingSphere;
	}
Exemplo n.º 6
0
AvatarSharedPointer AvatarManager::addAvatar(const QUuid& sessionUUID, const QWeakPointer<Node>& mixerWeakPointer) {
    AvatarSharedPointer avatar = AvatarHashMap::addAvatar(sessionUUID, mixerWeakPointer);
    const auto otherAvatar = std::static_pointer_cast<OtherAvatar>(avatar);
    if (otherAvatar && _space) {
        std::unique_lock<std::mutex> lock(_spaceLock);
        auto spaceIndex = _space->allocateID();
        otherAvatar->setSpaceIndex(spaceIndex);
        workload::Sphere sphere(otherAvatar->getWorldPosition(), otherAvatar->getBoundingRadius());
        workload::Transaction transaction;
        SpatiallyNestablePointer nestable = std::static_pointer_cast<SpatiallyNestable>(otherAvatar);
        transaction.reset(spaceIndex, sphere, workload::Owner(nestable));
        _space->enqueueTransaction(transaction);
    }
    return avatar;
}
Exemplo n.º 7
0
    //-----------------------------------------------------------------------
    bool InstancedEntity::findVisible( Camera *camera ) const
    {
        //Object is active
        bool retVal = isInScene();
        if (retVal)
        {
            //check object is explicitly visible
            retVal = isVisible();

            //Object's bounding box is viewed by the camera
            if( retVal && camera )
                retVal = camera->isVisible(Sphere(_getDerivedPosition(),getBoundingRadius()));
        }

        return retVal;
    }
	//-----------------------------------------------------------------------
	void MovableObject::_notifyCurrentCamera(Camera* cam)
	{
		if (mParentNode)
		{
			if (cam->getUseRenderingDistance() && mUpperDistance > 0)
			{
				Real rad = getBoundingRadius();
				Real squaredDepth = mParentNode->getSquaredViewDepth(cam->getLodCamera());

				const Vector3& scl = mParentNode->_getDerivedScale();
				Real factor = std::max(std::max(scl.x, scl.y), scl.z);

				// Max distance to still render
				Real maxDist = mUpperDistance + rad * factor;
				if (squaredDepth > Math::Sqr(maxDist))
				{
					mBeyondFarDistance = true;
				}
				else
				{
					mBeyondFarDistance = false;
				}
			}
			else
			{
				mBeyondFarDistance = false;
			}

            // Construct event object
            MovableObjectLodChangedEvent evt;
            evt.movableObject = this;
            evt.camera = cam;

            // Notify lod event listeners
            cam->getSceneManager()->_notifyMovableObjectLodChanged(evt);

		}

        mRenderingDisabled = mListener && !mListener->objectRendering(this, cam);
	}
Exemplo n.º 9
0
	//-----------------------------------------------------------------------
	void MovableObject::_notifyCurrentCamera(Camera* cam)
	{
		if (mParentNode)
		{
			mBeyondFarDistance = false;

			if (cam->getUseRenderingDistance() && mUpperDistance > 0)
			{
				Real rad = getBoundingRadius();
				Real squaredDepth = mParentNode->getSquaredViewDepth(cam->getLodCamera());

				const Vector3& scl = mParentNode->_getDerivedScale();
				Real factor = std::max(std::max(scl.x, scl.y), scl.z);

				// Max distance to still render
				Real maxDist = mUpperDistance + rad * factor;
				if (squaredDepth > Math::Sqr(maxDist))
				{
					mBeyondFarDistance = true;
				}
			}

			if (!mBeyondFarDistance && cam->getUseMinPixelSize() && mMinPixelSize > 0)
			{

				Real pixelRatio = cam->getPixelDisplayRatio();
				
				//if ratio is relative to distance than the distance at which the object should be displayed
				//is the size of the radius divided by the ratio
				//get the size of the entity in the world
				Ogre::Vector3 objBound = getBoundingBox().getSize() * 
							getParentNode()->_getDerivedScale();
				
				//We object are projected from 3 dimensions to 2. The shortest displayed dimension of 
				//as object will always be at most the second largest dimension of the 3 dimensional
				//bounding box.
				//The square calculation come both to get rid of minus sign and for improve speed
				//in the final calculation
				objBound.x = Math::Sqr(objBound.x);
				objBound.y = Math::Sqr(objBound.y);
				objBound.z = Math::Sqr(objBound.z);
				float sqrObjMedianSize = std::max(std::max(
									std::min(objBound.x,objBound.y),
									std::min(objBound.x,objBound.z)),
									std::min(objBound.y,objBound.z));

				//If we have a perspective camera calculations are done relative to distance
				Real sqrDistance = 1;
				if (cam->getProjectionType() == PT_PERSPECTIVE)
				{
					sqrDistance = mParentNode->getSquaredViewDepth(cam->getLodCamera());
				}

				//Final Calculation to tell whether the object is to small
				mBeyondFarDistance =  sqrObjMedianSize < 
							sqrDistance * Math::Sqr(pixelRatio * mMinPixelSize); 
			}
			
            // Construct event object
            MovableObjectLodChangedEvent evt;
            evt.movableObject = this;
            evt.camera = cam;

            // Notify LOD event listeners
            cam->getSceneManager()->_notifyMovableObjectLodChanged(evt);

		}

        mRenderingDisabled = mListener && !mListener->objectRendering(this, cam);
	}
Exemplo n.º 10
0
    //-----------------------------------------------------------------------
    void InstanceBatch::_notifyCurrentCamera( Camera* cam )
    {
        mCurrentCamera = cam;

        //See DistanceLodStrategy::getValueImpl()
        //We use our own because our SceneNode is just filled with zeroes, and updating it
        //with real values is expensive, plus we would need to make sure it doesn't get to
        //the shader
		Real depth = Math::Sqrt(getSquaredViewDepth(cam)) - getBoundingRadius();          
        depth = std::max( depth, Real(0) );

        Real lodValue = depth * cam->_getLodBiasInverse();

        //Now calculate Material LOD
        /*const LodStrategy *materialStrategy = m_material->getLodStrategy();
        
        //Calculate LOD value for given strategy
        Real lodValue = materialStrategy->getValue( this, cam );*/

        //Get the index at this depth
        unsigned short idx = mMaterial->getLodIndex( lodValue );

        //TODO: Replace subEntity for MovableObject
        // Construct event object
        /*EntityMaterialLodChangedEvent subEntEvt;
        subEntEvt.subEntity = this;
        subEntEvt.camera = cam;
        subEntEvt.lodValue = lodValue;
        subEntEvt.previousLodIndex = m_materialLodIndex;
        subEntEvt.newLodIndex = idx;

        //Notify LOD event listeners
        cam->getSceneManager()->_notifyEntityMaterialLodChanged(subEntEvt);*/

        // Change LOD index
        mMaterialLodIndex = idx;

        mBeyondFarDistance = false;

        if (cam->getUseRenderingDistance() && mUpperDistance > 0)
        {
            if (depth > mUpperDistance)
                mBeyondFarDistance = true;
        }

        if (!mBeyondFarDistance && cam->getUseMinPixelSize() && mMinPixelSize > 0)
        {
            Real pixelRatio = cam->getPixelDisplayRatio();

            Ogre::Vector3 objBound =
                getBoundingBox().getSize() * getParentNode()->_getDerivedScale();
            objBound.x = Math::Sqr(objBound.x);
            objBound.y = Math::Sqr(objBound.y);
            objBound.z = Math::Sqr(objBound.z);
            float sqrObjMedianSize = std::max(
                std::max(std::min(objBound.x, objBound.y), std::min(objBound.x, objBound.z)),
                std::min(objBound.y, objBound.z));

            // If we have a perspective camera calculations are done relative to distance
            Real sqrDistance = 1;

            if (cam->getProjectionType() == PT_PERSPECTIVE)
                sqrDistance = getSquaredViewDepth(cam->getLodCamera()); // it's ok

            mBeyondFarDistance =
                sqrObjMedianSize < sqrDistance * Math::Sqr(pixelRatio * mMinPixelSize);
        }

        if (mParentNode)
        {
            MovableObjectLodChangedEvent evt;
            evt.movableObject = this;
            evt.camera = cam;

            cam->getSceneManager()->_notifyMovableObjectLodChanged(evt);
        }

        mRenderingDisabled = mListener && !mListener->objectRendering(this, cam);

        // MovableObject::_notifyCurrentCamera( cam ); // it does not suit
    }