示例#1
0
void CameraFPS::update(){

	if(m_bForward){
		pos.x()+=m_fSpeed*direct.x();
		pos.y()+=m_fSpeed*direct.y();
		pos.z()+=m_fSpeed*direct.z();
	}

	if(m_bLeft){
		pos.x()+=m_fSpeed*right.x();
		pos.z()+=m_fSpeed*right.z();	
	}

	if(m_bRight){
		pos.x()-=m_fSpeed*right.x();
		pos.z()-=m_fSpeed*right.z();
	}

	if(m_bBackward){
		pos.x()-=m_fSpeed*direct.x();
		pos.y()-=m_fSpeed*direct.y();
		pos.z()-=m_fSpeed*direct.z();	
	}

	vectorsFromAngles();
}
示例#2
0
FreeCam::FreeCam()
{
    _speed = 2.5;
    _phi = 0;
    _theta = 88;
    _sensivity = 0.4;
    _target = _forward;
    vectorsFromAngles();
}
示例#3
0
void FreeCam::update(gdl::Input& input, const gdl::Clock& clock)
{
    float delta;

    delta = static_cast<float>(clock.getElapsed());

    glm::ivec2 motion = input.getMouseDelta();
    _theta += (_sensivity * static_cast<float>(motion.x));
    _phi -= (_sensivity * static_cast<float>(motion.y));
    vectorsFromAngles();

    moveCam(input, delta);
}
示例#4
0
void CameraFPS::updateMouse(int x, int y){
	
	alpha+=(windowwidth/2.0-x)*vitesseSouris;
	phi+=(windowheight/2.0-y)*vitesseSouris;

	if(phi>-1)
	{
		phi=-1;
	}
	if(phi<-179)
	{
		phi=-179;
	}
		/*  */
	if(alpha>360 || alpha < -360) alpha=0.0;

	vectorsFromAngles();
}
示例#5
0
void CameraFPS::init()
{
	AbstractCamera::init();
	m_fSpeed = 0.2;

	vitesseSouris = 0.1f;

	pos.x() = 0;
	pos.y() = 9.4;
	pos.z() = 5.0;

	alpha=0;
	phi=-90;

	m_bForward = m_bBackward = m_bLeft = m_bRight = false;

	vectorsFromAngles();

}
示例#6
0
void CCameraFreeFly::onEvent(const CMouseEvent& event)
{
    m_theta -= event.xrel * MOUSE_MOTION_SPEED;
    m_phi   -= event.yrel * MOUSE_MOTION_SPEED;
    vectorsFromAngles();

    if (event.type == ButtonPressed || event.type == ButtonReleased)
    {
        // Coup de molette vers le haut
        if (event.button == MouseWheelUp)
        {
            m_timeVerticalMotion = VerticalMotionTime;
            m_verticalMotionDirection = 1;

        }
        // Coup de molette vers le bas
        else if (event.button == MouseWheelDown)
        {
            m_timeVerticalMotion = VerticalMotionTime;
            m_verticalMotionDirection = -1;
        }
    }
}
示例#7
0
void CCameraFreeFly::animate(unsigned int frameTime)
{
    TVector3F new_position = m_position;

    // Déplacement vers l'avant
    if (CApplication::getApp()->isActionActive(ActionForward))
    {
        new_position += m_forward * CameraFreeFlyVelocity * frameTime;
    }

    // Déplacement vers l'arrière
    if (CApplication::getApp()->isActionActive(ActionBackward))
    {
        new_position -= m_forward * CameraFreeFlyVelocity * frameTime;
    }

    // Déplacement vers la gauche
    if (CApplication::getApp()->isActionActive(ActionStrafeLeft))
    {
        new_position += m_left * CameraFreeFlyVelocity * frameTime;
    }

    // Déplacement vers la droite
    if (CApplication::getApp()->isActionActive(ActionStrafeRight))
    {
        new_position -= m_left * CameraFreeFlyVelocity * frameTime;
    }

    // Rotation vers la gauche
    if (CApplication::getApp()->isActionActive(ActionTurnLeft))
    {
        m_theta += frameTime * MOUSE_MOTION_SPEED;
        vectorsFromAngles();
    }

    // Rotation vers la droite
    if (CApplication::getApp()->isActionActive(ActionTurnRight))
    {
        m_theta -= frameTime * MOUSE_MOTION_SPEED;
        vectorsFromAngles();
    }

    // Déplacement vertical
    if (m_verticalMotionDirection)
    {
        new_position += TVector3F(0.0f, 0.0f, m_verticalMotionDirection * CameraFreeFlyVelocity * frameTime);

        if (frameTime > m_timeVerticalMotion)
        {
            m_verticalMotionDirection = 0;
        }
        else
        {
            m_timeVerticalMotion -= frameTime;
        }
    }

    // Zoom
    if (CApplication::getApp()->isActionActive(ActionZoom))
    {
        if (m_zoom > frameTime)
        {
            m_zoom -= frameTime;
        }
        else if (m_zoom > 0)
        {
            m_zoom = 0;
        }
    }
    else
    {
        if (m_zoom + frameTime < ZOOM_TIME)
        {
            m_zoom += frameTime;
        }
        else if (m_zoom < ZOOM_TIME)
        {
            m_zoom = ZOOM_TIME;
        }
    }

    // La caméra n'a pas bougé
    if (m_position == new_position)
    {
        return;
    }

#ifdef T_CAMERA_FREEFLY_COLLISION

    T_ASSERT(m_sphere != nullptr);

    if (m_collisions)
    {
        // Déplacement du volume englobant
        CPhysicEngine::Instance().slide(*m_sphere, new_position - m_position);
        m_position = m_sphere->getPosition();
    }
    else
#endif
    {
        m_position = new_position;
#ifdef T_CAMERA_FREEFLY_COLLISION
        m_sphere->setPosition(m_position);
#endif
    }

    m_direction = m_position + m_forward;
}