示例#1
0
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;
}
示例#2
0
文件: Camera.cpp 项目: pierr/Projet3D
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);
}
示例#3
0
void GLViewer::mousePressEvent(QMouseEvent * event) {
    const WindowModel *windowModel = controller->getWindowModel();
    if (windowModel->isDragEnabled()) {
        float fov, ar;
        float screenWidth;
        float screenHeight;
        Vec3Df camPos;
        Vec3Df viewDirection;
        Vec3Df upVector;
        Vec3Df rightVector;
        getCameraInformation(fov, ar, screenWidth, screenHeight, camPos, viewDirection, upVector, rightVector);
        float tanX = tan(fov)*ar;
        float tanY = tan(fov);
        Vec3Df stepX = (float (event->x()) - screenWidth/2.f)/screenWidth * tanX * rightVector;
        Vec3Df stepY = (float (screenHeight-event->y()) - screenHeight/2.f)/screenHeight * tanY * upVector;
        Vec3Df step = stepX + stepY;
        Vec3Df dir = viewDirection + step;
        float distanceCameraScreen = dir.getLength();
        dir.normalize();
        Ray ray;
        if (controller->getRayTracer()->intersect(dir, camPos, ray)) {
            Object *o=ray.getIntersectedObject();
            QPoint p = event->globalPos();
            Vec3Df oPos = o->getTrans();
            float ratio = distanceCameraScreen/sqrt(ray.getIntersectionDistance());
            controller->viewerStartsDragging(o, oPos, p, ratio);
        }
    }
    if (!controller->getWindowModel()->isRealTime()) {
        controller->viewerSetDisplayMode(WindowModel::OpenGLDisplayMode);
    }
    else {
        controller->forceThreadUpdate();
    }
    QGLViewer::mousePressEvent(event);
}