Example #1
0
void Camera3::Walk(const double dt)
{
	//since -dt denotes backwards, vel is negative and -vel * -dt = positive result, so will when intent is to move back pos moves forward
	//therfore dt for backward pass in -dt, to negate the (-dt) parameter
	/* move forward */
	if(dt > 0)	//forward
	{
		walkMovingForward = true;
		walkMovingBackward = false;
	}
	else
	{
		walkMovingBackward = true;
		walkMovingForward = false;
	}

	/* update vel */
	movingVelocity += moveAcceleration * dt;

	/* cap vel */
	if(movingVelocity > CAMERA_MAX_VELOCITY)
		movingVelocity = CAMERA_MAX_VELOCITY;
	else if(movingVelocity < -CAMERA_MAX_VELOCITY)
		movingVelocity = -CAMERA_MAX_VELOCITY;
	
	if(dt >= 0)
		MoveForward(dt);
	else if(dt < 0)
		MoveBackward(-dt);	
}
Example #2
0
/********************************************************************************
Walk forward or backward. You can add in a deadzone here.
********************************************************************************/
void TPCamera::Walk(const double dt)
{
	if (dt > 0)
		MoveForward(dt);
	else if (dt < 0)
		MoveBackward(abs(dt));
}
// rotire fata de centru, la o distanta generica 5
void Camera::RotateYCenter (GLfloat Angle)
{
	float distance = 10;
	MoveForward(distance);
	RotateY(Angle);
	MoveBackward(distance);
}
void CFreeCameraController::Update()
{
	if(Global::InputManager().KeyDown('W'))
	{
		MoveForward();
	}
	else if(Global::InputManager().KeyDown('S'))
	{
		MoveBackward();
	}

	if (Global::InputManager().KeyDown('A'))
	{
		StrafeLeft();
	}
	else if (Global::InputManager().KeyDown('D'))
	{
		StrafeRight();
	}

	if (Global::InputManager().RightMouseDown())
	{
		MouseView();
	}
}
Example #5
0
// rotire fata de centru, la o distanta generica 5
void Camera::RotateYCenter (GLfloat Angle, float distance)
{
	//float distance = 5;
	MoveForward(distance);
	RotateY(Angle);
	MoveBackward(distance);
	printf("rotatie");
}
bool Server::IsRegistered(Message &message)
{
	int id = message.GetFrom();
	curr = tail;
	while (curr->prev != NULL && id != curr->client->GetUserID())	// ищем нужного получателя
		MoveBackward();
	if (id != curr->client->GetUserID()) return 0;	// такой пользователь не зарегистрирован на данном сервере
	else return 1;	// такой пользователь зарегистрирован на данном сервере
}
// rotire fata de centru, aflat in fata la o distanta data
void Camera::RotateYCenter (GLfloat angle, float distance)
{
	if(type!=CameraTypeORBIT)
	{
		fprintf(stderr, "Rotatie fata de un centru nepermisa. Tipul curent al camerei: %d\n",type);
		return ;
	}
	MoveForward(distance);
	RotateY(angle);
	MoveBackward(distance);
}
Example #8
0
void Camera3::DecelerateBackward(const double dt) //(-dt)
{
	if(movingVelocity < 0)
	{
		movingVelocity += -moveAcceleration * dt;

		MoveBackward(-dt);	//same explanation in walk()
	}
	else
	{
		movingVelocity = 0.f;
		walkMovingBackward = false;
	}
}
void Server::ShowListOfClients()
{
	while (curr->prev != NULL)
		MoveBackward();
	std::cout << "\n Client list of server #" << this->GetServerID()<<":\n";
	std::cout << "*****************\n";
	while (curr != tail)
	{
		std::cout << " Client id: " << GetCurrClient()->GetUserID() << std::endl;
		MoveForward();
	};	// остался последний элемент
	std::cout << " Client id: " << GetCurrClient()->GetUserID() << std::endl;
	std::cout << "*****************\n\n";
}
bool nsNodeIterator::NodePointer::MoveToPrevious(nsINode *aRoot)
{
    if (!mNode)
      return false;

    if (!mBeforeNode) {
        mBeforeNode = true;
        return true;
    }

    if (mNode == aRoot)
        return false;

    MoveBackward(mNode->GetParentNode(), mNode->GetPreviousSibling());

    return true;
}
Example #11
0
void UserShip3::Update(float RelativeTime)
{
	m_RelativeTime = RelativeTime;

	if ((IsKeyDown('I')) && (IsKeyDown('K')))
		Brake();
	else if (IsKeyDown('I'))
		MoveForward();
	else if (IsKeyDown('K'))
		MoveBackward();

	if ((IsKeyDown('J')) && !(IsKeyDown('L')))
		TurnLeft();
	if ((IsKeyDown('L')) && !(IsKeyDown('J')))
		TurnRight();

	SpaceShip::Update(RelativeTime);
}
Example #12
0
void MyKeyboard(int thekey, int mouseX, int mouseY)
{
	switch(thekey)
	{
		case GLUT_KEY_UP:InclineCameraAltitude();break;
		case GLUT_KEY_DOWN:DeclineCameraAltitude();break;
		case GLUT_KEY_RIGHT:InclineCameraAzimuth();break;
		case GLUT_KEY_LEFT:DeclineCameraAzimuth();break;
		case 'w':MoveForward();break;
		case 's':MoveBackward();break;
		case 'c':ElevateCannon();break;
		case 'z':DeclineCannon();break;
		case '1':RotateLeft();break;
		case '2':RotateRight();break;

	}
		
}
Example #13
0
void CPlayerOne::ActionThead(){
	/*Commands you can use to play.
	  void MoveForward(int delay);
	  void MoveBackward(int delay);
	  void Jump(int delay);
	  void Attack();
	  void crouch(int delay);
	  void upSword(int delay);*/
	
	while (1){
		//################Example of a bot (You can erase and rewrite this code)(You need to program you bot inside of this While() block)
		MoveForward(0);
		Attack();
		MoveBackward(0);
		Attack();
		//################Example of a bot (You can erase and rewrite this code)(You need to program you bot inside of this While() block)
	}
}
Example #14
0
void UserShip4::Update(float RelativeTime)
{
	m_RelativeTime = RelativeTime;

	if ((IsKeyDown(VK_NUMPAD8)) && (IsKeyDown(VK_NUMPAD5)))
		Brake();
	else if (IsKeyDown(VK_NUMPAD8))
		MoveForward();
	else if (IsKeyDown(VK_NUMPAD5))
		MoveBackward();

	if ((IsKeyDown(VK_NUMPAD4)) && !(IsKeyDown(VK_NUMPAD6)))
		TurnLeft();
	if ((IsKeyDown(VK_NUMPAD6)) && !(IsKeyDown(VK_NUMPAD4)))
		TurnRight();

	SpaceShip::Update(RelativeTime);
}
Example #15
0
void UserShip1::Update(float RelativeTime)
{
	m_RelativeTime = RelativeTime;

	if ((IsKeyDown(VK_UP)) && (IsKeyDown(VK_DOWN)))
		Brake();
	else if (IsKeyDown(VK_UP))
		MoveForward();
	else if (IsKeyDown(VK_DOWN))
		MoveBackward();

	if ((IsKeyDown(VK_LEFT)) && !(IsKeyDown(VK_RIGHT)))
		TurnLeft();
	if ((IsKeyDown(VK_RIGHT)) && !(IsKeyDown(VK_LEFT)))
		TurnRight();

	SpaceShip::Update(RelativeTime);
}
Example #16
0
void CCSBot::Wiggle()
{
	if (IsCrouching())
	{
		ResetStuckMonitor();
		return;
	}

	// for wiggling
	if (gpGlobals->time >= m_wiggleTimestamp)
	{
		m_wiggleDirection = (NavRelativeDirType)RANDOM_LONG(0, 3);
		m_wiggleTimestamp = RANDOM_FLOAT(0.5, 1.5) + gpGlobals->time;
	}

	// TODO: implement checking of the movement to fall down
	switch (m_wiggleDirection)
	{
	case LEFT:
		StrafeLeft();
		break;
	case RIGHT:
		StrafeRight();
		break;
	case FORWARD:
		MoveForward();
		break;
	case BACKWARD:
		MoveBackward();
		break;
	default:
		break;
	}

	if (gpGlobals->time >= m_stuckJumpTimestamp)
	{
		if (Jump())
		{
			m_stuckJumpTimestamp = RANDOM_FLOAT(1.0, 2.0) + gpGlobals->time;
		}
	}
}
void Server::MessageForCurrClient(Message &message)
{
	if (!IsRegistered(message)) {	// если отправитель не на этом сервере
		std::cout << " You are not registered at this server. \n";
		return;
	}; curr->client->GetHistory()->AddElement(message); // добавляем сообщение в "исходящие" к отправителю
	int id = message.GetTo();
	curr = tail;
	while (curr->prev != NULL && id != curr->client->GetUserID())	// ищем нужного получателя
		MoveBackward();
	if (id != curr->client->GetUserID()) // адресат не найден
		std::cout << " Reciever is not found. \n";
	else
	{	// добавляем сообщ-е в историю сообщений
		curr->client->GetHistory()->AddElement(message);
		std::cout << " Your message is delivered to reciever. \n";
		// Добавть анализ сообщения
	};
	curr = tail;
}
Example #18
0
void pgCamera::Update()
{
	if (ApConfig::IsWin())
	{
		static BtBool isLoaded = BtFalse;
		if (isLoaded == BtFalse)
		{
			// If we have a previously saved version of the camera then load
			FsFile file;
			BtChar filename[64];
			sprintf(filename, "%s%s", ApConfig::GetDocuments(), "camera.txt");
			file.Open(filename, FsMode_Read);
			if (file.IsOpen())
			{
				file.Read(m_cameraData);
				file.Close();
			}
			isLoaded = BtTrue;
		}
	}

	if (UiKeyboard::pInstance()->IsPressed(UiKeyCode_F3))
	{
		m_isFlyCam = !m_isFlyCam;
	}


	for (BtU32 i = 1; i < MaxTouches; i += 2)
	{
		if (ShTouch::IsHeld(i) || m_isFlyCam)
		{
			BtFloat speed = BtTime::GetTick() * 10.0f;

			if (UiKeyboard::pInstance()->IsHeld(UiKeyCode_LSHIFT))
			{
				speed = speed * 10.0f;
			}
			if (UiKeyboard::pInstance()->IsHeld(UiKeyCode_W))
			{
				MoveForward(speed);
			}
			if (UiKeyboard::pInstance()->IsHeld(UiKeyCode_S))
			{
				MoveBackward(speed);
			}
			if (UiKeyboard::pInstance()->IsHeld(UiKeyCode_D))
			{
				MoveRight(speed);
			}
			if (UiKeyboard::pInstance()->IsHeld(UiKeyCode_A))
			{
				MoveLeft(speed);
			}
		}
	}


	if (ShTouch::IsHeld(1))
	{
        BtBool onScreen = BtTrue;//ShTouch::OnScreen(1);
		if (onScreen)
		{
			for (BtU32 i = 0; i < MaxTouches; i += 2)
			{
				// Rotate the camera
				MtVector2 v2MouseDirection = ShTouch::GetMovement(i);
				BtFloat speed = BtTime::GetTick() * 0.1f;
				MtMatrix3 m3Rotate;
				m3Rotate.SetRotationY(v2MouseDirection.x * -speed);
				m_cameraData.m_m3Rotation = m3Rotate * m_cameraData.m_m3Rotation;
				m3Rotate.SetRotationX(v2MouseDirection.y * speed);
				m_cameraData.m_m3Rotation = m_cameraData.m_m3Rotation * m3Rotate;
			}
		}
	}

	static BtBool isCursorKeys = BtFalse;

	// Rotate the camera
	BtFloat speed = BtTime::GetTick();

	if (UiKeyboard::pInstance()->IsHeld(UiKeyCode_LSHIFT))
	{
		if (UiKeyboard::pInstance()->IsHeld(UiKeyCode_LEFT))
		{
			isCursorKeys = BtTrue;
			m_cameraData.m_yaw += speed;
		}
		if (UiKeyboard::pInstance()->IsHeld(UiKeyCode_RIGHT))
		{
			isCursorKeys = BtTrue;
			m_cameraData.m_yaw -= speed;
		}
		if (UiKeyboard::pInstance()->IsHeld(UiKeyCode_UP))
		{
			isCursorKeys = BtTrue;
			m_cameraData.m_pitch -= speed;
		}
		if (UiKeyboard::pInstance()->IsHeld(UiKeyCode_DOWN))
		{
			isCursorKeys = BtTrue;
			m_cameraData.m_pitch += speed;
		}
	}

	if (!ApConfig::IsWin())
	{
		// Support a landscape quaternion
		MtMatrix3 m_m3Rotation;
		MtQuaternion quaternion = ShIMU::GetQuaternion(0);
		quaternion.x = quaternion.x;
		quaternion.y = quaternion.y;
		quaternion.z = -quaternion.z;

		m_m3Rotation = MtMatrix3(quaternion);
		//m_m3Rotation = m_m3Rotation.GetInverse();

		MtMatrix3 m3RotateY;
		m3RotateY.SetRotationY(MtDegreesToRadians(90.0f));

		MtMatrix3 m3RotateZ;
		m3RotateZ.SetRotationZ(MtDegreesToRadians(-90.0f));

		m_m3Rotation = m3RotateY * m_m3Rotation;
		m_m3Rotation = m3RotateZ * m_m3Rotation;
		m_m3Rotation = m_m3Rotation * m3RotateZ;

		m_camera.SetRotation(m_m3Rotation);

	}
	else if (ShHMD::IsHMD())
	{
		MtMatrix3 m3RotateY;
		m3RotateY.SetRotationX(m_cameraData.m_pitch);
		MtMatrix3 m3RotateX;
		m3RotateX.SetRotationY(m_cameraData.m_yaw);
		m_cameraData.m_m3Rotation = m3RotateX * m3RotateY;

		// Cache the ShHMD rotation
		MtQuaternion quaternion = ShHMD::GetQuaternion();

		// Set the IMU rotation
		MtMatrix4 m4FinalRotation = m_cameraData.m_m3Rotation * MtMatrix3(quaternion);

		// Set the rotation
		m_camera.SetRotation(m4FinalRotation);
	}
	else
	{
		if (isCursorKeys)
		{
			MtMatrix3 m3RotateY;
			m3RotateY.SetRotationX(m_cameraData.m_pitch);
			MtMatrix3 m3RotateX;
			m3RotateX.SetRotationY(m_cameraData.m_yaw);
			m_cameraData.m_m3Rotation = m3RotateX * m3RotateY;
		}

		// Set the rotation
		m_camera.SetRotation(m_cameraData.m_m3Rotation);
	}

	// Set the position
	m_camera.SetPosition(m_cameraData.m_v3Position);

	// Update the camera
	m_camera.Update();

	if (UiKeyboard::pInstance()->IsPressed(SaveCameraKey))
	{
		FsFile file;
		BtChar filename[64];
		sprintf(filename, "%s%s", ApConfig::GetDocuments(), "camera.txt");
		file.Open(filename, FsMode_Write);
		if (file.IsOpen())
		{
			file.Write(m_cameraData);
			file.Close();
		}
	}
}
Example #19
0
void MasinaManager::movePrev_Limuzina() {
    if (!areLimuzina()) return;
    MoveBackward();
     while (carList[currentCarIndex]->toName() != "Limuzina")
            MoveBackward();
}
Example #20
0
void MasinaManager::movePrev_SUV() {
    if (!areSUV()) return;
    MoveBackward();
    while (carList[currentCarIndex]->toName() != "SUV")
            MoveBackward();
}
Example #21
0
//--------------------------------------------------------------
void testApp::bangFired(ofxTLBangEventArgs& bang){
	cout << "bang fired!" << bang.flag << endl;
	if (bang.flag == "fwd1")
	{
		cout << "Moving forward projector 1" << endl;
		MoveForward();
        //relayShield.PulseRelay3();
        //cout<< "Flash ON CC48" << endl;
	}
	if (bang.flag == "bck1")
	{
		cout << "Moving backward projector 1" << endl;
		MoveBackward();
	}
	if (bang.flag == "fwd2")
	{
		cout << "Moving forward projector 2" << endl;

        midiOut.sendControlChange(1, 48, 127);
		relayShield.PulseRelay3();
        cout<< "Flash ON CC48" << endl;
	}
    if (bang.flag == "bck2")
	{
		cout << "Moving forward projector 2" << endl;

        midiOut.sendControlChange(1, 48, 0);
        cout<< "Flash OFF CC48" << endl;

	}
	if (bang.flag == "AudioLocuraOn")
	{
		cout << "AudioLocuraOn" << endl;
		sublines[0]->play();
	}
	if (bang.flag == "AudioLocuraOff")
	{
		cout << "AudioLocuraOff" << endl;
		sublines[0]->stop();
	}
	if (bang.flag == "AudioSlideShowOn")
	{
		cout << "AudioSlideShowOn" << endl;
		sublines[1]->play();
	}
	if (bang.flag == "AudioSlideshowOff")
	{
		cout << "AudioSlideshowOff" << endl;
		sublines[1]->stop();
	}
	if (bang.flag == "AudioColadorOn")
	{
		cout << "AudioColadorOn" << endl;
		sublines[2]->play();
	}
	if (bang.flag == "AudioColadorOff")
	{
		cout << "AudioColadorOff" << endl;
		sublines[2]->stop();
	}
	if (bang.flag == "Projector1On")
	{
		cout << "Projector1On" << endl;
		relayShield.Relay5Off();
	}
	if (bang.flag == "Projector1Off")
	{
		cout << "Projector1Off" << endl;
		relayShield.Relay5On();
	}
	if (bang.flag == "Projector2On")
	{
		cout << "Projector2On" << endl;
		relayShield.Relay6Off();
	}
	if (bang.flag == "Projector2Off")
	{
		cout << "Projector2Off" << endl;
		relayShield.Relay6On();
	}
    if (bang.flag == "LightOn")
	{
		cout << "LightOn" << endl;
		relayShield.Relay4On();
	}
	if (bang.flag == "LightOff")
	{
		cout << "LightOff" << endl;
		relayShield.Relay4Off();
	}
		
}
Example #22
0
void MasinaManager::movePrev_MasinaDeCurse() {
    if (!areMasinaDeCurse()) return;
    MoveBackward();
    while (carList[currentCarIndex]->toName() != "MasinaDeCurse")
            MoveBackward();
}
Example #23
0
int cCamera::Control()
{
    if(m_Number != CurrCamera) return -1;


#ifndef DIMENSION_3D // 2D
    /* 상하좌우 이동 */
    float Speed = VFR(0.05f);

    if(cCore::Input.KeyPress('W'))
    {
        AddEyePt(0.f, Speed, 0.f);
        AddLookAt(0.f, Speed, 0.f);
    }
    else if(cCore::Input.KeyPress('S'))
    {
        AddEyePt(0.f, -Speed, 0.f);
        AddLookAt(0.f, -Speed, 0.f);
    }

    if(cCore::Input.KeyPress('A'))
    {
        AddEyePt(-Speed, 0.f, 0.f);
        AddLookAt(-Speed, 0.f, 0.f);
    }
    else if(cCore::Input.KeyPress('D'))
    {
        AddEyePt(Speed, 0.f, 0.f);
        AddLookAt(Speed, 0.f, 0.f);
    }
#else
#ifdef VIEW_3D
    /* 마우스 좌클릭 드래그로 카메라 회전 */
    if(cCore::Input.MousePress(VK_LBUTTON))
    {
#ifdef NOTUSE_VFR
        Rotation(VFR(+0.2f));
#else
        Rotation(VFR(+0.2f));
#endif
    }


    /* 쉬프트키와 스페이스키로 위아래 이동 */
    if(cCore::Input.KeyPress(VK_LSHIFT))
    {
        AddEyePt(0, VFR(-0.2f), 0);
        AddLookAt(0, VFR(-0.2f), 0);
    }
    else if(cCore::Input.KeyPress(VK_SPACE))
    {
        AddEyePt(0, VFR(0.2f), 0);
        AddLookAt(0, VFR(0.2f), 0);
    }


    /* 카메라가 보는 방향을 기준으로 앞, 뒤, 옆으로 이동 */
    if(cCore::Input.KeyPress('W'))
    {
        MoveForward(VFR(+0.2f));
    }
    else if(cCore::Input.KeyPress('S'))
    {
        MoveBackward(VFR(0.2f));
    }

    if(cCore::Input.KeyPress('A'))
    {
        MoveSideward(VFR(-0.1f));
    }
    else if(cCore::Input.KeyPress('D'))
    {
        MoveSideward(VFR(+0.1f));
    }


    /* 카메라가 보는곳을 중심으로 회전 */
    if(cCore::Input.KeyPress('Q'))
    {
        MoveSideward(VFR(-0.2f), false);
    }
    else if(cCore::Input.KeyPress('E'))
    {
        MoveSideward(VFR(+0.2f), false);
    }
#else
    /* 상하좌우 이동 */
    float Speed = VFR(0.05f);

    if(cCore::Input.KeyPress('W'))
    {
        AddEyePt(Speed, 0.f, Speed);
        AddLookAt(Speed, 0.f, Speed);
    }
    else if(cCore::Input.KeyPress('S'))
    {
        AddEyePt(-Speed, 0.f, -Speed);
        AddLookAt(-Speed, 0.f, -Speed);
    }

    if(cCore::Input.KeyPress('A'))
    {
        AddEyePt(-Speed, 0.f, Speed);
        AddLookAt(-Speed, 0.f, Speed);
    }
    else if(cCore::Input.KeyPress('D'))
    {
        AddEyePt(Speed, 0.f, -Speed);
        AddLookAt(Speed, 0.f, -Speed);
    }
#endif
#endif


    return 0;
}
Example #24
0
void CCSBot::MoveTowardsPosition(const Vector *pos)
{
	// Jump up on ledges
	// Because we may not be able to get to our goal position and enter the next
	// area because our extent collides with a nearby vertical ledge, make sure
	// we look far enough ahead to avoid this situation.
	// Can't look too far ahead, or bots will try to jump up slopes.

	// NOTE: We need to do this frequently to catch edges at the right time
	// TODO: Look ahead *along path* instead of straight line
	if ((m_lastKnownArea == NULL || !(m_lastKnownArea->GetAttributes() & NAV_NO_JUMP)) &&
		!IsOnLadder() && !m_isJumpCrouching)
	{
		float ground;
		Vector aheadRay(pos->x - pev->origin.x, pos->y - pev->origin.y, 0);
		aheadRay.NormalizeInPlace();

		// look far ahead to allow us to smoothly jump over gaps, ledges, etc
		// only jump if ground is flat at lookahead spot to avoid jumping up slopes
		bool jumped = false;

		if (IsRunning())
		{
			const float farLookAheadRange = 80.0f;
			Vector normal;
			Vector stepAhead = pev->origin + farLookAheadRange * aheadRay;
			stepAhead.z += HalfHumanHeight;

			if (GetSimpleGroundHeightWithFloor(&stepAhead, &ground, &normal))
			{
				if (normal.z > 0.9f)
					jumped = DiscontinuityJump(ground, ONLY_JUMP_DOWN);
			}
		}

		if (!jumped)
		{
			// close up jumping
			// cant be less or will miss jumps over low walls
			const float lookAheadRange = 30.0f;
			Vector stepAhead = pev->origin + lookAheadRange * aheadRay;
			stepAhead.z += HalfHumanHeight;

			if (GetSimpleGroundHeightWithFloor(&stepAhead, &ground))
			{
				jumped = DiscontinuityJump(ground);
			}
		}

		if (!jumped)
		{
			// about to fall gap-jumping
			const float lookAheadRange = 10.0f;
			Vector stepAhead = pev->origin + lookAheadRange * aheadRay;
			stepAhead.z += HalfHumanHeight;

			if (GetSimpleGroundHeightWithFloor(&stepAhead, &ground))
			{
				jumped = DiscontinuityJump(ground, ONLY_JUMP_DOWN, MUST_JUMP);
			}
		}
	}

	// compute our current forward and lateral vectors
	float angle = pev->v_angle.y;

	Vector2D dir(BotCOS(angle), BotSIN(angle));
	Vector2D lat(-dir.y, dir.x);

	// compute unit vector to goal position
	Vector2D to(pos->x - pev->origin.x, pos->y - pev->origin.y);
	to.NormalizeInPlace();

	// move towards the position independant of our view direction
	float toProj = to.x * dir.x + to.y * dir.y;
	float latProj = to.x * lat.x + to.y * lat.y;

	const float c = 0.25f;
	if (toProj > c)
		MoveForward();
	else if (toProj < -c)
		MoveBackward();

	// if we are avoiding someone via strafing, don't override
	if (m_avoid != NULL)
		return;

	if (latProj >= c)
		StrafeLeft();
	else if (latProj <= -c)
		StrafeRight();
}
Example #25
0
// Navigate our current ladder. Return true if we are doing ladder navigation.
// TODO: Need Push() and Pop() for run/walk context to keep ladder speed contained.
bool CCSBot::UpdateLadderMovement()
{
	if (!m_pathLadder)
		return false;

	bool giveUp = false;

	// check for timeout
	const float ladderTimeoutDuration = 10.0f;
	if (gpGlobals->time - m_pathLadderTimestamp > ladderTimeoutDuration)
	{
		PrintIfWatched("Ladder timeout!\n");
		giveUp = true;
	}

	else if (m_pathLadderState == APPROACH_ASCENDING_LADDER
		|| m_pathLadderState == APPROACH_DESCENDING_LADDER
		|| m_pathLadderState == ASCEND_LADDER
		|| m_pathLadderState == DESCEND_LADDER
		|| m_pathLadderState == DISMOUNT_ASCENDING_LADDER
		|| m_pathLadderState == MOVE_TO_DESTINATION)
	{
		if (m_isStuck)
		{
			PrintIfWatched("Giving up ladder - stuck\n");
			giveUp = true;
		}
	}

	if (giveUp)
	{
		// jump off ladder and give up
		Jump(MUST_JUMP);
		Wiggle();
		ResetStuckMonitor();
		DestroyPath();
		Run();
		return false;
	}

	ResetStuckMonitor();

	// check if somehow we totally missed the ladder
	switch (m_pathLadderState)
	{
	case MOUNT_ASCENDING_LADDER:
	case MOUNT_DESCENDING_LADDER:
	case ASCEND_LADDER:
	case DESCEND_LADDER:
	{
		const float farAway = 200.0f;
		Vector2D d = (m_pathLadder->m_top - pev->origin).Make2D();
		if (d.IsLengthGreaterThan(farAway))
		{
			PrintIfWatched("Missed ladder\n");
			Jump(MUST_JUMP);
			DestroyPath();
			Run();
			return false;
		}
		break;
	}
	}

	m_areaEnteredTimestamp = gpGlobals->time;

	const float tolerance = 10.0f;
	const float closeToGoal = 25.0f;

	switch (m_pathLadderState)
	{
	case APPROACH_ASCENDING_LADDER:
	{
		bool approached = false;
		Vector2D d(pev->origin.x - m_goalPosition.x, pev->origin.y - m_goalPosition.y);

		if (d.x * m_pathLadder->m_dirVector.x + d.y * m_pathLadder->m_dirVector.y < 0.0f)
		{
			Vector2D perp(-m_pathLadder->m_dirVector.y, m_pathLadder->m_dirVector.x);

#ifdef REGAMEDLL_FIXES
			if (Q_abs(d.x * perp.x + d.y * perp.y) < tolerance && d.Length() < closeToGoal)
#else
			if (Q_abs(int64(d.x * perp.x + d.y * perp.y)) < tolerance && d.Length() < closeToGoal)
#endif
				approached = true;
		}

		// small radius will just slow them down a little for more accuracy in hitting their spot
		const float walkRange = 50.0f;
		if (d.IsLengthLessThan(walkRange))
		{
			Walk();
			StandUp();
		}

		// TODO: Check that we are on the ladder we think we are
		if (IsOnLadder())
		{
			m_pathLadderState = ASCEND_LADDER;
			PrintIfWatched("ASCEND_LADDER\n");

			// find actual top in case m_pathLadder penetrates the ceiling
			ComputeLadderEndpoint(true);
		}
		else if (approached)
		{
			// face the m_pathLadder
			m_pathLadderState = FACE_ASCENDING_LADDER;
			PrintIfWatched("FACE_ASCENDING_LADDER\n");
		}
		else
		{
			// move toward ladder mount point
			MoveTowardsPosition(&m_goalPosition);
		}
		break;
	}
	case APPROACH_DESCENDING_LADDER:
	{
		// fall check
		if (GetFeetZ() <= m_pathLadder->m_bottom.z + HalfHumanHeight)
		{
			PrintIfWatched("Fell from ladder.\n");

			m_pathLadderState = MOVE_TO_DESTINATION;
			m_path[m_pathIndex].area->GetClosestPointOnArea(&m_pathLadder->m_bottom, &m_goalPosition);

			AddDirectionVector(&m_goalPosition, m_pathLadder->m_dir, HalfHumanWidth);
			PrintIfWatched("MOVE_TO_DESTINATION\n");
		}
		else
		{
			bool approached = false;
			Vector2D d(pev->origin.x - m_goalPosition.x, pev->origin.y - m_goalPosition.y);

			if (d.x * m_pathLadder->m_dirVector.x + d.y * m_pathLadder->m_dirVector.y > 0.0f)
			{
				Vector2D perp(-m_pathLadder->m_dirVector.y, m_pathLadder->m_dirVector.x);

				if (Q_abs(int64(d.x * perp.x + d.y * perp.y)) < tolerance && d.Length() < closeToGoal)
					approached = true;
			}

			// if approaching ladder from the side or "ahead", walk
			if (m_pathLadder->m_topBehindArea != m_lastKnownArea)
			{
				const float walkRange = 150.0f;
				if (!IsCrouching() && d.IsLengthLessThan(walkRange))
					Walk();
			}

			// TODO: Check that we are on the ladder we think we are
			if (IsOnLadder())
			{
				// we slipped onto the ladder - climb it
				m_pathLadderState = DESCEND_LADDER;
				Run();
				PrintIfWatched("DESCEND_LADDER\n");

				// find actual bottom in case m_pathLadder penetrates the floor
				ComputeLadderEndpoint(false);
			}
			else if (approached)
			{
				// face the ladder
				m_pathLadderState = FACE_DESCENDING_LADDER;
				PrintIfWatched("FACE_DESCENDING_LADDER\n");
			}
			else
			{
				// move toward ladder mount point
				MoveTowardsPosition(&m_goalPosition);
			}
		}
		break;
	}
	case FACE_ASCENDING_LADDER:
	{
		// find yaw to directly aim at ladder
		Vector to = m_pathLadder->m_bottom - pev->origin;
		Vector idealAngle = UTIL_VecToAngles(to);

		const float angleTolerance = 5.0f;
		if (AnglesAreEqual(pev->v_angle.y, idealAngle.y, angleTolerance))
		{
			// move toward ladder until we become "on" it
			Run();
			ResetStuckMonitor();
			m_pathLadderState = MOUNT_ASCENDING_LADDER;
			PrintIfWatched("MOUNT_ASCENDING_LADDER\n");
		}
		break;
	}
	case FACE_DESCENDING_LADDER:
	{
		// find yaw to directly aim at ladder
		Vector to = m_pathLadder->m_top - pev->origin;
		Vector idealAngle = UTIL_VecToAngles(to);

		const float angleTolerance = 5.0f;
		if (AnglesAreEqual(pev->v_angle.y, idealAngle.y, angleTolerance))
		{
			// move toward ladder until we become "on" it
			m_pathLadderState = MOUNT_DESCENDING_LADDER;
			ResetStuckMonitor();
			PrintIfWatched("MOUNT_DESCENDING_LADDER\n");
		}
		break;
	}
	case MOUNT_ASCENDING_LADDER:
	{
		if (IsOnLadder())
		{
			m_pathLadderState = ASCEND_LADDER;
			PrintIfWatched("ASCEND_LADDER\n");

			// find actual top in case m_pathLadder penetrates the ceiling
			ComputeLadderEndpoint(true);
		}

		MoveForward();
		break;
	}
	case MOUNT_DESCENDING_LADDER:
	{
		// fall check
		if (GetFeetZ() <= m_pathLadder->m_bottom.z + HalfHumanHeight)
		{
			PrintIfWatched("Fell from ladder.\n");

			m_pathLadderState = MOVE_TO_DESTINATION;
			m_path[m_pathIndex].area->GetClosestPointOnArea(&m_pathLadder->m_bottom, &m_goalPosition);

			AddDirectionVector(&m_goalPosition, m_pathLadder->m_dir, HalfHumanWidth);
			PrintIfWatched("MOVE_TO_DESTINATION\n");
		}
		else
		{
			if (IsOnLadder())
			{
				m_pathLadderState = DESCEND_LADDER;
				PrintIfWatched("DESCEND_LADDER\n");

				// find actual bottom in case m_pathLadder penetrates the floor
				ComputeLadderEndpoint(false);
			}

			// move toward ladder mount point
			MoveForward();
		}
		break;
	}
	case ASCEND_LADDER:
	{
		// run, so we can make our dismount jump to the side, if necessary
		Run();

		// if our destination area requires us to crouch, do it
		if (m_path[m_pathIndex].area->GetAttributes() & NAV_CROUCH)
			Crouch();

		// did we reach the top?
		if (GetFeetZ() >= m_pathLadderEnd)
		{
			// we reached the top - dismount
			m_pathLadderState = DISMOUNT_ASCENDING_LADDER;
			PrintIfWatched("DISMOUNT_ASCENDING_LADDER\n");

			if (m_path[m_pathIndex].area == m_pathLadder->m_topForwardArea)
				m_pathLadderDismountDir = FORWARD;
			else if (m_path[m_pathIndex].area == m_pathLadder->m_topLeftArea)
				m_pathLadderDismountDir = LEFT;
			else if (m_path[m_pathIndex].area == m_pathLadder->m_topRightArea)
				m_pathLadderDismountDir = RIGHT;

			m_pathLadderDismountTimestamp = gpGlobals->time;
		}
		else if (!IsOnLadder())
		{
			// we fall off the ladder, repath
			DestroyPath();
			return false;
		}

		// move up ladder
		MoveForward();
		break;
	}
	case DESCEND_LADDER:
	{
		Run();

		float destHeight = m_pathLadderEnd + HalfHumanHeight;
		if (!IsOnLadder() || GetFeetZ() <= destHeight)
		{
			// we reached the bottom, or we fell off - dismount
			m_pathLadderState = MOVE_TO_DESTINATION;
			m_path[m_pathIndex].area->GetClosestPointOnArea(&m_pathLadder->m_bottom, &m_goalPosition);

			AddDirectionVector(&m_goalPosition, m_pathLadder->m_dir, HalfHumanWidth);
			PrintIfWatched("MOVE_TO_DESTINATION\n");
		}

		// Move down ladder
		MoveForward();
		break;
	}
	case DISMOUNT_ASCENDING_LADDER:
	{
		if (gpGlobals->time - m_pathLadderDismountTimestamp >= 0.4f)
		{
			m_pathLadderState = MOVE_TO_DESTINATION;
			m_path[m_pathIndex].area->GetClosestPointOnArea(&pev->origin, &m_goalPosition);
			PrintIfWatched("MOVE_TO_DESTINATION\n");
		}

		// We should already be facing the dismount point
		if (m_pathLadderFaceIn)
		{
			switch (m_pathLadderDismountDir)
			{
			case LEFT:    StrafeLeft(); break;
			case RIGHT:   StrafeRight(); break;
			case FORWARD: MoveForward(); break;
			}
		}
		else
		{
			switch (m_pathLadderDismountDir)
			{
			case LEFT:    StrafeRight();  break;
			case RIGHT:   StrafeLeft();   break;
			case FORWARD: MoveBackward(); break;
			}
		}
		break;
	}
	case MOVE_TO_DESTINATION:
	{
		if (m_path[m_pathIndex].area->Contains(&pev->origin))
		{
			// successfully traversed ladder and reached destination area
			// exit ladder state machine
			PrintIfWatched("Ladder traversed.\n");
			m_pathLadder = nullptr;

			// incrememnt path index to next step beyond this ladder
			SetPathIndex(m_pathIndex + 1);

			return false;
		}

		MoveTowardsPosition(&m_goalPosition);
		break;
	}
	}

	return true;
}
Example #26
0
int32_t CFDE_TxtEdtEngine::MoveCaretPos(FDE_TXTEDTMOVECARET eMoveCaret,
                                        FX_BOOL bShift,
                                        FX_BOOL bCtrl) {
  if (IsLocked()) {
    return 0;
  }
  if (m_PagePtrArray.GetSize() <= m_nCaretPage) {
    return 0;
  }
  FX_BOOL bSelChange = FALSE;
  if (IsSelect()) {
    ClearSelection();
    bSelChange = TRUE;
  }
  if (bShift) {
    if (m_nAnchorPos == -1) {
      m_nAnchorPos = m_nCaret;
    }
  } else {
    m_nAnchorPos = -1;
  }
  FX_BOOL bVertical = m_Param.dwLayoutStyles & FDE_TEXTEDITLAYOUT_DocVertical;
  switch (eMoveCaret) {
    case MC_Left: {
      if (bVertical) {
        CFX_PointF ptCaret;
        if (MoveUp(ptCaret)) {
          UpdateCaretIndex(ptCaret);
        }
      } else {
        FX_BOOL bBefore = TRUE;
        int32_t nIndex = MoveBackward(bBefore);
        if (nIndex >= 0) {
          UpdateCaretRect(nIndex, bBefore);
        }
      }
    } break;
    case MC_Right: {
      if (bVertical) {
        CFX_PointF ptCaret;
        if (MoveDown(ptCaret)) {
          UpdateCaretIndex(ptCaret);
        }
      } else {
        FX_BOOL bBefore = TRUE;
        int32_t nIndex = MoveForward(bBefore);
        if (nIndex >= 0) {
          UpdateCaretRect(nIndex, bBefore);
        }
      }
    } break;
    case MC_Up: {
      if (bVertical) {
        FX_BOOL bBefore = TRUE;
        int32_t nIndex = MoveBackward(bBefore);
        if (nIndex >= 0) {
          UpdateCaretRect(nIndex, bBefore);
        }
      } else {
        CFX_PointF ptCaret;
        if (MoveUp(ptCaret)) {
          UpdateCaretIndex(ptCaret);
        }
      }
    } break;
    case MC_Down: {
      if (bVertical) {
        FX_BOOL bBefore = TRUE;
        int32_t nIndex = MoveForward(bBefore);
        if (nIndex >= 0) {
          UpdateCaretRect(nIndex, bBefore);
        }
      } else {
        CFX_PointF ptCaret;
        if (MoveDown(ptCaret)) {
          UpdateCaretIndex(ptCaret);
        }
      }
    } break;
    case MC_WordBackward:
      break;
    case MC_WordForward:
      break;
    case MC_LineStart:
      MoveLineStart();
      break;
    case MC_LineEnd:
      MoveLineEnd();
      break;
    case MC_ParagStart:
      MoveParagStart();
      break;
    case MC_ParagEnd:
      MoveParagEnd();
      break;
    case MC_PageDown:
      break;
    case MC_PageUp:
      break;
    case MC_Home:
      MoveHome();
      break;
    case MC_End:
      MoveEnd();
      break;
    default:
      break;
  }
  if (bShift && m_nAnchorPos != -1 && (m_nAnchorPos != m_nCaret)) {
    AddSelRange(std::min(m_nAnchorPos, m_nCaret),
                FXSYS_abs(m_nAnchorPos - m_nCaret));
    m_Param.pEventSink->On_SelChanged(this);
  }
  if (bSelChange) {
    m_Param.pEventSink->On_SelChanged(this);
  }
  return m_nCaret;
}
void CFullScreenFrame::SetupInput()
{
	INPUTENGPARAMS inputParams;
	KEYBIND binding;
	CHashString kbName(_T("GDS_kb"));
	
	CHashString inputManager(_T("CInputManager"));
	CHashString StopMessage(_T("StopPlaying"));
	CHashString MoveForward(_T("CamMoveForward"));
	CHashString MoveBackward(_T("CamMoveBackward"));
	CHashString StrafeLeft(_T("CamStrafeLeft"));
	CHashString StrafeRight(_T("CamStrafeRight"));

	// create the input manager
	m_ToolBox->CreateComponent(&CHashString(_T("CInputManager")), 0);

	// start the input manager
	HMODULE mod = GetModuleHandle(NULL);
	inputParams.hMod = mod;
	inputParams.hWnd = GetSafeHwnd();
	inputParams.mouseImmediate = true;
	inputParams.mouseExclusive = false;
	inputParams.mouseFG = true;
	inputParams.kbImmediate = true;
	inputParams.kbExclusive = false;
	inputParams.kbFG = true;
	
	static DWORD msgHash_Begin = CHashString(_T("Begin")).GetUniqueID();
	m_ToolBox->SendMessage(msgHash_Begin, sizeof(INPUTENGPARAMS), &inputParams, NULL, &inputManager);
	static DWORD msgHash_Start = CHashString(_T("Start")).GetUniqueID();
	m_ToolBox->SendMessage(msgHash_Start, 0, NULL, NULL, &inputManager);

	binding.m_kbNameID = kbName.GetUniqueID();
	binding.m_KeyID = EEK_ESC;//0x1; 
	binding.m_MessageID = StopMessage.GetUniqueID();
	binding.m_bHitOnce = true;
	static DWORD msgHash_SetKeyBinding = CHashString(_T("SetKeyBinding")).GetUniqueID();
	m_ToolBox->SendMessage(msgHash_SetKeyBinding, sizeof(KEYBIND), &binding, NULL, &inputManager);

	binding.m_kbNameID = kbName.GetUniqueID();
	binding.m_KeyID = EEK_LEFT;
	binding.m_MessageID = StrafeLeft.GetUniqueID();
	binding.m_bHitOnce = false;
	m_ToolBox->SendMessage(msgHash_SetKeyBinding, sizeof(KEYBIND), &binding, NULL, &inputManager);

	binding.m_kbNameID = kbName.GetUniqueID();
	binding.m_KeyID = EEK_RIGHT;
	binding.m_MessageID = StrafeRight.GetUniqueID();
	binding.m_bHitOnce = false;
	m_ToolBox->SendMessage(msgHash_SetKeyBinding, sizeof(KEYBIND), &binding, NULL, &inputManager);

	binding.m_kbNameID = kbName.GetUniqueID();
	binding.m_KeyID = EEK_UP;
	binding.m_MessageID = MoveForward.GetUniqueID();
	binding.m_bHitOnce = false;
	m_ToolBox->SendMessage(msgHash_SetKeyBinding, sizeof(KEYBIND), &binding, NULL, &inputManager);

	binding.m_kbNameID = kbName.GetUniqueID();
	binding.m_KeyID = EEK_DOWN;
	binding.m_MessageID = MoveBackward.GetUniqueID();
	binding.m_bHitOnce = false;
	m_ToolBox->SendMessage(msgHash_SetKeyBinding, sizeof(KEYBIND), &binding, NULL, &inputManager);

	binding.m_kbNameID = kbName.GetUniqueID();
	binding.m_KeyID = EEK_A;
	binding.m_MessageID = StrafeLeft.GetUniqueID();
	binding.m_bHitOnce = false;
	m_ToolBox->SendMessage(msgHash_SetKeyBinding, sizeof(KEYBIND), &binding, NULL, &inputManager);

	binding.m_kbNameID = kbName.GetUniqueID();
	binding.m_KeyID = EEK_D;
	binding.m_MessageID = StrafeRight.GetUniqueID();
	binding.m_bHitOnce = false;
	m_ToolBox->SendMessage(msgHash_SetKeyBinding, sizeof(KEYBIND), &binding, NULL, &inputManager);

	binding.m_kbNameID = kbName.GetUniqueID();
	binding.m_KeyID = EEK_W;
	binding.m_MessageID = MoveForward.GetUniqueID();
	binding.m_bHitOnce = false;
	m_ToolBox->SendMessage(msgHash_SetKeyBinding, sizeof(KEYBIND), &binding, NULL, &inputManager);

	CHashString reloadshaders(_T("ReloadAllShaders"));
	binding.m_kbNameID = kbName.GetUniqueID();
	binding.m_KeyID = EEK_S;
	binding.m_MessageID = MoveBackward.GetUniqueID();
	binding.m_bHitOnce = false;
	m_ToolBox->SendMessage(msgHash_SetKeyBinding, sizeof(KEYBIND), &binding, NULL, &inputManager);

	binding.m_kbNameID = kbName.GetUniqueID();
	binding.m_KeyID = EEK_Q;
	binding.m_MessageID = reloadshaders.GetUniqueID();
	binding.m_bHitOnce = true;
	m_ToolBox->SendMessage(msgHash_SetKeyBinding, sizeof(KEYBIND), &binding, NULL, &inputManager);

	static DWORD msgHash_SetActiveKeyBinding = CHashString(_T("SetActiveKeyBinding")).GetUniqueID();
	m_ToolBox->SendMessage(msgHash_SetActiveKeyBinding, sizeof(DWORD*), &binding.m_kbNameID, &inputManager);
}