예제 #1
0
void PlayerInterface3D :: logic(Freq::Time t)
{
    auto n = node();
    auto in = controller();
    auto m = in->input()->mouse_rel();

    const float sens = 0.001f * m_Sens;

    auto p = n->position();
    n->position(glm::vec3());
    n->rotate(m.x * sens, glm::vec3(0.0f, -1.0f, 0.0f), Space::PARENT);
    n->position(p);
    
    if(not m_bLockPitch)
        n->rotate(m.y * sens, glm::vec3(-1.0f, 0.0f, 0.0f));

    auto mag = glm::length(m_Move);
    if(mag > 0.1f) {
        auto vert_movement = m_Move.y;
        auto move = vec3(m_Move.x, 0.0f, m_Move.z);
        auto xz_mag = glm::length(move);
        if(xz_mag > 0.1) {
            
            move = glm::normalize(move) * mag;
            if(!m_bFly) {
                auto old_y = n->position().y;
                n->move(move * t.s(), Space::LOCAL);
                n->position(vec3(n->position().x, old_y, n->position().z));
            }
            else
                n->move(move * t.s(), Space::LOCAL);
        }
        n->move(vec3(0.0f, vert_movement, 0.0f) * t.s());
    }
}
예제 #2
0
파일: BasicState.cpp 프로젝트: tbhdwx/qor
void BasicState :: logic(Freq::Time t)
{
    if(m_pInput->key(SDLK_ESCAPE))
        m_pQor->quit();

    float speed = 1000.0f * t.s();
    //if(m_pInput->key(SDLK_r))
    //{
    //    *m_pCamera->matrix() = glm::scale(
    //        *m_pCamera->matrix(), glm::vec3(1.0f-t.s(), 1.0f-t.s(), 1.0f)
    //    );
    //    m_pCamera->pend();
    //}
    //if(m_pInput->key(SDLK_w))
    //{
    //    *m_pCamera->matrix() = glm::scale(
    //        *m_pCamera->matrix(), glm::vec3(1.0f+t.s(), 1.0f+t.s(), 1.0f)
    //    );
    //    m_pCamera->pend();
    //}

    if(m_pInput->key(SDLK_UP))
        m_pCamera->move(glm::vec3(0.0f, -speed, 0.0f));
    if(m_pInput->key(SDLK_DOWN))
        m_pCamera->move(glm::vec3(0.0f, speed, 0.0f));
    
    if(m_pInput->key(SDLK_LEFT))
        m_pCamera->move(glm::vec3(-speed, 0.0f, 0.0f));
    if(m_pInput->key(SDLK_RIGHT))
        m_pCamera->move(glm::vec3(speed, 0.0f, 0.0f));

    m_pRoot->logic(t);
}
예제 #3
0
파일: Particle.cpp 프로젝트: flipcoder/qor
void Particle :: logic_self(Freq::Time t)
{
    if(not m_Unit.life) {
        // should've been detach already, assume life is unlimited?
        return;
    }
    
    m_Unit.life = Freq::Time::ms(std::max(0, (int)m_Unit.life.ms() - (int)t.ms()));
    if(not m_Unit.life)
        detach();
}
예제 #4
0
파일: Node.cpp 프로젝트: dreamsxin/qor
void Node :: logic(Freq::Time t)
{
    if(m_bDetach) {
        detach();
        return;
    }
    auto self(shared_from_this()); // protect on_tick detach() calls killing pointer
    Actuation::logic(t);
    if(self.unique())
        return;
    kit::clear(self);
    
    logic_self(t);

    glm::vec3 new_vel;
    bool accel = false;
    if(m_Acceleration != glm::vec3(0.0f)){
        new_vel = m_Velocity;
        m_Velocity += m_Acceleration/2.0f * t.s();
        accel = true;
        new_vel += m_Acceleration * t.s();
    }
    
    if(m_Velocity != glm::vec3(0.0f)) {
        //clear_snapshots();
        //snapshot();
        move(m_Velocity * t.s());
    }

    if(accel)
        m_Velocity = new_vel;
    
    m_ChildrenCopy = m_Children;
    for(const auto& c: m_ChildrenCopy)
        c->logic(t);
    m_ChildrenCopy.clear();
}
예제 #5
0
파일: Physics.cpp 프로젝트: tbhdwx/qor
void Physics :: logic(Freq::Time advance)
{
    static float accum = 0.0f;
    const float fixed_step = 1/60.0f;
    float timestep = advance.s();

    accum += timestep;
    while(accum >= fixed_step)
    {
        
        m_pWorld->stepSimulation(fixed_step, NUM_SUBSTEPS);
        //NewtonUpdate(m_pWorld, fixed_step);
        sync(m_pRoot, SYNC_RECURSIVE);
//#ifdef _NEWTON_VISUAL_DEBUGGER
//        NewtonDebuggerServe(m_pDebugger, m_pWorld);
//#endif
        accum -= fixed_step;
    }
}
예제 #6
0
파일: ViewModel.cpp 프로젝트: NickYang/qor
void ViewModel :: logic_self(Freq::Time t)
{
    Tracker::logic_self(t);
    auto targ = target();
    
    if(not targ)
        return;
    
    position(targ->position(Space::WORLD));
    
    m_ZoomAnim.logic(t);
    m_SprintLowerAnim.logic(t);
    m_SprintRotateAnim.logic(t);
    m_ZoomFOVAnim.logic(t);
    m_RecoilAnim.logic(t);
    m_EquipAnim.logic(t);

    m_pNode->position(
        m_ZoomAnim.get() +
        glm::vec3(0.0f, m_SprintLowerAnim.get() + m_EquipAnim.get(), 0.0f));
    m_pCamera->fov(m_ZoomFOVAnim.get());
    m_pNode->reset_orientation();
    m_pNode->rotate(m_SprintRotateAnim.get(), Axis::Y);
    
    m_SwayOffset = glm::vec3(0.0f);
    if(m_bSway && not m_bZoomed)
    {
        m_SwayTime += t.s();
        const float SwaySpeed = 1.0f;
        m_SwayTime -= trunc(m_SwayTime);
        m_SwayOffset = glm::vec3(
            -0.01f * sin(m_SwayTime * SwaySpeed * K_TAU),
            0.005f * cos(m_SwayTime * SwaySpeed * 2.0f * K_TAU),
            0.01f * -sin(m_SwayTime * SwaySpeed * 2.0f * K_TAU)
        );
    }
    m_SwayOffset += glm::vec3(
        0.0f, 0.0f, m_RecoilAnim.get()
    );
    m_pNode->move(m_SwayOffset);
}
예제 #7
0
void LoadingState :: logic(Freq::Time t)
{
    Actuation::logic(t);
    m_pCamera->ortho(true);
    m_pPipeline->winding(false);
    m_pPipeline->blend(false);

    if(m_pInput->escape())
        m_pQor->quit();
    
    m_Fade.logic(t);
    m_pRoot->logic(t);
    
    //m_pPipeline->shader(1)->use();
    int fade = m_pPipeline->shader(1)->uniform("LightAmbient");
    if(fade != -1)
        m_pPipeline->shader(1)->uniform(
            fade,
            m_Fade.get().vec4()
        );
    m_pQor->do_tasks();
    
    // Loading screen fade style?
    if(m_pLogo)
        if(m_bFade){
            m_pPipeline->bg_color(m_Fade.get());
            
            Matrix::rescale(*m_pLogo->matrix(), m_Fade.get().r());
            m_pLogo->pend();
        }
    
    if(m_pMusic) {
        m_pMusic->source()->gain = m_Fade.get().r();
        m_pMusic->source()->refresh();
    }

    *m_pWaitIcon->matrix() *= rotate(
        t.s() * float(K_TAU),
        vec3(0.0f, 0.0f, -1.0f)
    );
    m_pWaitIcon->position(vec3(
        m_pWaitIcon->position().x,
        (m_pWindow->size().y * 1.0f/8.0f) * m_Fade.get().r(),
        m_pWaitIcon->position().z
    ));
    m_pWaitIcon->pend();

    if(m_pQor->state(1)->finished_loading()) {
        if(m_Fade.elapsed()) {
            if(m_Fade.get() == Color::white())
            {
                m_Fade.frame(Frame<Color>(
                    Color::black(),
                    Freq::Time::seconds(0.5f),
                    INTERPOLATE(out_sine<Color>)
                ));
            }
            else
            {
                m_pPipeline->shader(1)->uniform(
                    m_pPipeline->shader(1)->uniform("LightAmbient"),
                    Color::white().vec4()
                );
                m_pQor->pop_state();
            }
        }
    }
}