Maya Camera Set default zoom + swap mouse buttons?

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
gerydeft
Posts: 7
Joined: Tue Mar 30, 2010 1:36 am

Maya Camera Set default zoom + swap mouse buttons?

Post by gerydeft »

Hi everyone,

This maya camera is exacly what i was looking for but it have a small problem:

I want to look around with the right mouse button instead of the left...

i guess i have to edit it in the source directory

"CSceneNodeAnimatorCameraMaya.cpp"

I changed it and nothing happend , maybe i have to recomplie the whole engine? and use that dll?

Plus is it possible to have the camera zoomed out from the character because its kinda too close to it and if i change the camera's position the target will not be the character anymore.

Any reply welcomed :) :wink:
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Re: Maya Camera Set default zoom + swap mouse buttons?

Post by randomMesh »

gerydeft wrote:maybe i have to recomplie the whole engine? and use that dll?
Yes, of course.
gerydeft wrote:Plus is it possible to have the camera zoomed out from the character because its kinda too close to it and if i change the camera's position the target will not be the character anymore.
Just edit CSceneNodeAnimatorCameraMaya.cpp to fit your needs. But don't forget to recompile. ;)
"Whoops..."
gerydeft
Posts: 7
Joined: Tue Mar 30, 2010 1:36 am

Post by gerydeft »

i mean i have to recomplie the
irrlicht-1.7\source\IrrlichtIrrlicht.dev ?

i takes years for me :S

(i use dev c++)
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Post by randomMesh »

Well you could also make an own camera animator which simulates the behaviour of the maya camera with your changes applied. This works without recompiling the engine.
"Whoops..."
gerydeft
Posts: 7
Joined: Tue Mar 30, 2010 1:36 am

Post by gerydeft »

I tried to complie the engine it took many minutes and all i got is:
[Linker error] undefined reference to `irr::scene::COctreeSceneNode::COctreeSceneNode(irr::scene::ISceneNode*, irr::scene::ISceneManager*, int, int)'
[Linker error] undefined reference to `irr::scene::COctreeTriangleSelector::COctreeTriangleSelector(irr::scene::IMesh const*, irr::scene::ISceneNode const*, int)'
ld returned 1 exit status
C:\Dev-Cpp\irrlicht-1.7\source\Irrlicht\Makefile.win [Build Error] [../../bin/Win32-gcc/Irrlicht.dll] Error 1
and i don't get the dll in gcc directory :/

How could i implement my own cam?I don't want to wait 30 minutes each time i want to edit something. :roll:
Last edited by gerydeft on Tue Mar 30, 2010 2:42 am, edited 1 time in total.
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Post by Lonesome Ducky »

Derive your own class from the animator, just like the Maya camera does. You could probably even copy the code. That way you don't have to recompile.
gerydeft
Posts: 7
Joined: Tue Mar 30, 2010 1:36 am

Post by gerydeft »

ok i copied the maya camera and changed the mouse event left<->right

i saved it as cam.cpp added it to project hello world

if i try to rename the class to "CSceneNodeAnimatorCameraMaya2" i get errors, i have to add "CSceneNodeAnimatorCameraMaya2" to ISceneManager.h?

Code: Select all

// Copyright (C) 2002-2009 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h

#include "CSceneNodeAnimatorCameraMaya.h"
#include "ICursorControl.h"
#include "ICameraSceneNode.h"
#include "SViewFrustum.h"
#include "ISceneManager.h"

namespace irr
{
namespace scene
{

//! constructor
CSceneNodeAnimatorCameraMaya::CSceneNodeAnimatorCameraMaya(gui::ICursorControl* cursor, f32 rotate, f32 zoom, f32 translate)
	: CursorControl(cursor), Zooming(false), Rotating(false), Moving(false),
	Translating(false), ZoomSpeed(zoom), RotateSpeed(rotate), TranslateSpeed(translate),
	CurrentZoom(70.0f), RotX(0.0f), RotY(0.0f), OldCamera(0), MousePos(0.5f, 0.5f)
{
	#ifdef _DEBUG
	setDebugName("CSceneNodeAnimatorCameraMaya");
	#endif

	if (CursorControl)
	{
		CursorControl->grab();
		MousePos = CursorControl->getRelativePosition();
	}

	allKeysUp();
}


//! destructor
CSceneNodeAnimatorCameraMaya::~CSceneNodeAnimatorCameraMaya()
{
	if (CursorControl)
		CursorControl->drop();
}


//! It is possible to send mouse and key events to the camera. Most cameras
//! may ignore this input, but camera scene nodes which are created for
//! example with scene::ISceneManager::addMayaCameraSceneNode or
//! scene::ISceneManager::addMeshViewerCameraSceneNode, may want to get this input
//! for changing their position, look at target or whatever.
bool CSceneNodeAnimatorCameraMaya::OnEvent(const SEvent& event)
{
	if (event.EventType != EET_MOUSE_INPUT_EVENT)
		return false;

	switch(event.MouseInput.Event)
	{
	case EMIE_RMOUSE_PRESSED_DOWN:
		MouseKeys[0] = true;
		break;
	case EMIE_LMOUSE_PRESSED_DOWN:
		MouseKeys[2] = true;
		break;
	case EMIE_MMOUSE_PRESSED_DOWN:
		MouseKeys[1] = true;
		break;
	case EMIE_RMOUSE_LEFT_UP:
		MouseKeys[0] = false;
		break;
	case EMIE_LMOUSE_LEFT_UP:
		MouseKeys[2] = false;
		break;
	case EMIE_MMOUSE_LEFT_UP:
		MouseKeys[1] = false;
		break;
	case EMIE_MOUSE_MOVED:
		MousePos = CursorControl->getRelativePosition();
		break;
	case EMIE_MOUSE_WHEEL:
	case EMIE_LMOUSE_DOUBLE_CLICK:
	case EMIE_RMOUSE_DOUBLE_CLICK:
	case EMIE_MMOUSE_DOUBLE_CLICK:
	case EMIE_LMOUSE_TRIPLE_CLICK:
	case EMIE_RMOUSE_TRIPLE_CLICK:
	case EMIE_MMOUSE_TRIPLE_CLICK:
	case EMIE_COUNT:
		return false;
	}
	return true;
}


//! OnAnimate() is called just before rendering the whole scene.
//! nodes may calculate or store animations here, and may do other useful things,
//! dependent on what they are.
void CSceneNodeAnimatorCameraMaya::animateNode(ISceneNode *node, u32 timeMs)
{
	//Alt + LM = Rotate around camera pivot
	//Alt + LM + MM = Dolly forth/back in view direction (speed % distance camera pivot - max distance to pivot)
	//Alt + MM = Move on camera plane (Screen center is about the mouse pointer, depending on move speed)

	if (!node || node->getType() != ESNT_CAMERA)
		return;

	ICameraSceneNode* camera = static_cast<ICameraSceneNode*>(node);

	// If the camera isn't the active camera, and receiving input, then don't process it.
	if(!camera->isInputReceiverEnabled())
		return;

	scene::ISceneManager * smgr = camera->getSceneManager();
	if(smgr && smgr->getActiveCamera() != camera)
		return;

	if (OldCamera != camera)
	{
		OldTarget = camera->getTarget();
		OldCamera = camera;
		LastCameraTarget = OldTarget;
	}
	else
	{
		OldTarget += camera->getTarget() - LastCameraTarget;
	}

	core::vector3df target = camera->getTarget();

	f32 nRotX = RotX;
	f32 nRotY = RotY;
	f32 nZoom = CurrentZoom;

	if ( (isMouseKeyDown(0) && isMouseKeyDown(2)) || isMouseKeyDown(1) )
	{
		if (!Zooming)
		{
			ZoomStart = MousePos;
			Zooming = true;
			nZoom = CurrentZoom;
		}
		else
		{
			const f32 targetMinDistance = 0.1f;
			nZoom += (ZoomStart.X - MousePos.X) * ZoomSpeed;

			if (nZoom < targetMinDistance) // jox: fixed bug: bounce back when zooming to close
				nZoom = targetMinDistance;
		}
	}
	else if (Zooming)
	{
		const f32 old = CurrentZoom;
		CurrentZoom = CurrentZoom + (ZoomStart.X - MousePos.X ) * ZoomSpeed;
		nZoom = CurrentZoom;

		if (nZoom < 0)
			nZoom = CurrentZoom = old;
		Zooming = false;
	}

	// Translation ---------------------------------

	core::vector3df translate(OldTarget), upVector(camera->getUpVector());

	core::vector3df tvectX = Pos - target;
	tvectX = tvectX.crossProduct(upVector);
	tvectX.normalize();

	const SViewFrustum* const va = camera->getViewFrustum();
	core::vector3df tvectY = (va->getFarLeftDown() - va->getFarRightDown());
	tvectY = tvectY.crossProduct(upVector.Y > 0 ? Pos - target : target - Pos);
	tvectY.normalize();

	if (isMouseKeyDown(2) && !Zooming)
	{
		if (!Translating)
		{
			TranslateStart = MousePos;
			Translating = true;
		}
		else
		{
			translate +=  tvectX * (TranslateStart.X - MousePos.X)*TranslateSpeed +
			              tvectY * (TranslateStart.Y - MousePos.Y)*TranslateSpeed;
		}
	}
	else if (Translating)
	{
		translate += tvectX * (TranslateStart.X - MousePos.X)*TranslateSpeed +
		             tvectY * (TranslateStart.Y - MousePos.Y)*TranslateSpeed;
		OldTarget = translate;
		Translating = false;
	}

	// Rotation ------------------------------------

	if (isMouseKeyDown(0) && !Zooming)
	{
		if (!Rotating)
		{
			RotateStart = MousePos;
			Rotating = true;
			nRotX = RotX;
			nRotY = RotY;
		}
		else
		{
			nRotX += (RotateStart.X - MousePos.X) * RotateSpeed;
			nRotY += (RotateStart.Y - MousePos.Y) * RotateSpeed;
		}
	}
	else if (Rotating)
	{
		RotX += (RotateStart.X - MousePos.X) * RotateSpeed;
		RotY += (RotateStart.Y - MousePos.Y) * RotateSpeed;
		nRotX = RotX;
		nRotY = RotY;
		Rotating = false;
	}

	// Set Pos ------------------------------------

	target = translate;

	Pos.X = nZoom + target.X;
	Pos.Y = target.Y;
	Pos.Z = target.Z;

	Pos.rotateXYBy(nRotY, target);
	Pos.rotateXZBy(-nRotX, target);

	// Rotation Error ----------------------------

	// jox: fixed bug: jitter when rotating to the top and bottom of y
	upVector.set(0,1,0);
	upVector.rotateXYBy(-nRotY);
	upVector.rotateXZBy(-nRotX+180.f);

	camera->setPosition(Pos);
	camera->setTarget(target);
	camera->setUpVector(upVector);
	LastCameraTarget = camera->getTarget();
}


bool CSceneNodeAnimatorCameraMaya::isMouseKeyDown(s32 key)
{
	return MouseKeys[key];
}


void CSceneNodeAnimatorCameraMaya::allKeysUp()
{
	for (s32 i=0; i<3; ++i)
		MouseKeys[i] = false;
}


//! Sets the rotation speed
void CSceneNodeAnimatorCameraMaya::setRotateSpeed(f32 speed)
{
	RotateSpeed = speed;
}


//! Sets the movement speed
void CSceneNodeAnimatorCameraMaya::setMoveSpeed(f32 speed)
{
	TranslateSpeed = speed;
}


//! Sets the zoom speed
void CSceneNodeAnimatorCameraMaya::setZoomSpeed(f32 speed)
{
	ZoomSpeed = speed;
}


//! Gets the rotation speed
f32 CSceneNodeAnimatorCameraMaya::getRotateSpeed() const
{
	return RotateSpeed;
}


// Gets the movement speed
f32 CSceneNodeAnimatorCameraMaya::getMoveSpeed() const
{
	return TranslateSpeed;
}


//! Gets the zoom speed
f32 CSceneNodeAnimatorCameraMaya::getZoomSpeed() const
{
	return ZoomSpeed;
}

ISceneNodeAnimator* CSceneNodeAnimatorCameraMaya::createClone(ISceneNode* node, ISceneManager* newManager)
{
	CSceneNodeAnimatorCameraMaya * newAnimator =
		new CSceneNodeAnimatorCameraMaya(CursorControl, RotateSpeed, ZoomSpeed, TranslateSpeed);
	return newAnimator;
}

} // end namespace
} // end namespace

Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Post by Lonesome Ducky »

