コード例 #1
0
ファイル: mesh.cpp プロジェクト: UIKit0/nori
void Mesh::samplePosition(const Point2f &_sample, Point3f &p, Normal3f &n) const {
	Point2f sample(_sample);

	/* First, sample a triangle with respect to surface area */
	size_t index = m_distr.sampleReuse(sample.x());

	/* Lookup vertex positions for the chosen triangle */
	int i0 = m_indices[3*index],
		i1 = m_indices[3*index+1],
		i2 = m_indices[3*index+2];

	const Point3f
		&p0 = m_vertexPositions[i0],
		&p1 = m_vertexPositions[i1],
		&p2 = m_vertexPositions[i2];

	/* Sample a position in barycentric coordinates */
	Point2f b = squareToUniformTriangle(sample);
	
	p = p0 * (1.0f - b.x() - b.y()) + p1 * b.x() + p2 * b.y();

	/* Also provide a normal (interpolated if vertex normals are provided) */
	if (m_vertexNormals) {
		const Normal3f 
			&n0 = m_vertexNormals[i0],
			&n1 = m_vertexNormals[i1],
			&n2 = m_vertexNormals[i2];
		n = (n0 * (1.0f - b.x() - b.y()) + n1 * b.x() + n2 * b.y()).normalized();
	} else {
		n = (p1-p0).cross(p2-p0).normalized();
	}
}
コード例 #2
0
ファイル: microfacetBRDF.cpp プロジェクト: valdersoul/NoriV2
    /// Sample the BRDF
    Color3f sample(BSDFQueryRecord &bRec, const Point2f &sample) const {
        if (Frame::cosTheta(bRec.wi) <= 0)
            return Color3f(0.0f);
        bRec.measure = ESolidAngle;
        /* Warp a uniformly distributed sample on [0,1]^2
        to a direction on a cosine-weighted hemisphere */
        if (sample.x() < m_ks) {
            float x = sample.x()/m_ks;
            Vector3f n = Warp::squareToBeckmann(Point2f(x, sample.y()), m_alpha);
            bRec.wo = (2.0f * bRec.wi.dot(n) * n - bRec.wi );

        }
        else {
            float x = (sample.x() - m_ks) / (1.0f - m_ks);
            bRec.wo = Warp::squareToCosineHemisphere(Point2f(x,sample.y()));
        }
        if(Frame::cosTheta(bRec.wo) <= 0) {
            return Color3f(0.0f);
        }

        /* Relative index of refraction: no change */
        bRec.eta = 1.0f;
        float pdfVal = pdf(bRec);
        return (pdfVal != 0.0f) ? Color3f(eval(bRec) * Frame::cosTheta(bRec.wo) / pdfVal) : Color3f(0.0f);

    }
