Beispiel #1
0
// end a GL command list
void VRML_LAYER::glEnd( void )
{
    switch( glcmd )
    {
    case GL_LINE_LOOP:
        {
            // add the loop to the list of outlines
            std::list<int>* loop = new std::list<int>;

            if( !loop )
                break;

            for( unsigned int i = 0; i < vlist.size(); ++i )
            {
                loop->push_back( vlist[i]->o );
            }

            outline.push_back( loop );
        }
        break;

    case GL_TRIANGLE_FAN:
        processFan();
        break;

    case GL_TRIANGLE_STRIP:
        processStrip();
        break;

    case GL_TRIANGLES:
        processTri();
        break;

    default:
        break;
    }

    while( !vlist.empty() )
        vlist.pop_back();

    glcmd = 0;
}
// end a GL command list
void VRML_LAYER::glEnd( void )
{
    switch( glcmd )
    {
    case GL_LINE_LOOP:
        {
            // add the loop to the list of outlines
            std::list<int>* loop = new std::list<int>;

            if( !loop )
                break;

            double firstX = 0.0;
            double firstY = 0.0;
            double lastX = 0.0;
            double lastY = 0.0;
            double curX, curY;
            double area = 0.0;

            if( vlist.size() > 0 )
            {
                loop->push_back( vlist[0]->o );
                firstX = vlist[0]->x;
                firstY = vlist[0]->y;
                lastX = firstX;
                lastY = firstY;
            }

            for( size_t i = 1; i < vlist.size(); ++i )
            {
                loop->push_back( vlist[i]->o );
                curX = vlist[i]->x;
                curY = vlist[i]->y;
                area += ( curX - lastX ) * ( curY + lastY );
                lastX = curX;
                lastY = curY;
            }

            area += ( firstX - lastX ) * ( firstY + lastY );

            outline.push_back( loop );

            if( area <= 0.0 )
                solid.push_back( true );
            else
                solid.push_back( false );
        }
        break;

    case GL_TRIANGLE_FAN:
        processFan();
        break;

    case GL_TRIANGLE_STRIP:
        processStrip();
        break;

    case GL_TRIANGLES:
        processTri();
        break;

    default:
        break;
    }

    while( !vlist.empty() )
        vlist.pop_back();

    glcmd = 0;
}
Beispiel #3
0
double Oscillator::process (double frequency, int waveShape)
{    
	sharedMemory.enter();
	
	double output;
    switch (waveShape)
    {
        case 1:
            output = processSin();
            break;
        case 2:
            output = processSqr();
            break;
        case 3:
            output = processTri();
            break;
        case 4:
            output = processSawUp();
            break;
        case 5:
            output = processSawDown();
            break;
        default:
            output = processSin();
            break;
            
    }
    
    //the below functions being in seperate if else statements
    //means that when switching between certain waveforms the
    //waveform won't still be in sync. Could do with interating
    //through all the values no matter what the waveform is
	if (waveShape == 1 || waveShape == 3) 
	{
		increment = frequency * (TWOPI / sampRate);
		currentPhase += increment;
		
		if (currentPhase >= TWOPI)
			currentPhase -= TWOPI;
		if (currentPhase < 0.0)
			currentPhase += TWOPI;
	}
	else if (waveShape == 2) 
	{
		stepSize = squareNumSamples * (frequency / sampRate);
		currentSample += stepSize;
		
		//std::cout << "In process current sample: " <<  << std::endl;
		
		if (currentSample >= squareNumSamples)
			currentSample -= squareNumSamples;
		if (currentSample < 0.0)
			currentSample += squareNumSamples;
		
	}
	else if (waveShape == 4 || waveShape == 5) 
	{
		stepSize = sawNumSamples * (frequency / sampRate);
		currentSample += stepSize;
		
		//std::cout << "In process current sample: " <<  << std::endl;
		
		if (currentSample >= sawNumSamples)
			currentSample -= sawNumSamples;
		if (currentSample < 0.0)
			currentSample += sawNumSamples;
		
	}
	
    return output;
    
	sharedMemory.exit();
    //A digital wave signal is in the range of +1 to -1.
    //To creating an LFO using this class, the ouput must be scaled and offset
    //afterwards into the desired range.
    //For modulating amplitude, this is usually in the range 0 to 1;
    //the following equation is an example of how to do this:
    //output = (output * 0.5) + 0.5
    //the 0.5 is equal to the new range divided by the old range.
    
}