// Calculate position by adding one unit with given angle to the segment
void MoleculeLayoutGraph::_calculatePos (float phi, const Vec2f &v1, const Vec2f &v2, Vec2f &v)
{ 
   float alpha;
   Vec2f dir;

   dir.diff(v2, v1);

   alpha = dir.tiltAngle();
   alpha += phi;

   v.set(v1.x + cos(alpha), v1.y + sin(alpha));
}
void TestAppMesh::eventHandling ( const SDL_Event& event  ){
    //printf( "NonInert_seats::eventHandling() \n" );
    switch( event.type ){
        case SDL_KEYDOWN :
            switch( event.key.keysym.sym ){
                case SDLK_p:  first_person = !first_person; break;
                case SDLK_o:  perspective  = !perspective; break;
                //case SDLK_r:  world.fireProjectile( warrior1 ); break;
            }
            break;
        case SDL_MOUSEBUTTONDOWN:
            switch( event.button.button ){
                case SDL_BUTTON_LEFT:
                    Vec3d ray0;
                    ray0.set_lincomb( 1, mouse_begin_x, mouse_begin_y, camPos, camMat.a, camMat.b );
                    //glColor3f(1,1,1); Draw3D::drawPointCross( ray0, 0.2 );
                    ipicked= mesh.pickVertex( ray0, camMat.c );
                    mouse0.set(mouse_begin_x, mouse_begin_y);
                    dragging=true;
                    break;
            }
            break;
        case SDL_MOUSEBUTTONUP:
            switch( event.button.button ){
                case SDL_BUTTON_LEFT:
                    if(dragging){
                        Vec3d d;
                        d.set_lincomb( 1, mouse_begin_x, mouse_begin_y, camPos, camMat.a, camMat.b );
                        d.sub(mesh.points[ipicked]);
                        double c = d.dot(camMat.c);  d.add_mul(camMat.c, -c);
                        mesh.points[ipicked].add(d);

                        glDeleteLists(mesh.rendered_shape, 1);
                        mesh.rendered_shape = glGenLists(1);
                        glNewList( mesh.rendered_shape , GL_COMPILE );
                            glEnable( GL_LIGHTING );
                            glColor3f( 0.8f, 0.8f, 0.8f );
                            Draw3D::drawMesh( mesh );
                            mesh.tris2normals(true);
                            glColor3f(0.0f,0.0f,0.9f);
                            for(int i=0; i<mesh.points.size(); i++){
                                Draw3D::drawVecInPos( mesh.normals[i], mesh.points[i] );
                            }
                        glEndList();
                    }
                    dragging=false;
                    break;
            }
    };
    AppSDL2OGL::eventHandling( event );
}
示例#3
0
Vec2f NodeView::_calculateSize() {
    const int myInputCount = _node->inputs().size();
    const int myOutputCount = _node->outputs().size();


    int myMax = math<int>::max(myInputCount, myOutputCount);

    float myWidth = NODE_BASE_WIDTH + myMax * PIN_WIDTH + (myMax - 1) * PIN_SPACING;
    float myHeight = NODE_HEIGHT;

    Vec2f mySize;
    mySize.set(myWidth, myHeight);

    return mySize;
}
void ParticleController::addParticles( int amt, const Vec2i &mouseLoc, const Vec2f &mouseVel )
{
    for( int i=0; i<amt; i++ )
    {
        angle = i * ( (2 * M_PI)/amt);

        //Vec2f loc = mouseLoc + Rand::randVec2f() * 5.0f;
        Vec2f loc;
        loc.x = mouseLoc.x + 50*sin(angle);
        loc.y = mouseLoc.y + 50*cos(angle);

        coordinates.push_back(loc);

        //Vec2f velOffset = Rand::randVec2f() * Rand::randFloat( 1.0f, 5.0f );
        //Vec2f vel = mouseVel * 0.375f + velOffset;

        Vec2f vel;
        vel.set( sin(angle), cos(angle) );
        vel *= Rand::randFloat(3, 10);

        mParticles.push_back( Particle( loc, vel ) );
    }
}
示例#5
0
void VBSPGeometry::addFace(int faceIndex)
{
    Face                  currentFace;
    Edge                  currentEdge;
    DisplaceInfo          currentDispInfo;
    TexInfo               currentTexInfo;
    TexData               currentTexData;
    Vec3                  normal;
    int                   edgeIndex;
    int                   i;
    int                   currentSurfEdge;
    Vec3                  currentVertex;
    Vec3                  texU;
    float                 texUOffset;
    float                 texUScale;
    Vec3                  texV;
    float                 texVOffset;
    float                 texVScale;
    float                 u, v;
    Vec2f                 texCoord;

    // Make sure this face is not "on node" (an internal node of the BSP tree).
    // These faces are not used for visible geometry
    currentFace = bsp_data->getFace(faceIndex);

    // See if this is a displacement surface
    if (currentFace.dispinfo_index != -1)
    {
        // Get the displacement info
        currentDispInfo =
            bsp_data->getDispInfo(currentFace.dispinfo_index);

        // Generate the displacement surface
        createDispSurface(currentFace, currentDispInfo);
    }
    else
    {
        // Get the face normal, using the plane information
        normal = bsp_data->getPlane(currentFace.plane_index).plane_normal;
        if (currentFace.plane_side != 0)
            normal = -normal;

        // Get the texture info and data structures
        currentTexInfo = bsp_data->getTexInfo(currentFace.texinfo_index);
        currentTexData = bsp_data->getTexData(currentTexInfo.texdata_index);

        // Get the texture vectors and offsets.  These are used to calculate
        // texture coordinates 
        texU.set(currentTexInfo.texture_vecs[0][0],
                 currentTexInfo.texture_vecs[0][1],
                 currentTexInfo.texture_vecs[0][2]);
        texUOffset = currentTexInfo.texture_vecs[0][3];
        texV.set(currentTexInfo.texture_vecs[1][0],
                 currentTexInfo.texture_vecs[1][1],
                 currentTexInfo.texture_vecs[1][2]);
        texVOffset = currentTexInfo.texture_vecs[1][3];

        // Scale the texture vectors from inches to meters
        texU *= 39.37f;
        texV *= 39.37f;

        // Get the texture size, as the planar texture projection results in
        // non-normalized texture coordinates
        texUScale = 1.0f / (float)currentTexData.texture_width;
        texVScale = 1.0f / (float)currentTexData.texture_height;

        // Start with the last edge index, because we need to switch from
        // clockwise winding (DirectX) to counter-clockwise winding (OpenGL)
        edgeIndex = currentFace.first_edge + currentFace.num_edges - 1;

        // Set the length of this primitive on the primitive set
        primitive_set->push_back(currentFace.num_edges);

        // Iterate over the edges in this face, and extract the vertex data
        for (i = 0; i < currentFace.num_edges; i++)
        {
            // Look up the edge specified by the surface edge index, the
            // index might be negative (see below), so take the absolute
            // value
            currentSurfEdge = bsp_data->getSurfaceEdge(edgeIndex);
            currentEdge = bsp_data->getEdge(abs(currentSurfEdge));

            // The sign of the surface edge index specifies which vertex is
            // "first" for this face.  A negative index means the edge should
            // be flipped, and the second vertex treated as the first
            if (currentSurfEdge < 0)
                currentVertex = bsp_data->getVertex(currentEdge.vertex[1]);
            else
                currentVertex = bsp_data->getVertex(currentEdge.vertex[0]);

            // Add the vertex to the array
            vertex_array->push_back(currentVertex);

            // Set the normal
            normal_array->push_back(normal);

            // Calculate the texture coordinates for this vertex
            u = texU * currentVertex + texUOffset;
            u *= texUScale;
            v = texV * currentVertex + texVOffset;
            v *= texVScale;
            texCoord.set(u, v);

            // Add the texture coordinate to the array
            texcoord_array->push_back(texCoord);

            // Move on to the next (previous?) vertex
            edgeIndex--;
        }
    }
}
示例#6
0
void RenderContext::_bbVecToUser (Vec2f& d, const Vec2f& s)
{
   double x = s.x, y = s.y;
   cairo_device_to_user(_cr, &x, &y);
   d.set((float)x, (float)y);
}
void Ex21WindApp::setup()
{
    wind.set( 0.01f, 0.f );
    gravity.set( 0.f, 0.1f );
}
void OrbitEditor::drawHUD(){
    glDisable ( GL_LIGHTING );

    glColor3f(1.0f,1.0f,1.0f);   txtStatic.view3D( {5,5}, fontTex, 8 );

    glPushMatrix();

        glTranslatef(20, 200, 0);
        glScalef    (timeScale,valScale,1);
        glTranslatef(-tstart, 0, 0);

        // axis-zero
        glColor3f( 0.0f, 0.0f, 0.0f ); Draw2D::drawLine( { 0, 0.0}, {WIDTH, 0.0} );

        // curves
        glColor3f( 0.0f, 0.0f, 0.0f ); Draw2D::plot_cross( splines.n, splines.ts, splines.CPs[iedit], 0.03 );

        // curves
        //glColor3f( 1.0f, 1.0f, 1.0f ); glBegin(GL_LINE_STRIP); for(int i=0; i<nsamp; i++){ glVertex3d( (tstart+i*dt), (float)positions[i].array[iedit], 0.0 ); }; glEnd();
        glColor3f( 1.0f, 0.0f, 0.0f ); glBegin(GL_LINE_STRIP); for(int i=0; i<nsamp; i++){ glVertex3d( (tstart+i*dt), (float)positions[i].x, 0.0 ); }; glEnd();
        glColor3f( 0.0f, 1.0f, 0.0f ); glBegin(GL_LINE_STRIP); for(int i=0; i<nsamp; i++){ glVertex3d( (tstart+i*dt), (float)positions[i].y, 0.0 ); }; glEnd();
        glColor3f( 0.0f, 0.0f, 1.0f ); glBegin(GL_LINE_STRIP); for(int i=0; i<nsamp; i++){ glVertex3d( (tstart+i*dt), (float)positions[i].z, 0.0 ); }; glEnd();

        //DEGUB
        //glColor3f( 1.0f, 0.0f, 0.0f ); glBegin(GL_LINE_STRIP); for(int i=0; i<nsamp; i++){ glVertex3d( (tstart+i*dt), 0.5*(float)velocities[i].x, 0.0 ); }; glEnd();
        //glColor3f( 0.0f, 1.0f, 0.0f ); glBegin(GL_LINE_STRIP); for(int i=0; i<nsamp; i++){ glVertex3d( (tstart+i*dt), 0.25*(float)accelerations[i].x, 0.0 ); }; glEnd();
        //glColor3f( 1.0f, 0.0f, 1.0f ); glBegin(GL_LINE_STRIP); for(int i=0; i<nsamp; i++){ glVertex3d( (tstart+i*dt), 0.1+0.5*(float)dpos[i].x, 0.0 ); }; glEnd();
        //glColor3f( 0.0f, 1.0f, 1.0f ); glBegin(GL_LINE_STRIP); for(int i=0; i<nsamp; i++){ glVertex3d( (tstart+i*dt), 0.1+0.25*(float)ddpos[i].x, 0.0 ); }; glEnd();

        // tangents
        glColor3f( 0.0f, 0.0f, 0.0f );
        glBegin(GL_LINES);
        double * dCPi=splines.dCPs[iedit];
        for(int i=1; i<splines.n-1; i++){
            double t,d,p;
            t =splines.ts[i];
            p =splines.CPs[iedit][i];
            d =splines.getPointDeriv(i,iedit);
            //if(dCPi){d=dCPi[i];}else{  d=splines.inferDeriv(i,iedit); }
            glVertex3d( t-0.5, p-0.5*d, 0.0 );
            glVertex3d( t+0.5, p+0.5*d, 0.0 );
        }
        glEnd();

        // cursor
        //Vec2d pcur;    pcur.set( mouse_t,mouse_val );
        Vec2f ppoint;  ppoint.set( splines.ts[ipoint],splines.CPs[iedit][ipoint] );
        glColor3f( 1.0f, 1.0f, 1.0f );
        //Draw2D::drawPointCross( {mouse_t,mouse_val} , 0.1 );
        Draw2D::drawLine( {mouse_t-0.1,mouse_val}, {mouse_t+0.1,mouse_val} );
        Draw2D::drawLine( {mouse_t,valScale}, {mouse_t,-valScale} );
        Draw2D::drawCircle( ppoint, 0.1, 16, false );
        if(dragging){ Draw2D::drawLine( {mouse_t,mouse_val}, ppoint ); };

        //txtPop.view3D( {splines.ts[ipoint],splines.CPs[iedit][ipoint],1.0}, fontTex, 10 );
        glTranslatef(mouse_t,0,0);
        glRotatef(90,0,0,1);
        Draw::drawText(curCaption, fontTex, 0.1, 0, 0 );

    glPopMatrix();
}
void EpicMonsterApp::mouseMove( MouseEvent event )
{
    mMousePos.set(event.getPos());
}
void KochSnowflakeApp::setup()
{
    mStartPoint.set(100.0f, 220.0f );
    mStartLength = 650.0f;
}
示例#11
0
void gpuPSApp::mouseMove( MouseEvent event )
{
    mMousePos.set(event.getPos());
}