The default MAYA camera can't be repositioned

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
sunzhuo
Posts: 17
Joined: Tue Dec 23, 2008 2:14 am
Location: Nagoya

The default MAYA camera can't be repositioned

Post by sunzhuo »

The default MAYA camera can't be repositioned in 1.5. After adding a Maya camera to current scene, it can't be reposioned by using SetPosition function as I did in 1.4.2.

There are also some problems with the initiation of MAYA camera. The rotate speed, zoom speed and translation speed don't change to their specified values.

I also reported this problem to bug tracker and got a reply
That's expected behaviour. Maya cameras are always positioned relative to their target. Perhaps we could find another name for it? OrbittingCamera?
I still don't understand. If the maya camera can't be moved by program, what it exists for? Here I paste a sample. No matter what you set in the setPosition function, the camera stay at 0,0,0

Code: Select all

#include <irrlicht.h>

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif

int main()
{
	IrrlichtDevice *device =
#ifdef _IRR_OSX_PLATFORM_
		createDevice( video::EDT_OPENGL, dimension2d<s32>(640, 480), 16,
			false, false, false, 0);
#else
		createDevice( video::EDT_SOFTWARE, dimension2d<s32>(640, 480), 16,
			false, false, false, 0);
#endif
	if (!device)
		return 1;

	device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");

	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->getSceneManager();
	IGUIEnvironment* guienv = device->getGUIEnvironment();

	guienv->addStaticText(L"Hello World! This is the Irrlicht Software renderer!",
		rect<s32>(10,10,260,22), true);

	IAnimatedMesh* mesh = smgr->getMesh("../../media/sydney.md2");
	if (!mesh)
		return 1;
	IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );

	if (node)
	{
		node->setMaterialFlag(EMF_LIGHTING, false);
		node->setMD2Animation(scene::EMAT_STAND);
		node->setMaterialTexture( 0, driver->getTexture("../../media/sydney.bmp") );
	}
	scene::ICameraSceneNode* camera = smgr->addCameraSceneNodeMaya(0, -100.0f, 100.0f, 100.0f);
	
	camera->setPosition(vector3df(0,230,-40));
	camera->setTarget(vector3df(0,5,0));

	while(device->run())
	{
		driver->beginScene(true, true, SColor(255,100,101,140));
		smgr->drawAll();
		guienv->drawAll();
		driver->endScene();
	}
	device->drop();
	return 0;
}
Jiang
Posts: 77
Joined: Tue Feb 20, 2007 11:03 am

Re: The default MAYA camera can't be repositioned

Post by Jiang »

sunzhuo wrote:The default MAYA camera can't be repositioned in 1.5.
I reported the same problem here several months ago.


setPosition for Maya camera


The above change occurred when event handling was added to Maya camera. Unfortunately, or fortunately for someone else, I don't believe this behavior will be changed again.

Stay with your old irrlicht release or change your code (shift the whole scene, etc ...) please.

Regards,

Jiang
sunzhuo
Posts: 17
Joined: Tue Dec 23, 2008 2:14 am
Location: Nagoya

Re: The default MAYA camera can't be repositioned

Post by sunzhuo »

Thank you very much, Jiang.

This problem really confused me a lot. I am trying to integrate CmdKewin's RTS Camera into my current project. Hope it can solve the problem
sunzhuo
Posts: 17
Joined: Tue Dec 23, 2008 2:14 am
Location: Nagoya

Post by sunzhuo »

I just create a camera can simulate the MAYA camera. Hope these code can help someone that have the same confusion like me.

Code: Select all

