Пример #1
0
void COwnCharPlayer::setDifference(const Vector2 &dif)
{
    m_difference = dif;
    if( (m_difference.squaredLength() > getWalkSpeed() * getWalkSpeed()) && !m_blocked )
    {
        setPosition(getPosition2() - m_difference);
        m_difference = Vector2::ZERO;
        CWorld::instance()->getWorldContext()->sendCoords(getPosition2(),getRotation(),0);
//		CClientApp::instance()->getWorldConn()->sendCoords(getPosition2(),getRotation(),0);
        /// We must begin new move after this
        m_stop = true;
        m_blocked = true;
        m_sinceLastSendPos = 0;
        m_rotated = false;
    };
};
Пример #2
0
void ball::doPhysics(float dt)
{
	//Euler integration

	//F = M*A
	float inverseMass=0.1f;
	vector2f acc(m_cForce*inverseMass);
	vector2f vel(acc*dt);

	m_cVelocity = m_cVelocity+vel;
	vector2f pos(getPosition2());
	auto displacement = m_cVelocity*dt;
	pos = pos + m_cVelocity;

	m_cVelocity=m_cVelocity*0.9f;	//decipate the accumulated velocity over a period of time.
	clearForce();

	setPosition(pos);
}
Пример #3
0
void COwnCharPlayer::update(Real time)
{
    Vector3 normal = PagingLandScapeData2DManager::getSingleton().getNormal(getPosition().x,getPosition().z);
    if( normal.y < 0.1 )
    {
        Vector2 prevPos2(m_prevPosition.x,m_prevPosition.z);
        Vector2 diff2 = getPosition2() - prevPos2;
        Vector2 norm2 = getVectorForPair(prevPos2,getPosition2());
        if( Vector2(normal.x,normal.z).dotProduct(getPosition2() - prevPos2) < 0 )
        {
            Vector2 position2 = prevPos2 + diff2 - norm2 * diff2.dotProduct(norm2);
            normal = PagingLandScapeData2DManager::getSingleton().getNormal(position2.x,position2.y);
            if( normal.y < 0.1 )
                setPosition(m_prevPosition);
            else
                setPosition(position2);
        }
    }
    m_prevPosition = getPosition();
    if( !m_walk && !m_sinceLastSendPos && !m_rotated)
        m_stop = true;
    else
    {
        if( m_stop )
        {
            ///Send to server that we started walk
            CWorld::instance()->getWorldContext()->sendCoords(getPosition2(),m_rotation,0);
//			CClientApp::instance()->getWorldConn()->sendCoords(getPosition2(),m_rotation,0);
            m_sinceLastSendPos = 0;
            m_rotated = false;
            m_stop = false;
            m_blocked = false;
        };
        m_sinceLastSendPos += time;
        if( m_sinceLastSendPos > 0.450 || ( m_rotated && m_walk && m_sinceLastSendPos >= 0.100 ))
        {
            uint t = static_cast<uint>(m_sinceLastSendPos * 1000);
            /// Send our position to server
            if( t > 500 )
                t = 500;
            CWorld::instance()->getWorldContext()->sendCoords(getPosition2(),m_rotation,t);
//			CClientApp::instance()->getWorldConn()->sendCoords(getPosition2(),m_rotation,t);
            m_sinceLastSendPos = 0;
            m_rotated = false;
        };
        /// Compute correction
        if( !m_difference.isZeroLength() )
        {
            /// Originally (m_rotation == 0) we turned to (0,-1)
            /// Correction is minus projection of m_difference to move direction
            ///
            ///  -y
            ///  ^
            ///  |
            ///  |
            ///  |------> x
            ///  |
            ///  |
            ///  V
            ///  y(z in 3d)
            /// correction = -m_difference * direction = -m_difference * (-sin(m_rotation),-cos(m_rotation))
            m_correction = m_difference.dotProduct(Vector2(Math::Sin(m_rotation,true),Math::Cos(m_rotation,true)));
        } else
            m_correction = 0;
    }
    CCharPlayer::update(time);
};
Пример #4
0
    glm::vec2 Line::getNormal() const {
        float dx = getPosition2().x - getPosition1().x;
        float dy = getPosition2().y - getPosition1().y;

        return glm::normalize(glm::vec2(-dy, dx));
    }