Changeset 1368


Ignore:
Timestamp:
May 12, 2012, 11:36:39 AM (7 years ago)
Author:
sam
Message:

orbital: more snakes, with tails!

Location:
trunk/orbital
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/orbital/orbital.cpp

    r1367 r1368  
    115115    m_snakes.Push(new Snake(3));
    116116    Ticker::Ref(m_snakes.Last());
    117     m_snakes.Push(new Snake(15));
     117    m_snakes.Push(new Snake(8));
     118    Ticker::Ref(m_snakes.Last());
     119    m_snakes.Push(new Snake(25));
    118120    Ticker::Ref(m_snakes.Last());
    119121
  • trunk/orbital/snake.h

    r1367 r1368  
    2626        m_body.SendCommand("sc1,1,1,1,afcb.4,.4,7,.4,tx8,mx,fl");
    2727
    28         m_position = vec3(RandF(-250.f, -350.f), 20.f, RandF(250.f, 350.f));
     28        m_tail.SendCommand("sc1,1,1,1,afcb6,6,10,1,tz-1,fl");
     29        m_tail.SendCommand("sc.9,.6,.1,1,afcb3,15,3,.8,ty8,fl");
     30        m_tail.SendCommand("sc1,1,1,1,afcb.4,.4,8,.4,tz-1,ty8,fl");
     31        m_tail.SendCommand("sc1,1,1,1,afcb.4,.4,8,.4,tz-1,ty12,fl");
     32        m_tail.SendCommand("sc.9,.6,.1,1,afcb15,3,3,.8,tx8,fl");
     33        m_tail.SendCommand("sc1,1,1,1,afcb.4,.4,8,.4,tz-1,tx8,fl");
     34        m_tail.SendCommand("sc1,1,1,1,afcb.4,.4,8,.4,tz-1,tx12,fl");
     35
     36        m_position = vec3(RandF(0.f, 100.f), 20.f, RandF(150.f, 250.f));
    2937        m_rotation = quat::rotate(RandF(30.f, 70.f), 0.f, 1.f, 0.f);;
    3038
     39        /* The last node is actually the tail */
    3140        for (int i = 0; i < nodes; i++)
    3241            m_nodes.Push(vec3(0.f, 0.f, 0.f), 0.f);
     42        m_nodes.Push(vec3(0.f, 0.f, 0.f), 45.f);
    3343    }
    3444
     
    4555
    4656        m_steer += 2.f * seconds;
    47         float test = sinf(m_steer) * 120.f;
     57        float test = sinf(m_steer) * 100.f + 20.f;
    4858        m_rotation *= quat::rotate(seconds * test, vec3(0, 1, 0));
    4959
     
    5464        for (int i = 0; i < m_nodes.Count(); i++)
    5565        {
     66            /* The current node is dragged by the previous one */
    5667            vec3 newdelta = m_nodes[i].m1 - deltapos;
    5768            if (dot(newdelta, newdelta) > 12.f * 12.f)
     
    5970            deltapos = newdelta + deltapos - m_nodes[i].m1;
    6071            m_nodes[i].m1 = newdelta;
    61             m_nodes[i].m2 += seconds * ((i & 1) ? 200.f : -200.f);
     72
     73            /* If the current node is not the tail, rotate */
     74            if (i != m_nodes.Count() - 1)
     75                m_nodes[i].m2 += seconds * ((i & 1) ? 200.f : -200.f);
    6276        }
    6377    }
     
    7185            m_head.SendCommand("irb");
    7286            m_body.SendCommand("irb");
     87            m_tail.SendCommand("irb");
    7388            m_ready = true;
    7489        }
     
    7691        vec3 pos = m_position;
    7792        quat rot = m_rotation;
     93        float y_angle = 0.f;
    7894        mat4 model = mat4::translate(pos) * mat4(rot);
    7995        m_head.Render(model);
     
    8298        {
    8399            pos += m_nodes[i].m1;
    84             float angle = (180.f / M_PI) * atan2(m_nodes[i].m1.x, m_nodes[i].m1.z);
    85             rot = quat::rotate(angle, 0.f, 1.f, 0.f)
     100            y_angle = (180.f / M_PI) * atan2(m_nodes[i].m1.x, m_nodes[i].m1.z);
     101            rot = quat::rotate(y_angle, 0.f, 1.f, 0.f)
    86102                * quat::rotate(m_nodes[i].m2, 0.f, 0.f, 1.f);
    87103            model = mat4::translate(pos) * mat4(rot);
    88             m_body.Render(model);
     104            if (i != m_nodes.Count() - 1)
     105                m_body.Render(model);
     106            else
     107                m_tail.Render(model);
    89108        }
    90109    }
    91110
    92111private:
    93     Mesh m_head, m_body;
     112    Mesh m_head, m_body, m_tail;
    94113    float m_steer;
    95114    /* List of nodes (position, self-rotation angle) */
Note: See TracChangeset for help on using the changeset viewer.