You also have to declare the class "CSceneNodeAnimatorCameraMaya2." Class declarations are usually done inside an h file, and then the functions are actually written out in a cpp file.
gerydeft
Posts: 7
Joined: Tue Mar 30, 2010 1:36 am

Post by gerydeft »

any tutorial for this? i edited ISceneNode.h added new cam copied cpp and .h files from source and renamed the maya camera


wich files i exacly have to copy and where to put the declatarion?
gerydeft
Posts: 7
Joined: Tue Mar 30, 2010 1:36 am

Post by gerydeft »

I still coudn't find a solution for this could anyone tell me how to modify the maya cam ?

I tried to use this code :
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=33870

and

CSceneNodeAnimatorCameraMaya.cpp from source
ISceneNodeAnimatorCameraMaya.h form includes

i renamed all classnames inside the files added them to the project but still got alot of errors i think im missing some declarations from ISceneNodeAnimatorCameraMaya.h
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Post by randomMesh »

gerydeft wrote:could anyone tell me how to modify the maya cam ?
1. Add 3 empty files called 'IMyCameraAnimator.h', 'CMyCameraAnimator.h' and 'CMyCameraAnimator.cpp' to your project
2. Copy the contents of ISceneNodeAnimatorCameraMaya.h to IMyCameraAnimator.h
3. Copy the contents of CSceneNodeAnimatorCameraMaya.h to CMyCameraAnimator.h
4. Copy the contents of CSceneNodeAnimatorCameraMaya.cpp to CMyCameraAnimator.cpp
5. Edit the includes in CSceneNodeAnimatorCameraMaya.h and CSceneNodeAnimatorCameraMaya.cpp so they include your headers.
6. Make changes.

Usage would be

Code: Select all

#include "CMyCameraAnimator.h"

//add a 'normal' camera 
irr::scene::ICameraSceneNode* camera = smgr->addCameraSceneNode(); 

//create the camera animator 
irr::scene::IMyCameraAnimator* anim = new irr::scene::CMyCameraAnimator(/*arguments*/); 

//attach the animator to the camera 
camera->addAnimator(anim); 

//prevent memory leaks ;) 
anim->drop(); 
There is no need to edit Irrlicht files at all.
"Whoops..."
gerydeft
Posts: 7
Joined: Tue Mar 30, 2010 1:36 am

Post by gerydeft »

Thank you for your reply, I did what you wrote i get
...main.cpp `IMyCameraAnimator' is not a member of `irr::scene'

files looks like this:

http://gerydeft.uw.hu/CMyCameraAnimator.cpp

http://gerydeft.uw.hu/CMyCameraAnimator.h

http://gerydeft.uw.hu/IMyCameraAnimator.h

Image

I believe the problem that i coudn't set the headers well in each file and i have to rename "CSceneNodeAnimatorCameraMaya" in every file right to "MyCamera"? :idea:
Last edited by gerydeft on Sat Apr 03, 2010 2:55 pm, edited 1 time in total.
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Post by randomMesh »

You of course have to change the name of the class inside the new files.
Means ISceneNodeAnimatorCameraMaya becomes to IMyCameraAnimator, etc.

Code: Select all

class IMySceneNodeAnimator : public ISceneNodeAnimator
{

Code: Select all

class CMySceneNodeAnimator : public IMySceneNodeAnimator 
{

Code: Select all

//! constructor
CMySceneNodeAnimator::CMySceneNodeAnimator(gui::ICursorControl* cursor, f32 rotate, f32 zoom, f32 translate)
etc.
"Whoops..."
Post Reply