当前位置: 首页>>代码示例>>C++>>正文


C++ Vec3Df类代码示例

本文整理汇总了C++中Vec3Df的典型用法代码示例。如果您正苦于以下问题:C++ Vec3Df类的具体用法?C++ Vec3Df怎么用?C++ Vec3Df使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Vec3Df类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: intersect

float Ray::intersect (const Vec3Df & p0, const Vec3Df & p1, const Vec3Df & p2, Vec3Df & intersectionPoint) const {
    Vec3Df e0 = p1-p0;
    Vec3Df e1 = p2-p0;
    Vec3Df n = Vec3Df::crossProduct(e0,e1);
    n.normalize();
    Vec3Df q = Vec3Df::crossProduct(direction,e1);
    float a = Vec3Df::dotProduct(e0,q);

    if (Vec3Df::dotProduct(n,direction) >= 0 || a < epsilon)
        return -1;

    Vec3Df s = (origin-p0)/a;
    Vec3Df r = Vec3Df::crossProduct(s,e0);

    intersectionPoint[1] = Vec3Df::dotProduct(s,q);
    intersectionPoint[2] = Vec3Df::dotProduct(r,direction);
    intersectionPoint[0] = 1 - intersectionPoint[2] - intersectionPoint[1];

    if (intersectionPoint[0] < 0 || intersectionPoint[1] < 0 || intersectionPoint[2] < 0)
        return -1;

    float t = Vec3Df::dotProduct(e1,r);

    if (t < 0)
        return -1;
    else
        return t;
}
开发者ID:groscot,项目名称:ray3d,代码行数:28,代码来源:Ray.cpp

示例2: dir

float Ray::intersect (const Vec3Df & p0, const Vec3Df & p1, const Vec3Df & p2, Vec3Df & intersectionPoint, Vec3Df & bary) const {
    Vec3Df e0 = p1-p0;
    Vec3Df e1 = p2-p0;
    Vec3Df n = Vec3Df::crossProduct(e0,e1);
    Vec3Df dir (this->direction);
    n.normalize();
    Vec3Df q = Vec3Df::crossProduct(dir,e1);
    float a = Vec3Df::dotProduct(e0,q);

    if (Vec3Df::dotProduct(n,dir) >= 0 || std::abs(a) < epsilon)
        return -1;

    Vec3Df s = (this->origin-p0)/a;
    Vec3Df r = Vec3Df::crossProduct(s,e0);

    bary[1] = Vec3Df::dotProduct(s,q);
    bary[2] = Vec3Df::dotProduct(r,dir);
    bary[0] = 1 - bary[2] - bary[1];

    if (bary[0] < 0 || bary[1] < 0 || bary[2] < 0)
        return -1;

    float t = Vec3Df::dotProduct(e1,r);
    intersectionPoint = Vec3Df(p0 * bary[0] + p1 * bary[1] + p2 * bary[2])/(bary[0] + bary[1] + bary[2]);

    if (t < 0)
        return -1;
    else
        return t;
}
开发者ID:groscot,项目名称:ray3d,代码行数:30,代码来源:Ray.cpp

示例3: ray

Vec3Df Glass::genColor (const Vec3Df & camPos,
                        Ray *r,
                        const std::vector<Light> &lights, Brdf::Type type) const {
    const Object *o = r->getIntersectedObject();
    float size = o->getBoundingBox().getRadius();
    const Vertex &closestIntersection = r->getIntersection();
    const Vec3Df & pos = closestIntersection.getPos();
    Vec3Df dir = camPos-pos;

    Vec3Df normal = normalTexture->getNormal(r);

    dir = dir.refract(1, normal, coeff);
    dir.normalize();

    //Works well only for convex object
    Ray ray(pos-o->getTrans()+3*size*dir, -dir);
    if (!o->getKDtree().intersect(ray)) {
        return controller->getRayTracer()->getColor(pos+size*dir, pos-camPos);
    }

    const Vertex i = ray.getIntersection();
    dir = (-dir).refract(coeff,-normalTexture->getNormal(&ray), 1);

    Vec3Df glassColor = controller->getRayTracer()->getColor(dir, i.getPos()+o->getTrans(), false);

    Vec3Df brdfColor = Vec3Df();
    // If at least slightly opaque
    if (alpha) {
        brdfColor = Material::genColor(camPos, r, lights, type);
    }
    return Vec3Df::interpolate(brdfColor, glassColor, alpha);
}
开发者ID:B-C,项目名称:raymini,代码行数:32,代码来源:Material.cpp

示例4: up

