示例#1
0
Ogre::AxisAlignedBox EditSphere::aab(double scale) const
{
    Ogre::Sphere sp = scaleSphere(m_sp, scale);
    Ogre::AxisAlignedBox aabb(sp.getCenter().x-((int)sp.getRadius()+1), sp.getCenter().y-((int)sp.getRadius()+1), sp.getCenter().z-((int)sp.getRadius()+1),
                        sp.getCenter().x+((int)sp.getRadius()+1), sp.getCenter().y+((int)sp.getRadius()+1), sp.getCenter().z+((int)sp.getRadius()+1));
    return aabb;
}
示例#2
0
Ogre::Sphere EditSphere::scaleSphere(const Ogre::Sphere _sp, const double scale)
{
    Ogre::Sphere sp = _sp;
    sp.setCenter(sp.getCenter()/scale);
    sp.setRadius(sp.getRadius()/scale);
    return sp;
}
示例#3
0
    //-----------------------------------------------------------------------
    bool Light::isInLightRange(const Ogre::Sphere& container) const
    {
        bool isIntersect = true;
        //directional light always intersects (check only spotlight and point)
        if (mLightType != LT_DIRECTIONAL)
        {
            //Check that the sphere is within the sphere of the light
            isIntersect = container.intersects(Sphere(mDerivedPosition, mRange));
            //If this is a spotlight, check that the sphere is within the cone of the spot light
            if ((isIntersect) && (mLightType == LT_SPOTLIGHT))
            {
                //check first check of the sphere surrounds the position of the light
                //(this covers the case where the center of the sphere is behind the position of the light
                // something which is not covered in the next test).
                isIntersect = container.intersects(mDerivedPosition);
                //if not test cones
                if (!isIntersect)
                {
                    //Calculate the cone that exists between the sphere and the center position of the light
                    Ogre::Vector3 lightSphereConeDirection = container.getCenter() - mDerivedPosition;
                    Ogre::Radian halfLightSphereConeAngle = Math::ASin(container.getRadius() / lightSphereConeDirection.length());

                    //Check that the light cone and the light-position-to-sphere cone intersect)
                    Radian angleBetweenConeDirections = lightSphereConeDirection.angleBetween(mDerivedDirection);
                    isIntersect = angleBetweenConeDirections <=  halfLightSphereConeAngle + mSpotOuter * 0.5;
                }
            }
        }
        return isIntersect;
    }
示例#4
0
void OrbitCamera( ::Ogre::Camera* a_pCam, const::Ogre::Sphere& a_subjSphr,
                  const Ogre::Vector2& a_curTouch, const Ogre::Vector2& a_oldTouch )
{
    const ::Ogre::Vector3& center = a_subjSphr.getCenter() ;
    const ::Ogre::Vector3& camPos = a_pCam->getPosition() ;
    
    // gets the current looked-at point.
    const ::Ogre::Vector3 camDir = a_pCam->getDirection().normalisedCopy() ;
    const ::Ogre::Vector3 lookAt = camDir.dotProduct(center - camPos) * camDir + camPos  ;
    
    // makes the ray from the subjet's center to the camera.
    const ::Ogre::Ray rayToCam( center, (camPos - center).normalisedCopy() ) ;
    
    // makes the tangent plane to the sphere whose normal is toward the camera.
    ::Ogre::Real fDist = center.distance( camPos ) ;
    if( a_subjSphr.getRadius() < fDist )
        fDist = a_subjSphr.getRadius() ;        
    const ::Ogre::Plane touchPlane( rayToCam.getDirection(), fDist ) ;
    
    // gets the touch points on the plane.
    ::Ogre::Ray ray ;
    a_pCam->getCameraToViewportRay( a_curTouch.x, a_curTouch.y, &ray ) ;
    const ::Ogre::Vector3 curPoint = ray.getPoint( ray.intersects( touchPlane ).second ) ;
    a_pCam->getCameraToViewportRay( a_oldTouch.x, a_oldTouch.y, &ray ) ;
    const ::Ogre::Vector3 oldPoint = ray.getPoint( ray.intersects( touchPlane ).second ) ;
    
    // gets the quaternion.
    const ::Ogre::Quaternion qtnn = (curPoint - center).getRotationTo( oldPoint - center ) ;
    
    // gets the new camera position.
    ::Ogre::Vector3 newCamPos = camPos - center ;
    newCamPos = qtnn * newCamPos ;
    newCamPos += center ;
    
    // gest the new look-at.
    ::Ogre::Vector3 newLookAt = lookAt - center ;
    newLookAt = qtnn * newLookAt ;
    newLookAt += center ;
    
    // sets the camera to the new properties.
    a_pCam->setPosition( newCamPos ) ;
    a_pCam->lookAt( newLookAt ) ;
}
示例#5
0
double EditSphere::calcVoxel(const Ogre::Vector3& pos, const double &scale)
{
    Ogre::Sphere sp = scaleSphere(m_sp, scale);
    double dist = sp.getRadius() - sp.getCenter().distance(pos);
    return dist;
}