Example #1
0
  //Given a single face, draw 3 quads as selection targets for the 3 vertexes of the face.
void SubdivScene::drawQuads(Face* f) {
    Vec centre;
    std::vector<Vertex*> vertexList;

    for( Face::iterator itr = f->begin(); !itr.isDone(); ++itr) {
        vertexList.push_back(&*itr);
        centre = centre + itr->getData().p;
    }

 
    GLuint i = 0;
    for( Face::iterator itr = f->begin(); !itr.isDone(); ++itr) {
      glLoadName(i);
      glBegin(GL_QUADS);
      Vec v = itr->getData().p;

      Vec next = (v + vertexList[ ((i + 1) % vertexList.size() )]->getData().p ) / 2;
      Vec prev = (v + vertexList[ ((i + vertexList.size()- 1) % vertexList.size() )]->getData().p ) / 2;
      prev.print();
      glVertex3f( v.x, v.y, v.z );
      glVertex3f( next.x, next.y, next.z);
      glVertex3f(centre.x, centre.y, centre.z);
      glVertex3f(prev.x, prev.y, prev.z);

      glEnd();
      i++;
    }
}
Example #2
0
bool SubdivScene::repositionSelectedVertex(int x, int y) {
    if (!selectedVertex)
        return false;

    printf("Repositioning vertex, (%i, %i)...\n", x,y);
    //In the plane perpendicular to camera->look, and through which the vertex passes, 
    //move vertex from where it is to where the mouse is

    //Use current vertex position to calculate the center of the screen
    Vec camPos = camera->getPos();
    Vec vPos = selectedVertex->getData().p;
    Vec diff = vPos - camPos;
    Vec look = camera->getLook().normalize();
    float cosAngle = sqrt(diff.normalize().dot(look));
    float lookLength = diff.length()*cosAngle;
    Vec centreDiff = look*lookLength;
    Vec diffInPlane = vPos - (camPos + centreDiff);
printf(" diffInPlane is"); diffInPlane.print();
printf(" Cam pos is"); camPos.print();


    float anglex = (x - Globals::getWidth()/2)*Globals::getFovx() * Globals::PI/180/Globals::getWidth();
    float angley = (y - Globals::getHeight()/2)*Globals::getFovy() * Globals::PI/180/Globals::getHeight();
    float hLength = tan(anglex)*centreDiff.length();
    float vLength = tan(angley)*centreDiff.length();
printf(" anglex is %f and angley is %f, fovx is %f\n", anglex, angley, Globals::getFovx());
printf(" hLength is %f and vLength is %f, hrat is %i\n", hLength, vLength, x - Globals::getWidth()/2);


    //calculate the shifts in the horiz and vertical directions
    Vec right = camera->getLook().cross(camera->getUp()).normalize()*hLength;
    Vec up = camera->getUp().normalize()*vLength;

printf(" Right is"); right.print();
printf(" up is"); up.print();

    Vec newPos = vPos + right + up - diffInPlane;
    selectedVertex->getData().p = newPos;

    printf("  Old position was (%f, %f, %f)\n", vPos.x, vPos.y, vPos.z);
    printf("  New position is (%f, %f, %f)\n", newPos.x, newPos.y, newPos.z);

    redrawRequired = true;
}
Example #3
0
int main() {
    
    // ---------------------------------------------------
    // initialize v1 with 10 values...  the multiples of 5
    Vec<int> v1( 10, 0 );
    Vec<int>::size_type i;
    for ( i = 0; i < v1.size(); i++) {
        v1[i] = 5 * i;
    }
    cout << "v1.size() = " << v1.size() << ".  Should be 10.\n";
    cout << "Contents of v1 (multiples of 5):";
    for ( i = 0; i<v1.size(); ++i ) {
        cout << " " << v1[i];
    }
    cout << endl;
    
    // --------------------------------------------------------------------------
    // make v2 be a copy of v1, but then overwrite the 2nd half with the 1st half
    Vec<int> v2( v1 );
    v2[ 9 ] = v2[ 0 ];
    v2[ 8 ] = v2[ 1 ];
    v2[ 7 ] = v2[ 2 ];
    v2[ 6 ] = v2[ 3 ];
    v2[ 5 ] = v2[ 4 ];
    cout << "Contents of v1 (still multiples of 5):";
    for ( i = 0; i<v1.size(); ++i )
        cout << " " << v1[i];
    cout << endl;
    cout << "Contents of v2 (now palindrome):";
    for ( i = 0; i<v2.size(); ++i )
        cout << " " << v2[i];
    cout << endl;
    
    // ------------------------------------------
    // make v3 be a copy of v2, but then clear it
    Vec<int> v3;
    v3 = v2;
    v3.clear();
    cout << "\nAfter copying v2 to v3 and clearing v3,  v2.size() = "
    << v2.size() << " and v3.size() = " << v3.size() << endl;
    cout << "Contents of v2 (should be unchanged):";
    for ( i = 0; i<v2.size(); ++i ) {
        cout << " " << v2[i];
    }
    cout << endl;
    
    // --------------
    // test push back
    cout << "\nNow testing push_back.  Adding 3, 6, 9 to v2:\n";
    v2.push_back( 3 );
    v2.push_back( 6 );
    v2.push_back( 9 );
    cout << "v2 is now: \n";
    for ( i = 0; i<v2.size(); ++i ) {
        cout << " " << v2[i];
    }
    cout << endl;
    
    // -----------
    // test resize
    v1.resize(20,100);
    cout << "\nNow testing resize.  Resizing v1 to have 20 elements and v2 to have 2 elements\n";
    cout << "v1 is now (should have 100s at the end): \n";
    for ( i = 0; i<v1.size(); ++i )
        cout << " " << v1[i];
    cout << endl;
    v2.resize(2,100);
    cout << "v2 is now: \n";
    for ( i = 0; i<v2.size(); ++i )
        cout << " " << v2[i];
    cout << endl;
    
    // ------------------------
    // test of a vec of doubles
    cout << "\nStarting from an empty vector, z,  of doubles and doing\n"
    << "5 push_backs\n";
    Vec<double> z;
    for ( i = 0; i<5; ++i )
        z.push_back( sqrt( double(10*(i+1)) ));
    cout << "Contents of vector z: ";
    for ( Vec<double>::size_type j = 0; j < z.size(); j++ )
        cout << " " << z[j];
    cout << endl;
    
    
    
    // ADD MORE TEST CASES HERE
    
    Vec<int> T;
    T.push_back(6);
    T.push_back(6);
    T.push_back(6);
    T.push_back(47);
    T.push_back(7);
    T.push_back(8);
    T.push_back(426);
    cout << "T should contain 6 6 6 47 7 8 426" << endl;
    cout<< "T: ";
    for(int i =0; i < T.size(); ++i){
        cout << T[i] << " ";
    }
    cout << endl;
    remove_matching_elements(T,6);
    
    cout << "Now T should contain 47 7 8 426" << endl;
    cout << "T:";
    for(int i =0; i < T.size(); ++i){
        cout << T[i] << " ";
    }
    
    Vec<int> Q;
    Q.push_back(8);
    Q.push_back(1);
    Q.push_back(47);
    Q.push_back(47);
    Q.push_back(7);
    Q.push_back(47);
    Q.push_back(426);
    cout << "Q should contain 8 1 47 47 7 47 426" << endl;
    cout<< "Q: ";
    for(int i =0; i < Q.size(); ++i){
        cout << Q[i] << " ";
    }
    cout << endl;
    remove_matching_elements(Q,47);
    
    cout << "Now Q should contain 8 1 7 426" << endl;
    cout << "Q:";
    for(int i =0; i < Q.size(); ++i){
        cout << Q[i] << " ";
    }
    Vec<int> X;
    X.push_back(8);
    X.push_back(1);
    X.push_back(47);
    X.push_back(47);
    X.push_back(7);
    X.push_back(47);
    X.push_back(426);
    X.print();
    
    remove_matching_elements(X, 426);
    X.print();
    
    Vec<int> LOOP;
    for(int i =0; i<100; ++i){
        LOOP.push_back(i);
        for(int j = 0; j< 5; j++){
            LOOP.push_back(i+j);
        }
    }
    LOOP.print();
    remove_matching_elements(LOOP, 12);
    LOOP.print();
    
    return 0; 
}