void Camera::rotate (float theta, float phi) {
    Vec3Df up (getUpVector ());
    Vec3Df right (getRightVector ());
    Vec3Df ce (eye - center);
    float d = ce.getLength ();
    ce.normalize ();
    Vec3Df c = Vec3Df (sin (theta), sin (phi), cos (theta));
    eye = center + d * (c[0]*right + c[1]*up + c[2]*ce);
}
开发者ID:pierr,项目名称:Projet3D,代码行数:9,代码来源:Camera.cpp

示例5: hard

bool Shadow::hard(const Vec3Df & pos, const Vec3Df& light) const {
    Ray riShadow;

    Vec3Df dir = light - pos;
    float dist = dir.normalize();

    bool inter = rt->intersect(dir, pos, riShadow);
    if(inter && dynamic_cast<const Glass *>(&riShadow.getIntersectedObject()->getMaterial()))
        return true;

    return !inter || (inter && riShadow.getIntersectionDistance() > dist);
}
开发者ID:B-C,项目名称:raymini,代码行数:12,代码来源:Shadow.cpp

示例6: asin

Vec3Df Sphere::shade(const Vec3Df& cam_pos, const Vec3Df& intersect, const Vec3Df& light_pos, const Vec3Df& normal){
	if (!_mat.has_tex()) return Shape::shade(cam_pos, intersect, light_pos, normal);
	float u, v;
	Vec3Df mid = this->_origin;
	Vec3Df dir = intersect - mid;
	dir.normalize();
	u = 0.5 + (atan2(dir[2], dir[0]))/(2*M_PI);
	v = 0.5 - asin(dir[1])/M_PI;
	Vec3Df diffuse = this->_tex->getColor(u,v);
	this->_mat.set_Kd(diffuse[0], diffuse[1], diffuse[2]);
	return Shape::shade(cam_pos, intersect, light_pos, normal);
}
开发者ID:Balletie,项目名称:TI1805-Project,代码行数:12,代码来源:sphere.cpp

示例7: ground

void Scene::buildOriginalScene2 () {

    Mesh groundMesh;
    groundMesh.loadOFF ("models/ground.off");
    groundMesh.scale(Vec3Df(20.f, 25.f, 1.f));
    Material groundMat;
    Object ground (groundMesh, groundMat);
    ground.setTrans(Vec3Df(0.f, -15.f, 0.f));
    objects.push_back (ground);

    Mesh killerooMesh;
    killerooMesh.loadOFF ("models/killeroo.off");
    killerooMesh.scale(0.3f);
    killerooMesh.rotate(0);
    killerooMesh.rotate(0);
    killerooMesh.rotate(0);
    killerooMesh.rotate(2);
    killerooMesh.rotate(2);
    Material killerooMat (1.f, 1.f, 2.f, 0.f, Vec3Df (0.1f, .6f, 0.5f));
    Object killeroo (killerooMesh, killerooMat);
    killeroo.setTrans (Vec3Df (0., 29.f, 4.f));
    objects.push_back (killeroo);


    float stepX = 2.2f;
    float stepY = 2.2f;
    float offsetX = -2.8f;
    float offsetY = 3.f;

    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 3; ++j) {
            Mesh ramMesh;
            ramMesh.loadOFF ("models/ram.off");
            Material ramMat (1.f, 1.f, 2.f, 0.f, Vec3Df (1.f, .6f, .2f));
            Object ram (ramMesh, ramMat);
            float randX = (rand()%100)/100.f - 0.5f;
            float randY = (rand()%100)/100.f - 0.5f;
            ram.setTrans (Vec3Df (offsetX + i*stepX + randX, offsetY + j*stepY + randY, 0.f));
            objects.push_back (ram);
        }
    }

    Vec3Df lightPos(Vec3Df (2.0f, 25.0f, 15.0f));
    Vec3Df dir = -lightPos;
    dir.normalize();

    Light l0 (lightPos , dir, 2.f, Vec3Df (1.0f, 1.0f, 1.0f), 1.0f);
    lights.push_back (l0);

}
开发者ID:rfaugeroux,项目名称:RayTracer,代码行数:50,代码来源:Scene.cpp

示例8: intersect

