Rotation Problem - Pitch not relative?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
JuicyLobster
Posts: 25
Joined: Sat Jun 07, 2008 8:55 pm

Rotation Problem - Pitch not relative?

Post by JuicyLobster »

Im creating a 3rd person camera for my project using an invisible scene node as the parent that follows the players object/character with a camera scene node attached as a child. As the parent is rotated the camera will relatively be rotated automatically.

Heres the current Camera class source as to where I currently stand:

Code: Select all

#pragma once
#include "stdafx.h"
#include "irrlicht.h"
#include "MastEventReceiver.h"

class Camera
{
	public:
		ISceneManager* scene;
		MastEventReceiver* input;
		ISceneNode* parent;
		ISceneNode* target;
		ICameraSceneNode* cam;
		float mouseX;
		float mouseY;
		float newMouseX;
		float newMouseY;
		bool reset;

	Camera(ISceneManager* s, MastEventReceiver* i)
	{
		scene = s;
		input = i;
		target = scene->addEmptySceneNode(0,-1);
		cam = scene->addCameraSceneNode(target,vector3df(100,0,0),vector3df(target->getRotation().X,
			target->getRotation().Y,target->getRotation().Z),-1);
		mouseX = 0;
		mouseY = 0;
		reset = true;
	}

	//void setParent(ISceneNode* node)
	//{
	//	parent = node;
	//	updateLocation();
	//}

	//void updateLocation()
	//{
	//}

	void run()
	{
		if(input->rightMouseDown())
		{
			if(input->mouseHasMoved())
			{
				if(reset)
				{
					mouseX = float(input->mouseX());
					mouseY = float(input->mouseY());
					reset = false;
				}
				newMouseX = mouseX - float(input->mouseX());
				newMouseY = mouseY - float(input->mouseY());

				target->setRotation(vector3df(target->getRotation().X,
					target->getRotation().Y - newMouseX,
					target->getRotation().Z - newMouseY));

				mouseX = float(input->mouseX());
				mouseY = float(input->mouseY());
			}
		}
		if(input->rightMouseReleased())
		{
			reset = true;
		}
	}


};
Turning is fine, but the pitch always pitches at the same spot. So if I were to turn the parent node 90 degrees then try to pitch, the node would actually roll instead of pitch. I thought pitch would be relative to where the node was already rotated by...
--
Juicy, hot, and full of butter!
CuteAlien
Admin
Posts: 9924
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

I usually avoid setting the target node as parent. but anyway - the rotation of the camera-node does/should not influence the the look-at target until you set camera->bindTargetAndRotation(true). So maybe try that.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply