Limiting the pitch of a camera

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
ijshockeymen
Gnoblar
Posts: 2
Joined: Wed Jul 02, 2014 12:41 pm

Limiting the pitch of a camera

Post by ijshockeymen »

Hi,
( i was writing a story of how i got this idea but instead replaced it with this line because; probably you are not bothered about my story :lol: )

here is how it works:

Code: Select all

// Pitch
	float oldVal = mViewAnglePitch;
	mViewAnglePitch += (evt.state.Y.rel * -0.1f);

	if(mViewAnglePitch < 90.0f && mViewAnglePitch > -90.0f)
	{
		m_pCamera->pitch(Ogre::Degree(evt.state.Y.rel * -0.1f));
	}
	else
	{
		mViewAnglePitch = oldVal;
	}


// Yaw
	Ogre::Real scale = 0.13f;
	scale = scale* evt.state.X.rel;
	mNinjaNode->yaw(Ogre::Degree(-scale));
	m_pCamera->yaw(Ogre::Degree(-scale));
	return true;


if you want more information about how i did it or how it works or more code
just leave a reply below.

(i am running low on time, probably will expand this post tonight )

i salute all humanoids!
User avatar
areay
Bugbear
Posts: 819
Joined: Wed May 05, 2010 4:59 am
Location: Auckland, NZ
x 69

Re: Limiting the pitch of a camera

Post by areay »

There's a good system here too http://www.ogre3d.org/tikiwiki/tiki-ind ... e=Cookbook it's pretty similar.
ijshockeymen
Gnoblar
Posts: 2
Joined: Wed Jul 02, 2014 12:41 pm

Re: Limiting the pitch of a camera

Post by ijshockeymen »

areay wrote:There's a good system here too http://www.ogre3d.org/tikiwiki/tiki-ind ... e=Cookbook it's pretty similar.
yea but i calculate my pitch limit different and dont have all those scene nodes. i dont reset my pitch angle with quaternions as is done by the other system because it will also reset the yaw.
(that is because i dont have a sperate pitch and yaw node )
drwbns
Orc Shaman
Posts: 788
Joined: Mon Jan 18, 2010 6:06 pm
Location: Costa Mesa, California
x 24

Re: Limiting the pitch of a camera

Post by drwbns »

Is there any way to get the yaw value and feed it back into the new reset pitch quaternion?
User avatar
areay
Bugbear
Posts: 819
Joined: Wed May 05, 2010 4:59 am
Location: Auckland, NZ
x 69

Re: Limiting the pitch of a camera

Post by areay »

drwbns wrote:Is there any way to get the yaw value and feed it back into the new reset pitch quaternion?
How about creating a new quaternion based on yawing around the default up-axis?

Code: Select all

/*pseudocode*/
Ogre::Quaternion newlyResetQuat(Ogre::Radian(yaw), Ogre::Vector3::UNIT_Y);
amartin
Halfling
Posts: 87
Joined: Wed Aug 14, 2013 6:55 am
Location: Norway
x 13

Re: Limiting the pitch of a camera

Post by amartin »

There is a small bug in that logic. If the value is over 90 or less than 90 you want to set it to the limit not to the old value. It is possible but probably rare for the mouse to move far enough in 1 frame that the value ends up outside the limit but the original value is well within it. In most cases this won't be a problem but its better to handle it that expect people not to notice that sometimes you get to 85 degrees and other times 87 degrees before it locks out.
drwbns
Orc Shaman
Posts: 788
Joined: Mon Jan 18, 2010 6:06 pm
Location: Costa Mesa, California
x 24

Re: Limiting the pitch of a camera

Post by drwbns »

He's right. Put a couple statements checking

Code: Select all

//psuedo if angle > 90 angle = 90;  if angle < -90 angle = -90;
This will guarantee the viewangle will not be compromised.
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 538

Re: Limiting the pitch of a camera

Post by Kojack »

I find it's much easier to generate a new camera orientation each frame and keep the pitch/yaw values in explicit variables. No need to normalise orientations to re-orthogonalise them (due to float error / drift), they are generated correctly each frame.