5 Replies - 730 Views - Last Post: 02 December 2012 - 02:47 PM Rate Topic: -----

#1 AlgoRhythm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 29-November 12

Problem updating forward direction after rotation. C++

Posted 29 November 2012 - 10:44 AM

Hey, having a bit of a problem with a game object I am trying to manipulate. Basically I use the "A" and "D" keys to rotate the object anti-clockwise and clockwise respectively. I also use the keys "W" and "S" to translate the object back and forward, this is working up until the point that the object is rotated. After this has occurred the object will only continue to move in the same axis. I understand why this is happening as I am not updating the translate with the rotation, anyone know how I can do this with my code?

if (CInput::getInstance().getKeyboard()->isKeyDown((int)'W'))
	{
		//play sound
		CTransformComponent * pTransform=m_pGameObjectManager->findGameObject("Player")->getTransform();
		pTransform->translate(0.0f,0.0f,m_Timer.getElapsedTime()*4);
		CTransformComponent * pTransform2=m_pGameObjectManager->findGameObject("Camera")->getTransform();
		pTransform2->translate(0.0f,0.0f,m_Timer.getElapsedTime()*4);
	}
	else if (CInput::getInstance().getKeyboard()->isKeyDown((int)'S'))
	{
		//play sound
		CTransformComponent * pTransform=m_pGameObjectManager->findGameObject("Player")->getTransform();
		pTransform->translate(0.0f,0.0f,m_Timer.getElapsedTime()*-4);
		CTransformComponent * pTransform2=m_pGameObjectManager->findGameObject("Camera")->getTransform();
		pTransform2->translate(0.0f,0.0f,m_Timer.getElapsedTime()*-4);


	}
	if (CInput::getInstance().getKeyboard()->isKeyDown((int)'D'))
	{
		//play sound
		CTransformComponent * pTransform=m_pGameObjectManager->findGameObject("Player")->getTransform();
		pTransform->rotate(0.0f,m_Timer.getElapsedTime()*2,0.0f);
		CTransformComponent * pTransform2=m_pGameObjectManager->findGameObject("Sky")->getTransform();
		pTransform2->rotate(0.0f,m_Timer.getElapsedTime()*2,0.0f);
	}
	else if (CInput::getInstance().getKeyboard()->isKeyDown((int)'A'))
	{
		//play sound
		CTransformComponent * pTransform=m_pGameObjectManager->findGameObject("Player")->getTransform();
		pTransform->rotate(0.0f,m_Timer.getElapsedTime()*-2,0.0f);
		CTransformComponent * pTransform2=m_pGameObjectManager->findGameObject("Sky")->getTransform();
		pTransform2->rotate(0.0f,m_Timer.getElapsedTime()*-2,0.0f);
	}


Is This A Good Question/Topic? 0
  • +

Replies To: Problem updating forward direction after rotation. C++

#2 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Problem updating forward direction after rotation. C++

Posted 29 November 2012 - 02:04 PM

It's not clear what you're asking. What I am thinking is that you simply restore your axes after performing the translation. Does that seem right?
Was This Post Helpful? 0
  • +
  • -

#3 AlgoRhythm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 29-November 12

Re: Problem updating forward direction after rotation. C++

Posted 29 November 2012 - 11:47 PM

View PostButchDean, on 29 November 2012 - 02:04 PM, said:

It's not clear what you're asking. What I am thinking is that you simply restore your axes after performing the translation. Does that seem right?


I guess that might work. Basically when I rotate the vehicle, I would like it to move in the new direction it is facing when I press the forward button rather than continue moving along the same axis
Was This Post Helpful? 0
  • +
  • -

#4 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Problem updating forward direction after rotation. C++

Posted 30 November 2012 - 11:14 AM

So you're after a motion that you see in a racing game, for instance? If you are there is a novel solution.

In racing games the vehicle you control is actually stationary and the world around is rotated and translated. This removes a lot of complexity. Would that approach be applicable to solving your problem?
Was This Post Helpful? 0
  • +
  • -

#5 AlgoRhythm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 29-November 12

Re: Problem updating forward direction after rotation. C++

Posted 02 December 2012 - 01:26 PM

Unfortunately that isn't really a practical solution as there are other vehicles that move independently that the player has to attack. The vehicle needs to be able to rotate on the y axis which it does already, but once it has rotated it is facing a new direction. when the player presses the forward key I would like the vehicle to move in the direction it is facing
Was This Post Helpful? 0
  • +
  • -

#6 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Problem updating forward direction after rotation. C++

Posted 02 December 2012 - 02:47 PM

How did you work out that what I suggested is not a practical solution? Have you thought about how you would approach it?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1