class MyEventReceiver : public IEventReceiver
{
public:
	// This is the one method that we have to implement
	virtual bool OnEvent(const SEvent& event)
	{
		if (event.EventType != EET_MOUSE_INPUT_EVENT)
			return false;

		switch(event.MouseInput.Event)
		{
		case EMIE_LMOUSE_PRESSED_DOWN:
			MouseKeys[0] = true;
			StartPos.X = event.MouseInput.X;
			StartPos.Y = event.MouseInput.Y;
			break;
		case EMIE_RMOUSE_PRESSED_DOWN:
			MouseKeys[2] = true;
			StartPos.X = event.MouseInput.X;
			StartPos.Y = event.MouseInput.Y;
			break;
		case EMIE_MMOUSE_PRESSED_DOWN:
			MouseKeys[1] = true;
			break;
		case EMIE_LMOUSE_LEFT_UP:
			MouseKeys[0] = false;
			break;
		case EMIE_RMOUSE_LEFT_UP:
			MouseKeys[2] = false;
			break;
		case EMIE_MMOUSE_LEFT_UP:
			MouseKeys[1] = false;
			break;
		case EMIE_MOUSE_MOVED:
			if(MouseKeys[0])
			{
				core::vector3df relativeTarget(Camera->getTarget() -Camera->getPosition());
				relativeTarget.normalize();
				//core::vector3df pos(Camera->getPosition()), target(Camera->getTarget());
				core::vector3df upVector(Camera->getUpVector()); 
				//core::vector3df tvectX = relativeTarget;
				core::vector3df tvectX = relativeTarget.crossProduct(upVector);
				tvectX.normalize();
				core::vector3df tvectY = tvectX.crossProduct(relativeTarget);
				tvectY.normalize();
				upVector = tvectY;
				relativeTarget +=  tvectX * (event.MouseInput.X - StartPos.X)*0.002f + 
								tvectY * (event.MouseInput.Y - StartPos.Y)*0.002f;
				Camera->setTarget(Camera->getPosition()+relativeTarget);
				Camera->setUpVector(upVector);

				StartPos.X = event.MouseInput.X;
				StartPos.Y = event.MouseInput.Y;
			}
			if(MouseKeys[2])
			{
				core::vector3df pos(Camera->getPosition()), target(Camera->getTarget());
				core::vector3df translate(Camera->getTarget()), upVector(Camera->getUpVector()); 
				core::vector3df tvectX = target - pos;
				tvectX = tvectX.crossProduct(upVector);
				tvectX.normalize();
				core::vector3df tvectY = tvectX.crossProduct(target - pos);
				tvectY.normalize();
				translate +=  tvectX * (event.MouseInput.X - StartPos.X)*0.1f + 
								tvectY * (event.MouseInput.Y - StartPos.Y)*0.1f;
				pos += tvectX * (event.MouseInput.X - StartPos.X)*0.1f + 
						tvectY * (event.MouseInput.Y - StartPos.Y)*0.1f;
				Camera->setTarget(translate);
				Camera->setPosition(pos);
				StartPos.X = event.MouseInput.X;
				StartPos.Y = event.MouseInput.Y;
			}
			break;
		case EMIE_MOUSE_WHEEL:
			{
				core::vector3df pos = Camera->getPosition();
				core::vector3df tar = Camera->getTarget();
				core::vector3df relative = tar - pos;
				relative.normalize();
				Camera->setTarget(pos+relative*(1+3.0f*event.MouseInput.Wheel));
				Camera->setPosition(pos+3.0f*relative*event.MouseInput.Wheel);
			}
			break;
		case EMIE_COUNT:
			return false;
		}
		return true;
	}

	// This is used to check whether a key is being held down
	
	MyEventReceiver():Camera(0),StartPos(0,0),relativeRotation(0,0,0),Target(0,0,0)
	{
		MouseKeys[0] = false;
		MouseKeys[1] = false;
		MouseKeys[2] = false;
	}
	void InitCamera(ICameraSceneNode* camera)
	{
		Camera = camera;
	}

private:
	// We use this array to store the current state of each key
	bool MouseKeys[3];
	ICameraSceneNode* Camera;
	core::position2di StartPos;
	core::vector3df relativeRotation;
	core::vector3df Target;
};
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Hi guys. I'm sorry if this screwed you, but I don't think the behaviour of the Maya camera has ever been clear. Since it's a camera that orbits a target position, I don't think that it ever made sense to set its position, since it should always be reset to be relative to its target.

I don't intend to change the current (i.e. 1.5) behaviour unless there's a compelling reason. Hopefully you can create user defined cameras to fulfill your requirements.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Post Reply