Camera pitch limitations

Problems building or running the engine, queries about how to use features etc.
Post Reply
User avatar
Shtong
Gnoblar
Posts: 23
Joined: Sat Apr 23, 2005 1:46 pm
Location: Paris, France

Camera pitch limitations

Post by Shtong » Tue May 17, 2005 9:56 pm

After (unsuccessfully) trying some ways to limit a node's pitch values, in order to make it impossible to be upside-down, I search around here in forum and wiki some explanations, but the topics I found didn't get any answers, and wiki does not seem to explain how to do that.

I tried to do this :

Code: Select all

void Pawn::commandPitch(const Radian& angle)
{
	mNextPitch = angle;

	//Do not allow to reverse camera
	//temp is the final node's pitch after making a pitch(mNextPitch)
	Radian temp = mOgreNode->getWorldOrientation().getPitch() + mNextPitch;
	// Will the result be out of limits ?
	if(temp > mMaxPitch || temp < mMinPitch)
	{
		// Yeah, so substract exceedent to the command
		if(mNextPitch > Degree(0))
			mNextPitch -= temp - mMaxPitch;
		else
			mNextPitch += temp - mMinPitch;
	}

	// Now we can safely call cameraNode->pitch(mNextPitch)
}
This don't works, because of the strange values the getPitch function returns. I get a value between 1.0e-7 and 1.0e-10 (except at the beginning, when no pitch has been applied yet, it returns 0). I tried this with getOrientation and _getDerivedOrientation, inversed quaternions... but I always get the same values range...
What should I use to have correct values, or who do I use values returned by getPitch if they're right ?

Thanks
0 x

User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19261
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
Contact:

Post by sinbad » Tue May 17, 2005 11:51 pm

There were bugs in the getPitch() code previously, please update the latest CVS on the 'v1-0' to get the fix.
0 x

User avatar
Shtong
Gnoblar
Posts: 23
Joined: Sat Apr 23, 2005 1:46 pm
Location: Paris, France

Post by Shtong » Wed May 18, 2005 2:21 pm

Huh, my last CVS checkout is 2 weeks old, but I'll try this anyway...
0 x

User avatar
vilgeits
Goblin
Posts: 298
Joined: Tue Aug 02, 2005 10:41 pm

Post by vilgeits » Tue Mar 28, 2006 12:47 pm

still not working for me besides i change it for something like:

Code: Select all

void Pawn::commandPitch(const Radian& angle)
{
   mNextPitch = angle;

   //Do not allow to reverse camera
   //temp is the final node's pitch after making a pitch(mNextPitch)
   Radian temp = mCamera->getOrientation().getPitch() + mNextPitch;
   // Will the result be out of limits ?
   if(temp > mMaxPitch || temp < mMinPitch)
   {
      // Yeah, so substract exceedent to the command
      if(mNextPitch > Degree(0))
         mNextPitch -= temp - mMaxPitch;
      else
         mNextPitch += temp - mMinPitch;
   }

   // Now we can safely call cameraNode->pitch(mNextPitch)
} 
0 x

User avatar
vilgeits
Goblin
Posts: 298
Joined: Tue Aug 02, 2005 10:41 pm

Post by vilgeits » Wed Mar 29, 2006 8:34 am

is using the camera target the onlyway to do this? :cry:
0 x

User avatar
ahmedali
Gnome
Posts: 302
Joined: Fri Feb 20, 2004 8:52 pm
Location: Lahore, Pakistan

Post by ahmedali » Wed Mar 29, 2006 12:37 pm

vilgeits wrote:still not working for me besides i change it for something like:

Code: Select all

void Pawn::commandPitch(const Radian& angle)
{
   mNextPitch = angle;

   //Do not allow to reverse camera
   //temp is the final node's pitch after making a pitch(mNextPitch)
   Radian temp = mCamera->getOrientation().getPitch() + mNextPitch;
   // Will the result be out of limits ?
   if(temp > mMaxPitch || temp < mMinPitch)
   {
      // Yeah, so substract exceedent to the command
      if(mNextPitch > Degree(0))
         mNextPitch -= temp - mMaxPitch;
      else
         mNextPitch += temp - mMinPitch;
   }

   // Now we can safely call cameraNode->pitch(mNextPitch)
} 
Your method is over complicated. You just want to clamp an input between Min and Max limits?

do like this

Code: Select all


originalPitch = mCamera->getOrientation().getPitch()
newPitch = temp(the input) + originalPitch

to limit....
if newPitch > maxPitch
    newPitch = maxPitch
if newPitch < minPitch
    newPitch = minPitch

IMPORTANT:
now dont use pitch() here but use setPitch()


0 x

User avatar
vilgeits
Goblin
Posts: 298
Joined: Tue Aug 02, 2005 10:41 pm

Post by vilgeits » Thu Mar 30, 2006 9:07 am

setPitch() ¿?

currently i use:

Code: Select all

	
		iCamera->yaw(iRotX);
		Ogre::Radian originalPitch = iCamera->getOrientation().getPitch();
		Ogre::Radian newPitch = iRotY + originalPitch;

		if (Ogre::Math::Abs(newPitch) < Ogre::Radian(Ogre::Math::PI/2)) 
		{
			iCamera->pitch(iRotY);	
		}
but don't works fine at all (only facing in one direction, not in the inverse)
0 x

User avatar
vilgeits
Goblin
Posts: 298
Joined: Tue Aug 02, 2005 10:41 pm

Post by vilgeits » Thu Mar 30, 2006 10:04 am

0 x

Post Reply