Пример #1
0
//-----------------------------------------------------------------------------
// name: render()
// desc: ...
//-----------------------------------------------------------------------------
t_CKUINT AudicleFaceShredder::render( void * d )
{
    static t_CKFLOAT x = 0.0;

    glPushMatrix();
    glPushName( m_b1_id );
    glTranslatef( 1.5, -1.1, .1 );
    glColor3f( .25, .75, .25 );
    glRotatef( x, 0.0, 0.0, 1.0 );
    x += .1 ;
    glutWireSphere( sphere_down ? .06 : .075, 15, 15 );
    glPopName();
    glPopMatrix();

    glRotatef( m_eye_y * 100.0, 1.0, 0.0, 0.0 );

    // get shreds from ChucK VM
    AudicleStats::instance()->get_shreds( m_stats, m_done );
    
    Shred_Stat * stat = NULL;
    Shred_Data * data = NULL;
    Color4D c;
    Point3D p, v, a;
    Point3D b;
    t_CKFLOAT theta;

    m_time = AudicleWindow::main()->get_current_time();
    if( m_last_time < 0.0 ) m_last_time = m_time;
    t_CKFLOAT delta = m_time - m_last_time;
    m_last_time = m_time;
    int i;

    // loop through
    for( i = 0; i < m_stats.size(); i++ )
    {
        stat = m_stats[i];
        data = (Shred_Data *)stat->data;
        // initialized?

        if( stat->data == NULL )
        {
            initialize_stat_data ( stat );
        }

        if( stat->data->in_shredder_map == false ) 
        { 
            //this will catch data that have been inited
            //outside the shredder ( like in TNT! ) 
            m_map[stat->data->name] = stat->data;
            stat->data->in_shredder_map = true;
        }        
    }
    
    // loop through
    for( i = 0; i < m_stats.size(); i++ )
    {
        stat = m_stats[i];
        data = (Shred_Data *)stat->data;
        p = data->pos;
        // v = data->vel;
        // a = data->acc;
        // advance
        // v += a * delta;
        theta = stat->average_cycles / 100000.0 + v[0];
        b[0] = cos(theta) * p[0] + sin(theta) * p[1];
        b[1] = -sin(theta) * p[0] + cos(theta) * p[1];
        b[2] = p[2];

        data->pos = b;
        // data->vel = v;
    }

    // loop through
    for( i = 0; i < m_stats.size(); i++ )
    {
        data = (Shred_Data *)m_stats[i]->data;
        if( data->radius < .15 )
            data->radius += .05 * delta;

        for( int j = 0; j < m_stats.size(); j++ )
        {
            Shred_Data * other = (Shred_Data *)m_stats[j]->data;
            if( data == other ) continue;

            t_CKFLOAT norm = ( data->pos - other->pos ).length();
            if( norm < ( data->radius + other->radius + .02 ) )
            {
                Shred_Data * smaller = other->radius < data->radius ? other : data;
                Shred_Data * bigger = smaller == other ? data : other;

                t_CKFLOAT ratio = norm / ( data->radius + other->radius + .02 );
                data->radius *= ratio;
                other->radius *= ratio;
                
                if( smaller->radius < .07 ) smaller->radius = .07;
                if( bigger->radius < .07 ) bigger->radius = .07;
            }
        }
    }

    // loop through
    m_happy.clear();
    map<Shred_Stat *, Shred_Stat *>::iterator iter;
    for( iter = m_done.begin(); iter != m_done.end(); iter++ )
    {
        stat = (*iter).second;
        data = (Shred_Data *)stat->data;
        // data->color.scale( .9 );
        
        if( !data || data->pos[2] > 20.0 )
        {
            if( data ) data->ref_count--;
            m_happy.push_back( stat );
            continue;
        }

        data->x += .0015;
        data->pos[2] += data->x * delta;
        // data->radius -= .1 * delta;
    }
    
    // loop through
    for( i = 0; i < m_happy.size(); i++ )
    {
        m_done.erase( m_done.find( m_happy[i] ) );
    }

    if( which == 1 ) render_1( delta );
    else if( which == 2 ) render_2( delta );
//    else if( which == 3 ) render_3();

    return 0;
}
Пример #2
0
//-----------------------------------------------------------------------------
// Name: WinMain()
// Desc: The application's entry point
//-----------------------------------------------------------------------------
int WINAPI WinMain( HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpCmdLine,
    int nCmdShow )
{
    WNDCLASSEX winClass;
    MSG uMsg;
    bool deviceReset = FALSE;

    memset(&uMsg,0,sizeof(uMsg));
    winClass.lpszClassName = "MY_WINDOWS_CLASS";
    winClass.cbSize = sizeof(WNDCLASSEX);
    winClass.style = CS_HREDRAW | CS_VREDRAW;
    winClass.lpfnWndProc = WindowProc;
    winClass.hInstance = hInstance;
    winClass.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_DIRECTX_ICON);
    winClass.hIconSm = LoadIcon(hInstance, (LPCTSTR)IDI_DIRECTX_ICON);
    winClass.hCursor = LoadCursor(NULL, IDC_ARROW);
    winClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
    winClass.lpszMenuName = NULL;
    winClass.cbClsExtra = 0;
    winClass.cbWndExtra = 0;

    if(!RegisterClassEx( &winClass) )
        return E_FAIL;

    //
    // Create window #0...
    //

    g_hWnd_0 = CreateWindowEx( NULL, "MY_WINDOWS_CLASS",
        "Direct3D (DX9) - Multiple Devices (Window #0)",
        WS_EX_TOPMOST | WS_POPUP, // fullscreen values /* WS_OVERLAPPEDWINDOW | WS_VISIBLE,*/
        0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, NULL, NULL, hInstance, NULL );

    if( g_hWnd_0 == NULL )
        return E_FAIL;

    ShowWindow( g_hWnd_0, nCmdShow );
    UpdateWindow( g_hWnd_0 );

