示例#1
0
CC3Matrix* CC3Camera::getProjectionMatrix()
{
    buildProjection();
    return _hasInfiniteDepthOfField
           ? _frustum->getInfiniteProjectionMatrix()
           : _frustum->getFiniteProjectionMatrix();
}
示例#2
0
//follow the player around by changing to follow them
//offset remains the same unless changed
void Camera::update()
{
	if (bFollowPlayer)
	{
		mTarget = gPlayer->getPosition();
	}
	buildView();
	buildProjection();
}
示例#3
0
void Camera::init(D3DXVECTOR3 _offset, D3DXVECTOR3 _target)
{
	mOffset = _offset;
	mTarget = _target;
	bFollowPlayer = true;
	mOffsetAngle = 0.0f;
	buildView();
	buildProjection();
}
示例#4
0
bool PhotoCamera::initializeFromMeshLab(QDomElement &element)
{
    QStringList attTemp;
    //Get Translation
    attTemp = element.attribute("TranslationVector").split(" ");
    Eigen::Vector4f translation;
    for(int i = 0; i < attTemp.count(); i++){
        translation(i) = attTemp[i].toFloat();
    }
    translationMatrix.translation() = translation.head(3);
    //translationMatrix.col(3) = translation;

    //Get Center;
    attTemp = element.attribute("CenterPx").split(" ");
    principalPoint << attTemp.at(0).toFloat(), attTemp.at(1).toFloat();


    //Get RotationMatrix;
    attTemp = element.attribute("RotationMatrix").split(" ");
    for(int i = 0; i < 4; i++){
        for(int j = 0; j < 4; j++){
            rotationMatrix(i, j) = attTemp[i*4 + j].toFloat();
        }
    }

    //Get Viewport;
    attTemp = element.attribute("ViewportPx").split(" ");
    viewport << attTemp.at(0).toFloat(), attTemp.at(1).toFloat();

    //Lens Distortion;
    attTemp = element.attribute("LensDistortion").split(" ");
    distortion << attTemp.at(0).toFloat(), attTemp.at(1).toFloat();
    //std::cout << distortion.transpose() << std::endl;

    //PixelSize;
    attTemp = element.attribute("PixelSizeMm").split(" ");
    pixelSize << attTemp.at(0).toFloat(), attTemp.at(1).toFloat();
    oneOverDx           = 1/pixelSize(0);
    oneOverDy           = 1/pixelSize(1);
    //std::cout << pixelSize.transpose() << std::endl;

    //Focal
    focalLength = element.attribute("FocalMm").toFloat();

    buildExtrinsic();
    buildIntrinsic();
    buildProjection();

//    cameraCenter = center(intrinsicMatrix.topLeftCorner(3,4)*extrinsicMatrix.matrix());
    cameraCenter = center(intrinsicMatrix.matrix().topLeftCorner(3,4)*extrinsicMatrix.matrix());
    return true;
}
示例#5
0
CC3Ray CC3Camera::unprojectPoint( const CCPoint& cc2Point )
{
    // Scale from UI points to GL points
    CCPoint glPoint = ccpMult(cc2Point, CCDirector::sharedDirector()->getContentScaleFactor());

    // Express the glPoint X & Y as proportion of the viewport dimensions.
    CC3Viewport vp = getViewport();
    GLfloat xp = ((2.0f * glPoint.x) / vp.w) - 1;
    GLfloat yp = ((2.0f * glPoint.y) / vp.h) - 1;

    // Ensure that the camera's frustum is up to date, and then map the proportional point
    // on the viewport to its position on the near clipping rectangle. The Z-coordinate is
    // negative because the camera points down the negative Z axis in its local coordinates.
    buildProjection();
    CC3Vector pointLocNear = cc3v(_frustum->getRight() * xp, _frustum->getTop() * yp, -_frustum->getNear());

    CC3Ray ray;
    if ( isUsingParallelProjection() )
    {
        // The location on the near clipping plane is relative to the camera's
        // local coordinates. Convert it to global coordinates before returning.
        // The ray direction is straight out from that global location in the
        // camera's globalForwardDirection.
        ray.startLocation =  getGlobalTransformMatrix()->transformLocation( pointLocNear );
        ray.direction = getGlobalForwardDirection();
    }
    else
    {
        // The location on the near clipping plane is relative to the camera's local
        // coordinates. Since the camera's origin is zero in its local coordinates,
        // this point on the near clipping plane forms a directional vector from the
        // camera's origin. Rotate this directional vector with the camera's rotation
        // matrix to convert it to a global direction vector in global coordinates.
        // Thanks to Cocos3D forum user Rogs for suggesting the use of the globalRotationMatrix.
        ray.startLocation = getGlobalLocation();
        ray.direction = getGlobalRotationMatrix()->transformDirection( pointLocNear );
    }

    // Ensure the direction component is normalized before returning.
    ray.direction = ray.direction.normalize();

    //LogTrace(@"%@ unprojecting point %@ to near plane location %@ and to ray starting at %@ and pointing towards %@",
    //			  [self class], NSStringFromCGPoint(glPoint), NSStringFromCC3Vector(pointLocNear),
    //			  NSStringFromCC3Vector(ray.startLocation), NSStringFromCC3Vector(ray.direction));

    return ray;
}
示例#6
0
/**
 * Returns the camera's FOV in terms of ratios of the near clip bounds
 * (width & height) to the near clip distance.
 */
CCSize CC3Camera::getFovRatios()
{
    buildProjection();

    /// TODO: get device orientation
    const int orientation = CC3UIInterfaceOrientationLandscapeLeft;

    switch(/*CCDirector.sharedDirector.getDeviceOrientation*/ orientation)
    {
    case CC3UIInterfaceOrientationLandscapeLeft:
    case CC3UIInterfaceOrientationLandscapeRight:
        return CCSizeMake(_frustum->getTop() / _frustum->getNear(), _frustum->getRight() / _frustum->getNear());
    case CC3UIInterfaceOrientationPortrait:
    case CC3UIInterfaceOrientationPortraitUpsideDown:
    default:
        return CCSizeMake(_frustum->getRight() / _frustum->getNear(), _frustum->getTop() / _frustum->getNear());
    }
}
示例#7
0
CC3Frustum* CC3Camera::getFrustum()
{
    buildProjection();
    return _frustum;
}