Jump to content

Camera Rotation Independant Of Player Control Object?


Steve_Yorkshire

Recommended Posts

I was wondering if anyone had any experience with separating camera control (specifically orbitObject or Third Person) from inheriting the player (controlObject) head rotation?


I thought that creating a new move trigger group to get input would be best, but then was not sure exactly how to pass it over to the camera. If the player is the controlObject the camera's process tick doesn't get "move" called on it (as it would if it was the controlObject) and I from there I baffled myself with science and math ... :?


The new input code is based off existing rotation input:

MoveManager.h

struct Move
{
   enum { ChecksumBits = 16, ChecksumMask = ((1<
//...
   U32 checksum;
 
   U32 pcamyaw, pcampitch, pcamroll;//yorks cam in
   F32 camyaw, campitch, camroll;//yorks cam in
 
   bool deviceIsKeyboardMouse;
//...
};
//.............
class MoveManager
{
public:
   static bool mDeviceIsKeyboardMouse;
//...
   static F32 mYAxis_R;
 
   //yorks cam start
   static F32 mCamPitch;
   static F32 mCamYaw;
   static F32 mCamRoll;
 
   static F32 mCamPitchUpSpeed;
   static F32 mCamPitchDownSpeed;
   static F32 mCamYawLeftSpeed;
   static F32 mCamYawRightSpeed;
   static F32 mCamRollLeftSpeed;
   static F32 mCamRollRightSpeed;
   //yorks cam end
 
   static U32 mTriggerCount[MaxTriggerKeys];
//...

 

MoveManager.cpp

//...
F32 MoveManager::mYAxis_R = 0;
 
//yorks cam start
F32 MoveManager::mCamPitch = 0;
F32 MoveManager::mCamYaw = 0;
F32 MoveManager::mCamRoll = 0;
 
F32 MoveManager::mCamPitchUpSpeed = 0;
F32 MoveManager::mCamPitchDownSpeed = 0;
F32 MoveManager::mCamYawLeftSpeed = 0;
F32 MoveManager::mCamYawRightSpeed = 0;
F32 MoveManager::mCamRollLeftSpeed = 0;
F32 MoveManager::mCamRollRightSpeed = 0;
//yorks cam end
 
U32 MoveManager::mTriggerCount[MaxTriggerKeys] = { 0, };
//...
 
void MoveManager::init()
{
//...
   Con::addVariable("mvRollRightSpeed", TypeF32, &mRollRightSpeed, 
      "Right roll speed.\n"
	   "@ingroup Game");
 
   //yorks cam start
   Con::addVariable("mvCamPitch", TypeF32, &mCamPitch,
	   "Current pitch value, typically applied through input devices, such as a mouse.\n"
	   "@ingroup Game");
   Con::addVariable("mvCamYaw", TypeF32, &mCamYaw,
	   "Current yaw value, typically applied through input devices, such as a mouse.\n"
	   "@ingroup Game");
   Con::addVariable("mvCamRoll", TypeF32, &mCamRoll,
	   "Current roll value, typically applied through input devices, such as a mouse.\n"
	   "@ingroup Game");
   Con::addVariable("mvCamPitchUpSpeed", TypeF32, &mCamPitchUpSpeed,
	   "Upwards pitch speed.\n"
	   "@ingroup Game");
   Con::addVariable("mvCamPitchDownSpeed", TypeF32, &mCamPitchDownSpeed,
	   "Downwards pitch speed.\n"
	   "@ingroup Game");
   Con::addVariable("mvCamYawLeftSpeed", TypeF32, &mCamYawLeftSpeed,
	   "Left Yaw speed.\n"
	   "@ingroup Game");
   Con::addVariable("mvCamYawRightSpeed", TypeF32, &mCamYawRightSpeed,
	   "Right Yaw speed.\n"
	   "@ingroup Game");
   Con::addVariable("mvCamRollLeftSpeed", TypeF32, &mCamRollLeftSpeed,
	   "Left roll speed.\n"
	   "@ingroup Game");
   Con::addVariable("mvCamRollRightSpeed", TypeF32, &mCamRollRightSpeed,
	   "Right roll speed.\n"
	   "@ingroup Game");
   //yorks cam end
 
   // Dual-analog
   Con::addVariable( "mvXAxis_L", TypeF32, &mXAxis_L, 
      "Left thumbstick X axis position on a dual-analog gamepad.\n"
	   "@ingroup Game" );
//...
}
 
Move::Move()
{
//...
   sendCount=0;
   pcamyaw = 0; pcampitch = 0; pcamroll = 0;//yorks cam in
   camyaw = 0; campitch = 0; camroll = 0;//yorks cam in
 
   checksum = false;
//...
}
 
void Move::unclamp()
{
//...
   z = (pz - 16) / F32(16);
 
   //yorks cam start
   camyaw = IANG2FANG(pcamyaw);
   campitch = IANG2FANG(pcampitch);
   camroll = IANG2FANG(pcamroll);
   //yorks cam end
}
 
void Move::clamp()
{
//...
   proll = FANG2IANG(roll);
 
   //yorks cam start
   camyaw = clampAngleClamp(camyaw);
   campitch = clampAngleClamp(campitch);
   camroll = clampAngleClamp(camroll);
 
   // angles are all 16 bit.
   pcamyaw = FANG2IANG(camyaw);
   pcampitch = FANG2IANG(campitch);
   pcamroll = FANG2IANG(camroll);
   //yorks cam end
 
   px = clampRangeClamp(x);
//...
}
 
bool Move::packMove(BitStream *stream, const Move* basemove, bool alwaysWriteAll)
{
//...
                             (pz!=basemove->pz)         ||
							 //yorks cam start
							 (pcamyaw != basemove->pcamyaw) ||
							 (pcampitch != basemove->pcampitch) ||
							 (pcamroll != basemove->pcamroll) ||
							 //yorks cam end
                             (deviceIsKeyboardMouse!=basemove->deviceIsKeyboardMouse) ||
                             (freeLook!=basemove->freeLook) ||
                             triggerDifferent;
 
/...
      if(stream->writeFlag(proll != basemove->proll))
      stream->writeInt(proll, 16);
 
	  //yorks cam start
	  if (stream->writeFlag(pcamyaw != basemove->pcamyaw))
		  stream->writeInt(pcamyaw, 16);
	  if (stream->writeFlag(pcampitch != basemove->pcampitch))
		  stream->writeInt(pcampitch, 16);
	  if (stream->writeFlag(pcamroll != basemove->pcamroll))
		  stream->writeInt(pcamroll, 16);
	  //yorks cam end
 
      if (stream->writeFlag(px != basemove->px))
         stream->writeInt(px, 6);
//...
 
bool Move::unpackMove(BitStream *stream, const Move* basemove, bool alwaysReadAll)
{
//...
      proll = stream->readFlag() ? stream->readInt(16) : basemove->proll;
 
	  //yorks cam start
	  pcamyaw = stream->readFlag() ? stream->readInt(16) : basemove->pcamyaw;
	  pcampitch = stream->readFlag() ? stream->readInt(16) : basemove->pcampitch;
	  pcamroll = stream->readFlag() ? stream->readInt(16) : basemove->pcamroll;
	  //yorks cam end
 
      px = stream->readFlag() ? stream->readInt(6) : basemove->px;
//...
}

 

MoveList.h

bool MoveList::getNextMove(Move &curMove)
{
/...
   MoveManager::mRoll = 0;
 
   //yorks cam start
   F32 campitchAdd = MoveManager::mCamPitchUpSpeed - MoveManager::mCamPitchDownSpeed;
   F32 camyawAdd = MoveManager::mCamYawLeftSpeed - MoveManager::mCamYawRightSpeed;
   F32 camrollAdd = MoveManager::mCamRollRightSpeed - MoveManager::mCamRollLeftSpeed;
 
   curMove.campitch = MoveManager::mCamPitch + campitchAdd;
   curMove.camyaw = MoveManager::mCamYaw + camyawAdd;
   curMove.camroll = MoveManager::mCamRoll + camrollAdd;
 
   MoveManager::mCamPitch = 0;
   MoveManager::mCamYaw = 0;
   MoveManager::mCamRoll = 0;
   //yorks cam end
 
   curMove.x = MoveManager::mRightAction - MoveManager::mLeftAction + MoveManager::mXAxis_L;
/..
}

 

TorqueScript: game/scripts/client/default.bind.cs - change mouse yaw/pitch to take the new inputs for testing

function yaw(%val)
{
//...
 
   $mvCamYaw += %yawAdj;//yorks was $mvYaw
}
 
function pitch(%val)
{
//...
 
   $mvCamPitch += %pitchAdj;//yorks was $mvPitch
}

 

That all works as hoped and can be tested in Player.cpp UpdateMove() - just above move->pitch etc:

//yorks cam start
			F32 pcam = move->campitch;
			if (pcam > M_PI_F)
				pcam -= M_2PI_F;
			F32 ycam = move->camyaw;
			if (ycam > M_PI_F)
				ycam -= M_2PI_F;
 
			if (!mIsZero(ycam) || !mIsZero(pcam))
			{
				Con::printf("camRotation Yaw '%d' ", ycam);
				Con::printf("camRotation Pitch '%d' ", pcam);
			}
			//yorks cam end

 

Unfortunately after that I'm unsure how to proceed to affect the camera's rotation with it, and camera processTick(constMove *move) does not get the move passed as it is not the controlObject. I was thinking maybe get the controlObject/Player camera and thenget/set rotation like that but it seems like an ugly hack and I already have another ugly hack in TorqueScript to rotate it which I'm trying to get rid of.


Anyhow, any bright ideas welcome.

Link to comment
Share on other sites

I don't know if I'd call it "an ugly hack" - you have to set the camera position/rotation, and it seems that either in the control object's tick or the camera tick you're going to have to do something about it. It will logically go in one of these two places, so to me it sounds like something that just needs to be done.


I've wanted to make the "right button down to control camera rotation/orbit" from the editor part of the game camera for a while now - this sounds like another good addition to the camera's list of tricks....

Link to comment
Share on other sites

After a fair bit hunting around I discovered T3D\gameBase\std\stdGameProcess.cpp is where moves to all objects are passed using:

void StdClientProcessList::onTickObject( ProcessObject *obj )

and

void StdServerProcessList::onTickObject( ProcessObject *pobj )

 

From here I could call the cameraObject when it was not the controlObject by adding:

if  ( con && con->getCameraObject() == obj )

 

Changing camera.cpp to take camyaw and campitch instead of yaw/pitch, I was a bit out of my depth to put it mildly and still didn't seem to get any results.

Think I might abandon this one and stick with my rubbishy hack :?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...