#ifdef TWO
    //
    // Create window #1...
    //
    g_hWnd_1 = CreateWindowEx( NULL, "MY_WINDOWS_CLASS",
        "Direct3D (DX9) - Multiple Devices (Window #1)",
        WS_EX_TOPMOST | WS_POPUP, // fullscreen values /* WS_OVERLAPPEDWINDOW | WS_VISIBLE,*/
        1920, 0, SCREEN_WIDTH, SCREEN_HEIGHT, NULL, NULL, hInstance, NULL );

    if( g_hWnd_1 == NULL )
        return E_FAIL;

    ShowWindow( g_hWnd_1, nCmdShow );
    UpdateWindow( g_hWnd_1 );
#endif
    //
    // Init Direct3D usage on both windows...
    //

    init_0();
#ifdef TWO
    init_1();
#endif

    ResetDevice(); // Important !!!

    LoadModels();

    while( uMsg.message != WM_QUIT )
    {
        if( PeekMessage( &uMsg, NULL, 0, 0, PM_REMOVE ) )
        {
            TranslateMessage( &uMsg );
            DispatchMessage( &uMsg );
        }
        else
        {
            g_dCurrentTime = timeGetTime();
            g_dElpasedFrameTime = g_dCurrentTime - g_dLastTime; // How much time has passed since the last frame?
            g_dElpasedAppTime += g_dElpasedFrameTime; // How much time has passed overall for the application?
            g_dLastTime = g_dCurrentTime;

            render_0();
#ifdef TWO
            render_1();
#endif
        }
    }

    //
    // Cleanup Direct3D usage on both windows...
    //
#ifdef TWO
    shutDown_1();
#endif
    shutDown_0();

    UnregisterClass( "MY_WINDOWS_CLASS", winClass.hInstance );
    return uMsg.wParam;
}