Changeset 1364


Ignore:
Timestamp:
May 10, 2012, 10:02:12 PM (11 years ago)
Author:
sam
Message:

orbital: simplify starfield.

Location:
trunk/orbital
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/orbital/orbital.cpp

    r1363 r1364  
    9090    //Ticker::Ref(m_particlesystem);
    9191
    92     m_starfield = new StarField(100, 100, 1.f, 2.f, 10.f, 20.f);
    93     Ticker::Ref(m_starfield);
     92    m_small_stars = new StarField(100, 1.f, 20.f);
     93    Ticker::Ref(m_small_stars);
     94    m_large_stars = new StarField(100, 2.f, 10.f);
     95    Ticker::Ref(m_large_stars);
    9496
    9597    /* Create a camera that matches the settings of XNA Orbital */
     
    190192    }
    191193
    192     Video::SetClearColor(vec4(0.0f, 0.0f, 0.0f, 1.0f));
     194    Video::SetClearColor(vec4(0.0f, 0.0f, 0.12f, 1.0f));
    193195
    194196    m.Render(m_model);
     
    202204        Ticker::Unref(m_players[i]);
    203205    //Ticker::Unref(m_particlesystem);
    204     Ticker::Unref(m_starfield);
     206    Ticker::Unref(m_small_stars);
     207    Ticker::Unref(m_large_stars);
    205208    Ticker::Unref(m_camera);
    206209}
  • trunk/orbital/orbital.h

    r1363 r1364  
    3333
    3434    ParticleSystem *m_particlesystem;
    35     StarField *m_starfield;
     35    StarField *m_small_stars, *m_large_stars;
    3636    Camera *m_camera;
    3737    Array<Player *> m_players;
  • trunk/orbital/starfield.h

    r1363 r1364  
    1313{
    1414public:
    15     StarField(int count3, int count4, float z3, float z4, float speed3, float speed4)
     15    StarField(int count, float z, float speed)
    1616      : m_ready(false)
    1717    {
    18         m_star3_mesh.SendCommand("sc1,1,1,1,scb1,1,1,0,ad4,1.8,1");
    19         m_star4_mesh.SendCommand("sc1,1,1,1,scb1,1,1,0,ad3,0.8,1");
     18        if (z == 1.f)
     19            m_mesh.SendCommand("sc1,1,1,1,scb1,1,1,0,ad4,1.8,1");
     20        else
     21            m_mesh.SendCommand("sc1,1,1,1,scb1,1,1,0,ad3,0.8,1");
    2022
    21         for (int i = 0; i < count3; i++)
    22             m_star3.Push(vec3(RandF(800.f) - 400.f, z3, RandF(600.f) - 300.f),
    23                          vec3(0.f, 0.f, speed3),
    24                          RandF(0.f, 10.f));
    25 
    26         for (int i = 0; i < count4; i++)
    27             m_star4.Push(vec3(RandF(800.f) - 400.f, z4, RandF(600.f) - 300.f),
    28                          vec3(0.f, 0.f, speed4),
     23        for (int i = 0; i < count; i++)
     24            m_stars.Push(vec3(RandF(440.f) - 220.f, z, RandF(600.f) - 300.f),
     25                         vec3(0.f, 0.f, speed),
    2926                         RandF(0.f, 10.f));
    3027    }
     
    3431    }
    3532
    36     char const *GetName() { return "<particlesystem>"; }
     33    char const *GetName() { return "<starfield>"; }
    3734
    3835protected:
     
    4138        WorldEntity::TickGame(seconds);
    4239
    43         for (int i = 0; i < m_star3.Count(); i++)
     40        for (int i = 0; i < m_stars.Count(); i++)
    4441        {
    45             m_star3[i].m3 += 10.f * seconds;
    46             m_star3[i].m1 += seconds * m_star3[i].m2;
    47             if (m_star3[i].m1.z > 300.f)
    48                 m_star3[i].m1.z = -300.f;
    49         }
    50 
    51         for (int i = 0; i < m_star4.Count(); i++)
    52         {
    53             m_star4[i].m3 += 10.f * seconds;
    54             m_star4[i].m1 += seconds * m_star4[i].m2;
    55             if (m_star4[i].m1.z > 300.f)
    56                 m_star4[i].m1.z = -300.f;
     42            m_stars[i].m3 += 10.f * seconds;
     43            m_stars[i].m1 += seconds * m_stars[i].m2;
     44            if (m_stars[i].m1.z > 300.f)
     45            {
     46                m_stars[i].m1.x = RandF(440.f) - 220.f;
     47                m_stars[i].m1.z = -300.f;
     48            }
    5749        }
    5850    }
     
    6456        if (!m_ready)
    6557        {
    66             m_star3_mesh.SendCommand("irb");
    67             m_star4_mesh.SendCommand("irb");
     58            m_mesh.SendCommand("irb");
    6859            m_ready = true;
    6960        }
    7061
    71         for (int i = 0; i < m_star3.Count(); i++)
     62        for (int i = 0; i < m_stars.Count(); i++)
    7263        {
    73             mat4 model = mat4::translate(m_star3[i].m1)
    74                        * mat4::rotate(m_star3[i].m3, 0.f, 1.f, 0.f);
     64            mat4 model = mat4::translate(m_stars[i].m1)
     65                       * mat4::rotate(m_stars[i].m3, 0.f, 1.f, 0.f);
    7566
    76             m_star3_mesh.Render(model);
    77         }
    78 
    79         for (int i = 0; i < m_star4.Count(); i++)
    80         {
    81             mat4 model = mat4::translate(m_star4[i].m1)
    82                        * mat4::rotate(m_star4[i].m3, 0.f, 1.f, 0.f);
    83 
    84             m_star4_mesh.Render(model);
     67            m_mesh.Render(model);
    8568        }
    8669    }
    8770
    8871private:
    89     Mesh m_star3_mesh, m_star4_mesh;
    90     Array<vec3, vec3, float> m_star3, m_star4;
     72    Mesh m_mesh;
     73    Array<vec3, vec3, float> m_stars;
    9174    bool m_ready;
    9275};
Note: See TracChangeset for help on using the changeset viewer.