Example #1
0
void CRenderer::DrawScene(const CFrustum& frustum,
                          CWorld* world,
                          int localctrlid,
                          bool generateShadowMap)
{
    CObj* obj;
    OBJITER iter;

    // Draw the level
    if(!generateShadowMap && world->GetBSP()->IsLoaded())
    {
        // Draw the level with lightmapping?
        if(m_lightmapactive && m_shaderactive)
            glUniform1i(m_uselightmap, 1);

        world->GetBSP()->RenderGL(frustum.pos, frustum);

        if(m_shaderactive)
            glUniform1i(m_uselightmap, 0);
    }

    // Draw every object
    for(iter=world->ObjBegin();iter!=world->ObjEnd();++iter)
    {
        obj = (*iter).second;

        if((obj->GetFlags() & OBJ_FLAGS_GHOST) || // ghosts are invisible - duh
            obj->GetID() == localctrlid || // don't draw the player object
           !obj->GetMesh()) // object has no md5 model
            continue;

        // check if object is in view frustum
        if(!generateShadowMap && !frustum.TestSphere(obj->GetOrigin(), obj->GetRadius()))
            continue;

        glPushMatrix();
        glTranslatef(obj->GetOrigin().x, obj->GetOrigin().y, obj->GetOrigin().z);
        glTranslatef(0.0f, -obj->GetRadius(), 0.0f);
        glMultMatrixf(obj->GetRotMatrix()->pm);

        obj->GetMesh()->Render(obj->GetMeshState());
#ifdef DRAW_NORMALS
        obj->GetMesh()->RenderNormals(obj->GetMeshState()); // not implemented for md2s?
#endif
        glPopMatrix();
    }
}
Example #2
0
File: Mixer.cpp Project: jnz/Lynx
void CMixer::Update(const float dt, const uint32_t ticks)
{
    OBJITER iter;
    CObj* obj;
    bool success;

    for(iter=m_world->ObjBegin();iter!=m_world->ObjEnd();iter++)
    {
        obj = (*iter).second;

        if(obj->GetSound() && !obj->GetSoundState()->is_playing)
        {
            success = obj->GetSound()->Play(obj->GetSoundState());

            CObj* localplayer = m_world->GetLocalObj();
            if(success && localplayer)
            {
                // Distance to sound source
                const vec3_t diff = localplayer->GetOrigin() - obj->GetOrigin();
                const float dist = std::min(diff.Abs(), SOUND_MAX_DIST);
                int volume = (int)(dist*255/SOUND_MAX_DIST);
                if(volume > 255)
                    volume = 255;

                uint16_t angle; // 0-360 deg. for Mix_SetPosition
                vec3_t playerlook; // player is looking in this direction
                float fAlpha; // riwi to sound source
                float fBeta; // riwi look dir
                m_world->GetLocalController()->GetDir(&playerlook, NULL, NULL);

                fAlpha = atan2(diff.x, -diff.z);
                fBeta = atan2(playerlook.x, -playerlook.z);
                angle = (uint16_t)((fAlpha - fBeta)*180/lynxmath::PI);
                Mix_SetPosition(obj->GetSoundState()->cur_channel,
                                angle, (uint8_t)volume);
            }
        }
    }
}