Changeset 1669 for trunk/tutorial


Ignore:
Timestamp:
Jul 26, 2012, 8:22:40 AM (8 years ago)
Author:
sam
Message:

tutorial: use real numbers in the fractal navigation (doubles are still
used in the fractal computation).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tutorial/11_fractal.cpp

    r1647 r1669  
    8787        for (int i = 0; i < 4; i++)
    8888        {
    89             m_deltashift[i] = 0.0;
    90             m_deltascale[i] = 1.0;
     89            m_deltashift[i] = real("0");
     90            m_deltascale[i] = real("1");
    9191            m_dirty[i] = 2;
    9292        }
    9393#if defined __CELLOS_LV2__ || defined _XBOX
    94         //m_center = dcmplx(-.22815528839841, -1.11514249704382);
    95         //m_center = dcmplx(0.001643721971153, 0.822467633298876);
    96         m_center = dcmplx(-0.65823419062254, 0.50221777363480);
     94        //m_center = rcmplx(-.22815528839841, -1.11514249704382);
     95        //m_center = rcmplx(0.001643721971153, 0.822467633298876);
     96        m_center = rcmplx("-0.65823419062254", "0.50221777363480");
    9797        m_zoom_speed = -0.025;
    9898#else
    99         m_center = -0.75;
     99        m_center = rcmplx(-0.75, 0.0);
    100100        m_zoom_speed = 0.0;
    101101#endif
    102         m_translate = 0;
     102        m_translate = rcmplx(0.0, 0.0);
    103103        m_radius = 5.0;
    104104        m_ready = false;
     
    200200        WorldEntity::TickGame(seconds);
    201201
    202         int prev_frame = m_frame;
     202        int prev_frame = (m_frame + 4) % 4;
    203203        m_frame = (m_frame + 1) % 4;
    204204
    205         dcmplx worldmouse = m_center + ScreenToWorldOffset(m_mousepos);
     205        rcmplx worldmouse = m_center + rcmplx(ScreenToWorldOffset(m_mousepos));
    206206
    207207        ivec3 buttons = Input::GetMouseButtons();
     
    221221             * incorrectly because a quarter of the pixels in the image
    222222             * would have tie rankings in the distance calculation. */
    223             m_translate *= 1023.0 / 1024.0;
     223            m_translate *= real(1023.0 / 1024.0);
    224224            m_oldmouse = m_mousepos;
    225225        }
     
    227227        {
    228228            m_drag = false;
    229             if (m_translate != 0.0)
    230             {
    231                 m_translate *= std::pow(2.0, -seconds * 5.0);
    232                 if (m_translate.norm() / m_radius < 1e-4)
    233                     m_translate = 0.0;
     229            if (m_translate != rcmplx(0.0, 0.0))
     230            {
     231                m_translate *= real(std::pow(2.0, -seconds * 5.0));
     232                if ((double)m_translate.norm() < m_radius * 1e-4)
     233                    m_translate = rcmplx(0.0, 0.0);
    234234            }
    235235        }
     
    238238        {
    239239            double zoom = buttons[0] ? -0.5 : 0.5;
    240             m_zoom_speed += seconds * zoom;
     240            m_zoom_speed += zoom * seconds;
    241241            if (m_zoom_speed / zoom > 5e-3f)
    242                 m_zoom_speed = 5e-3f * zoom;
     242                m_zoom_speed = zoom * 5e-3f;
    243243        }
    244244        else if (m_zoom_speed)
     
    250250#endif
    251251
    252         if (m_zoom_speed || m_translate != 0.0)
    253         {
    254             dcmplx oldcenter = m_center;
     252        if (m_zoom_speed || m_translate != rcmplx(0.0, 0.0))
     253        {
     254            rcmplx oldcenter = m_center;
    255255            double oldradius = m_radius;
    256256            double zoom = std::pow(2.0, seconds * 1e3f * m_zoom_speed);
     
    268268#if !defined __CELLOS_LV2__ && !defined _XBOX
    269269            m_center += m_translate;
    270             m_center = (m_center - worldmouse) * zoom + worldmouse;
    271             worldmouse = m_center + ScreenToWorldOffset(m_mousepos);
     270            m_center = (m_center - worldmouse) * real(zoom) + worldmouse;
     271            worldmouse = m_center + rcmplx(ScreenToWorldOffset(m_mousepos));
    272272#endif
    273273
    274274            /* Store the transformation properties to go from m_frame - 1
    275275             * to m_frame. */
    276             m_deltashift[prev_frame] = (m_center - oldcenter) / oldradius;
     276            m_deltashift[prev_frame] = (m_center - oldcenter) / real(oldradius);
    277277            m_deltashift[prev_frame].x /= m_size.x * m_texel2world.x;
    278278            m_deltashift[prev_frame].y /= m_size.y * m_texel2world.y;
     
    284284            /* If settings didn't change, set transformation from previous
    285285             * frame to identity. */
    286             m_deltashift[prev_frame] = 0.0;
    287             m_deltascale[prev_frame] = 1.0;
     286            m_deltashift[prev_frame] = real::R_0;
     287            m_deltascale[prev_frame] = real::R_1;
    288288        }
    289289
     
    300300            int cur_index = (m_frame + 3 - i) % 4;
    301301
    302             m_zoom_settings[cur_index][0] = m_zoom_settings[prev_index][0] * m_deltascale[cur_index] + m_deltashift[cur_index].x;
    303             m_zoom_settings[cur_index][1] = m_zoom_settings[prev_index][1] * m_deltascale[cur_index] + m_deltashift[cur_index].y;
    304             m_zoom_settings[cur_index][2] = m_zoom_settings[prev_index][2] * m_deltascale[cur_index];
     302            m_zoom_settings[cur_index][0] = (real)m_zoom_settings[prev_index][0] * m_deltascale[cur_index] + m_deltashift[cur_index].x;
     303            m_zoom_settings[cur_index][1] = (real)m_zoom_settings[prev_index][1] * m_deltascale[cur_index] + m_deltashift[cur_index].y;
     304            m_zoom_settings[cur_index][2] = (real)m_zoom_settings[prev_index][2] * m_deltascale[cur_index];
    305305        }
    306306
     
    313313
    314314#if !defined __native_client__
    315         char buf[128];
    316         sprintf(buf, "center: %+16.14f%+16.14fi", m_center.x, m_center.y);
     315        char buf[256];
     316        sprintf(buf, "center: ");
     317        m_center.x.sprintf(buf + strlen(buf), 30);
     318        sprintf(buf + strlen(buf), " ");
     319        m_center.y.sprintf(buf + strlen(buf), 30);
    317320        m_centertext->SetText(buf);
    318         sprintf(buf, " mouse: %+16.14f%+16.14fi", worldmouse.x, worldmouse.y);
     321        sprintf(buf, " mouse: ");
     322        worldmouse.x.sprintf(buf + strlen(buf), 30);
     323        sprintf(buf + strlen(buf), " ");
     324        worldmouse.y.sprintf(buf + strlen(buf), 30);
    319325        m_mousetext->SetText(buf);
    320326        sprintf(buf, "  zoom: %g", 1.0 / m_radius);
     
    359365                             + m_size.x * (m_size.y / 4 * m_frame + line / 4);
    360366
     367        dcmplx c = (dcmplx)m_center;
     368
    361369        for (int j = jmin; j < jmax; j += 2)
    362370        for (int i = m_frame % 2; i < m_size.x; i += 2)
    363371        {
    364             dcmplx z0 = m_center + TexelToWorldOffset(ivec2(i, j));
     372            dcmplx z0 = c + TexelToWorldOffset(ivec2(i, j));
    365373            dcmplx z1, z2, z3, r0 = z0;
    366374            //dcmplx r0(0.28693186889504513, 0.014286693904085048);
     
    588596    bool m_ready, m_drag;
    589597
    590     dcmplx m_center, m_translate;
     598    rcmplx m_deltashift[4], m_center, m_translate;
     599    real m_deltascale[4];
    591600    double m_zoom_speed, m_radius;
     601
    592602    vec4 m_texel_settings, m_screen_settings;
    593603    mat4 m_zoom_settings;
    594     dcmplx m_deltashift[4];
    595     double m_deltascale[4];
    596604
    597605    /* Worker threads */
Note: See TracChangeset for help on using the changeset viewer.