コード例 #3
0
ファイル: rect.cpp プロジェクト: bjandras/Newtown
bool Rect::contains(Point2f const & p) const
{
	float left = m_corner.x();
	float right = left + width();
	float bottom = m_corner.y();
	float top = bottom + height();

	return p.x() >= left && p.x() <= right && p.y() >= bottom && p.y() <= top;
}
コード例 #4
0
Point2d View::screenSizeInDisplayCoords(Point2f &frameSize)
{
    Point2d screenSize(0,0);
    if (frameSize.x() == 0.0 || frameSize.y() == 0.0)
        return screenSize;
    
    screenSize.x() = tan(fieldOfView/2.0) * heightAboveSurface() * 2.0;
    screenSize.y() = screenSize.x() / frameSize.x() * frameSize.y();
    
    return screenSize;
}
コード例 #5
0
Eigen::Matrix4d View::calcProjectionMatrix(Point2f frameBufferSize,float margin)
{
	float near=0,far=0;
	Point2d frustLL,frustUR;
	frustLL.x() = -imagePlaneSize * (1.0 + margin);
	frustUR.x() = imagePlaneSize * (1.0 + margin);
	double ratio =  ((double)frameBufferSize.y() / (double)frameBufferSize.x());
	frustLL.y() = -imagePlaneSize * ratio * (1.0 + margin);
	frustUR.y() = imagePlaneSize * ratio * (1.0 + margin);
	near = nearPlane;
	far = farPlane;
    
    
    // Borrowed from the "OpenGL ES 2.0 Programming" book
    Eigen::Matrix4d projMat;
    Point3d delta(frustUR.x()-frustLL.x(),frustUR.y()-frustLL.y(),far-near);
    projMat.setIdentity();
    projMat(0,0) = 2.0f * near / delta.x();
    projMat(1,0) = projMat(2,0) = projMat(3,0) = 0.0f;
    
    projMat(1,1) = 2.0f * near / delta.y();
    projMat(0,1) = projMat(2,1) = projMat(3,1) = 0.0f;
    
    projMat(0,2) = (frustUR.x()+frustLL.x()) / delta.x();
    projMat(1,2) = (frustUR.y()+frustLL.y()) / delta.y();
    projMat(2,2) = -(near + far ) / delta.z();
    projMat(3,2) = -1.0f;
    
    projMat(2,3) = -2.0f * near * far / delta.z();
    projMat(0,3) = projMat(1,3) = projMat(3,3) = 0.0f;
    
    return projMat;
}
コード例 #6
0
ファイル: polygon.cpp プロジェクト: bjandras/Newtown
void Polygon::buildQPolygon()
{
	int const n = numPoints();
	m_qpolygon = QPolygonF(n);

	for (int i = 0; i < n; ++i)
	{
		Point2f p = m_points[i];
		m_qpolygon[i] = QPointF(p.x(), p.y());
	}
}
コード例 #7
0
ファイル: warp.cpp プロジェクト: valdersoul/NoriV2
Vector3f Warp::squareToSchlick(const Point2f &sample, float k) {

    //use the inverse methode
    if(k == 0.0){
        return Warp::squareToUniformSphere(sample);
    }

    float cosTheta = ((k + 2.0f * sample.x() - 1.0f ) / ( k * (2.0f * sample.x() - 1.0f ) + 1.0f));
    float acostheta = acos(cosTheta);
    float phi = 2.0f * M_PI * sample.y();

    return Vector3f(sin(acostheta) * cos(phi), sin(acostheta) * sin(phi), cos(acostheta));
}
コード例 #8
0
ファイル: Perspective.cpp プロジェクト: FallenShard/vesper
    Spectrum PerspectiveSensor::sampleRay(Ray3f& ray, const Point2f& samplePosition, const Point2f& apertureSample) const
    {
        Point3f nearPoint = m_sampleToCamera * Point3f(
            samplePosition.x() * m_invImageSize.x(),
            samplePosition.y() * m_invImageSize.y(), 0.f);

        Vector3f dir = nearPoint.normalized();
        float invZ = 1.f / dir.z();

        ray.o = m_cameraToWorld * Point3f(0.f, 0.f, 0.f);
        ray.d = m_cameraToWorld * dir;
        ray.minT = m_nearClip * invZ;
        ray.maxT = m_farClip * invZ;
        ray.update();

        return Spectrum(1.f);
    }
コード例 #9
0
ファイル: InternalWindow.cpp プロジェクト: dreamsxin/egoboo
void InternalWindow::TitleBar::draw(DrawingContext& drawingContext) {
    std::shared_ptr<const Material> material;
    Point2f position;
    // Background of title bar
    position = getDerivedPosition();
    position -= Vector2f(BORDER_PIXELS * 2, 0.0f);
    material = std::make_shared<const Material>(_titleBarTexture.get(), Ego::Math::Colour4f::white(), true);
    _gameEngine->getUIManager()->drawImage(position, Vector2f(getWidth() + BORDER_PIXELS * 4, getHeight()), material);

    // Title string (centered on title bar)
    position = getDerivedPosition();
    position += Vector2f(getWidth() / 2.0f - _textWidth / 2.0f, 12);
    _font->drawText(_title, position.x(), position.y(), Colour4f(0.28f, 0.16f, 0.07f, 1.0f));

    //Skull texture (centered above top border of title bar)
    const int skullWidth = _titleSkullTexture.get_ptr()->getWidth() / 2;
    const int skullHeight = _titleSkullTexture.get_ptr()->getHeight() / 2;
    material = std::make_shared<const Material>(_titleSkullTexture.get(), Ego::Math::Colour4f::white(), true);
    position = getDerivedPosition();
    position += Vector2f(getWidth() / 2.0f - skullWidth / 2.0f, -skullHeight / 2.0f);
    _gameEngine->getUIManager()->drawImage(position, Vector2f(skullWidth, skullHeight), material);
}
コード例 #10
0
Point3d View::pointUnproject(Point2f screenPt,unsigned int frameWidth,unsigned int frameHeight,bool clip)
{
	Point2d ll,ur;
	double near,far;
	calcFrustumWidth(frameWidth,frameHeight,ll,ur,near,far);
	
	// Calculate a parameteric value and flip the y/v
	double u = screenPt.x() / frameWidth;
    if (clip)
    {
        u = std::max(0.0,u);	u = std::min(1.0,u);
    }
	double v = screenPt.y() / frameHeight;
    if (clip)
    {
        v = std::max(0.0,v);	v = std::min(1.0,v);
    }
	v = 1.0 - v;
	
	// Now come up with a point in 3 space between ll and ur
	Point2d mid(u * (ur.x()-ll.x()) + ll.x(), v * (ur.y()-ll.y()) + ll.y());
	return Point3d(mid.x(),mid.y(),-near);
}
コード例 #11
0
ファイル: polygon.cpp プロジェクト: bjandras/Newtown
bool Polygon::contains(Point2f const & p) const
{
	return m_qpolygon.containsPoint(QPointF(p.x(), p.y()), Qt::OddEvenFill);
}