bool Sphere::intersect(const Vec3Df& origin, const Vec3Df& dir, Vec3Df& new_origin, Vec3Df& normal) {
	Vec3Df trans_origin = origin - this->_origin;
	float a = Vec3Df::dotProduct(dir, dir);
	float b = 2 * Vec3Df::dotProduct(trans_origin, dir);
	float c = Vec3Df::dotProduct(trans_origin, trans_origin) - this->_radius * this->_radius;

	float disc = b * b - 4 * a * c;
	if (disc < 0)	return false;

	// We use the following in place of the quadratic formula for
	// more numeric precision.
	float q = (b > 0) ?
				-0.5 * (b + sqrtf(disc)) :
				-0.5 * (b - sqrtf(disc));
	float t0 = q / a;
	float t1 = c / q;
	if (t0 < t1) std::swap(t0,t1);

	float t;
	if (t0 < EPSILON)	return false;
	if (t1 < 0)		t = t0;
	else			t = t1;

	normal = trans_origin + t * dir;
	normal.normalize();
	new_origin = origin + t * dir;
	return true;
}
开发者ID:Balletie,项目名称:TI1805-Project,代码行数:28,代码来源:sphere.cpp

示例9: glBegin

/************************************************************
* draw
************************************************************/
void Mesh::drawSmooth() {

	glBegin(GL_TRIANGLES);

	for (unsigned int i = 0;i<triangles.size();++i)
	{
		Vec3Df col = this->materials[triangleMaterials[i]].Kd();

		glColor3fv(col.pointer());
		for (int v = 0; v < 3; v++) {
			glNormal3f(vertices[triangles[i].v[v]].n[0], vertices[triangles[i].v[v]].n[1], vertices[triangles[i].v[v]].n[2]);
			glVertex3f(vertices[triangles[i].v[v]].p[0], vertices[triangles[i].v[v]].p[1], vertices[triangles[i].v[v]].p[2]);
		}

	}
	glEnd();
}
开发者ID:thervh70,项目名称:Raytracing-Project,代码行数:20,代码来源:mesh.cpp

示例10: glBegin

void Mesh::draw(){
    glBegin(GL_TRIANGLES);

    for (int i=0;i<triangles.size();++i)
    {
        Vec3Df edge01 = vertices[triangles[i].v[1]].p -  vertices[triangles[i].v[0]].p;
        Vec3Df edge02 = vertices[triangles[i].v[2]].p -  vertices[triangles[i].v[0]].p;
        Vec3Df n = Vec3Df::crossProduct (edge01, edge02);
        n.normalize ();
        glNormal3f(n[0], n[1], n[2]);
        for(int v = 0; v < 3 ; v++){
            glVertex3f(vertices[triangles[i].v[v]].p[0], vertices[triangles[i].v[v]].p[1] , vertices[triangles[i].v[v]].p[2]);
        }

    }
    glEnd();
}
开发者ID:highsmallxu,项目名称:Forgotten-Worlds,代码行数:17,代码来源:mesh.cpp

示例11: Vec3Df

/************************************************************
 * Fonctions de calcul des normales pour chaque sommet
 ************************************************************/
void Mesh::computeVertexNormals () {
    //initialisation des normales des vertex
    for (unsigned int i = 0; i < vertices.size (); i++)
        vertices[i].n = Vec3Df (0.0, 0.0, 0.0);

    //Somme des normales du 1 voisinage du vertex
    for (unsigned int i = 0; i < triangles.size (); i++) {
        Vec3Df edge01 = vertices[triangles[i].v[1]].p -  vertices[triangles[i].v[0]].p;
        Vec3Df edge02 = vertices[triangles[i].v[2]].p -  vertices[triangles[i].v[0]].p;
        Vec3Df n = Vec3Df::crossProduct (edge01, edge02);
        n.normalize ();
        for (unsigned int j = 0; j < 3; j++)
            vertices[triangles[i].v[j]].n += n;
    }

    //Normalisation
    for (unsigned int i = 0; i < vertices.size (); i++)
        vertices[i].n.normalize ();
}
开发者ID:highsmallxu,项目名称:Forgotten-Worlds,代码行数:22,代码来源:mesh.cpp

示例12: tan

void GridAARayIterator::raysForPixel(int i, int j, std::vector<Ray>& res)
{
    res.clear();

    float tanX = tan (_fieldOfView)*_aspectRatio;
    float tanY = tan (_fieldOfView);

    for (int k = 0; k < gridSize; k++) {
        for(int l = 0; l < gridSize; l++)
        {
            Vec3Df stepX = (float (k+gridSize*i) - gridSize*_screenWidth/2.f)/(gridSize * _screenWidth) * tanX * _rightVector;
            Vec3Df stepY = (float (l+gridSize*j) - gridSize*_screenHeight/2.f)/(gridSize * _screenHeight) * tanY * _upVector;
            Vec3Df step = stepX + stepY;
            Vec3Df dir = _direction + step;
            dir.normalize ();
            res.push_back(Ray(_camPos, dir));

        }
    }
}
开发者ID:jcaille,项目名称:Raymini,代码行数:20,代码来源:GridAARayIterator.cpp

示例13: draw

void draw () {
    //On récupère la matrice objet monde
    GLfloat	modl[16];
    glGetFloatv( GL_MODELVIEW_MATRIX, modl );
    GLfloat lightPos[4];
    glGetLightfv(GL_LIGHT1, GL_POSITION, lightPos);
    
    //Vec3Df lightPosition()
    const vector<Vertex> & V = mesh.V;
    const vector<Triangle> & T = mesh.T;
    glBegin (GL_TRIANGLES);
    
    for (unsigned int i = 0; i < T.size (); i++) {
        /*if(i < (unsigned int)T.size()/2){
            glColor3ub(255, 12, 4);
        }  else{    
            glColor3ub(1, 12, 200);
        }*/
        if (polygonMode != Gouraud) {
            Vec3Df e01 = V[T[i].v[1]].p -  V[T[i].v[0]].p;
            Vec3Df e02 = V[T[i].v[2]].p -  V[T[i].v[0]].p;
            Vec3Df n = Vec3Df::crossProduct (e01, e02);
            n.normalize ();
            glNormal3f (n[0], n[1], n[2]);
            //glColorMaterial(GLenum face, GLenum mode)
            //modl.V[T[i].v]
        }
        
        //glGetFloatv(GLenum pname, GLfloat *params)
        for (unsigned int j = 0; j < 3; j++) {
            const Vertex & v = V[T[i].v[j]];
            if (polygonMode == Gouraud)
                glNormal3f (v.n[0], v.n[1], v.n[2]);
            
            glVertex3f (v.p[0], v.p[1], v.p[2]);
            
        }
        
    }
    glEnd ();
}
开发者ID:pierr,项目名称:tp1,代码行数:41,代码来源:gmini.cpp

示例14: Vec3Df

/************************************************************
* Normal calculations
************************************************************/
void Mesh::computeVertexNormals() {
	for (unsigned int i = 0; i < vertices.size(); i++)
		vertices[i].n = Vec3Df(0.0, 0.0, 0.0);

	//Sum up neighboring normals
	for (unsigned int i = 0; i < triangles.size(); i++) {
		Vec3Df edge01 = vertices[triangles[i].v[1]].p - vertices[triangles[i].v[0]].p;
		Vec3Df edge02 = vertices[triangles[i].v[2]].p - vertices[triangles[i].v[0]].p;
		Vec3Df n = Vec3Df::crossProduct(edge01, edge02);

		n.normalize();
		//triangles[i].normal = new Vec3Df(n.p[0], n.p[1], n.p[2]);

		for (unsigned int j = 0; j < 3; j++)
			vertices[triangles[i].v[j]].n += n;
	}

	//Normalize
	for (unsigned int i = 0; i < vertices.size(); i++)
		vertices[i].n.normalize();
}
开发者ID:thervh70,项目名称:Raytracing-Project,代码行数:24,代码来源:mesh.cpp

示例15: BuildFromVertices

void Surfel::BuildFromVertices (
    const Vertex&       iA,
    const Vertex&       iB,
    const Vertex&       iC,
    const Vec3Df&       iTranslation
) {
    // Edge eX is opposed to vertex X.
    Vec3Df eA = iC.getPos () - iB.getPos ();
    Vec3Df eB = iC.getPos () - iA.getPos ();
    Vec3Df eC = iA.getPos () - iB.getPos ();

    float a = eA.getLength ();
    float b = eB.getLength ();
    float c = eC.getLength ();
    
    eA.normalize ();
    eB.normalize ();
    eC.normalize ();
   
    // The perimeter of the triangle.
    float p = (a + b + c);
    // The semiperimeter of the triangle.
    float s = 0.5f * p;
    // The area of the triangle.
    float k = sqrt ( s * ( s - a ) * ( s - b ) * ( s - c ) );
    
    // The surfel radius equals the radius of the circle inscribed
    // in the triangle defined by vertices iA, iB and iC.
    m_radius = k / s;

    // The surfel's position is defined by the center of the inscribed
    // circle, which is subsequently defined by the intersection point
    // of the angle bisections.
    m_position  = a * iA.getPos () 
                + b * iB.getPos () 
                + c * iC.getPos ();
    m_position /= p;
    m_position += iTranslation;

    // We interpolate the normals the same way.
    m_normal    = a * iA.getNormal () 
                + b * iB.getNormal () 
                + c * iC.getNormal ();
    m_normal   /= p;
}
开发者ID:elfprincexu,项目名称:RayMini,代码行数:45,代码来源:Surfel.cpp


注:本文中的Vec3Df类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。