Game Development Community

Trying to get this to work

by Wesley Hopson · in RTS Starter Kit · 10/06/2008 (10:54 pm) · 3 replies

I am trying to modify the process tick of the RTScamera so that i can control the camera with the global $mvYaw and $mvPitch and more specficly the mouse X and Y axis. I could get some results out of just using the setYaw and setpitch methods but it was just too jerky so I based this around how those two methods work to the best of my knowledge. I am a total noob when it comes to the engine code to be honest so i am probably missing somthing that should be obvious to anyone who acctually knows what they are doing.

This is my best guess of what i need to do based on all my searching (so far) of the documentation and some really heavy attempt to read the code.

void RTSCamera::processTick(const Move* move)
{
Parent::processTick(move);

RTSCameraData* data = (RTSCameraData*)mDataBlock;

if (Con::getFloatVariable("$mvPitch", 0.0) != 0.0)
{
Con::printf("My Pitch is called");
mTargetAngle = mDegToRad(mClampF(Con::getFloatVariable("$mvPitch", 0.0), data->mMinAngle, data->mMaxAngle));
}

if (Con::getFloatVariable("$mvYaw", 0.0) != 0.0)
{
Con::printf("My Yaw is called");
mTargetYawAngle = mDegToRad(Con::getFloatVariable("$mvYaw", 0.0));
// Make sure we're not getting cranzy angles!
while(mTargetYawAngle > M_2PI_F)
{
mTargetYawAngle -= M_2PI_F;
mCurrYawAngle -= M_2PI_F;
mPrevYawAngle -= M_2PI_F;
}
while(mTargetYawAngle < -M_2PI_F)
{
mTargetYawAngle += M_2PI_F;
mCurrYawAngle += M_2PI_F;
mPrevYawAngle += M_2PI_F;
}
}

mPrevPos = mTargetPos;
mPrevYawAngle = mCurrYawAngle;
mPrevHeight = mCurrHeight;
mPrevAngle = mCurrAngle;

if (mTargetHeight != mCurrHeight)
{
if (mCurrHeight < mTargetHeight)
{
F32 step = mDataBlock->mMovementSpeed * TickSec;
if (mCurrHeight + step > mTargetHeight)
mCurrHeight = mTargetHeight;
else
mCurrHeight += step;
}
else
{
F32 step = -mDataBlock->mMovementSpeed * TickSec;
if (mCurrHeight + step < mTargetHeight)
mCurrHeight = mTargetHeight;
else
mCurrHeight += step;
}
}

if (mTargetAngle != mCurrAngle)
{//block1
if (mCurrAngle < mTargetAngle)
{
F32 step = gDegsPerTick;
if (mCurrAngle + step > mTargetAngle)
mCurrAngle = mTargetAngle;
else
mCurrAngle += step;
}
else
{
F32 step = -gDegsPerTick;
if (mCurrAngle + step < mTargetAngle)
mCurrAngle = mTargetAngle;
else
mCurrAngle += step;
}
}

if (mTargetYawAngle != mCurrYawAngle)
{//block2
if (mCurrYawAngle < mTargetYawAngle)
{
F32 step = gDegsPerTick;
if (mCurrYawAngle + step > mTargetYawAngle)
mCurrYawAngle = mTargetYawAngle;
else
mCurrYawAngle += step;
}
else
{
F32 step = -gDegsPerTick;
if (mCurrYawAngle + step < mTargetYawAngle)
mCurrYawAngle = mTargetYawAngle;
else
mCurrYawAngle += step;
}
}

#1
10/06/2008 (10:54 pm)
MatrixF xRot, zRot;
xRot.set(EulerF(mPrevAngle, 0, 0));
zRot.set(EulerF(0, 0, mPrevYawAngle));
MatrixF temp;
temp.mul(zRot, xRot);

// Update pos
Point3F pos;
pos.x = mTargetPos.x;
pos.y = mTargetPos.y;
pos.z = getTerrHeight(mTargetPos) + mCurrHeight;

//setPosition(pos);
temp.setPosition(pos);
setTransform(temp);

if (move)
{
//Con::printf("move true");
// Move appropriately based on our direction.
F32 tempX, tempY;
tempX = move->x * TickSec * mDataBlock->mMovementSpeed;
tempY = move->y * TickSec * mDataBlock->mMovementSpeed;
mTargetPos.x += ((tempX * mCos(-1 * mCurrYawAngle)) - (tempY * mSin(-1 * mCurrYawAngle)));
mTargetPos.y += ((tempY * mCos(-1 * mCurrYawAngle)) + (tempX * mSin(-1 * mCurrYawAngle)));

//Con::printf("TempX = %f", tempX);
//Con::printf("TempY = %f", tempY);

// tell the server what we are doing
if(isClientObject())
{
//Con::printf("post event");
GameConnection *conn = GameConnection::getConnectionToServer();
if(conn)
{
RTSCameraUpdate *rtsCamUpdate = new RTSCameraUpdate(this, !isClientObject());
//not sure these if's are really needed structuraly i do not think so although i did try adding
//them just to see if it would make it work but no such luck
// if (Con::getFloatVariable("$mvYaw", 0.0) != 0.0)
// {
// rtsCamUpdate->setYawAngle(Con::getFloatVariable("$mvYaw", 0.0));
// }

// if (Con::getFloatVariable("$mvYaw", 0.0) != 0.0)
// {
// rtsCamUpdate->setPitchAngle(Con::getFloatVariable("$mvYaw", 0.0));
// }
conn->postNetEvent(rtsCamUpdate);
}
}
}

if(getControllingClient() && mContainer)
updateContainer();
}

it compiles and i have confirmed it is getting input for the mtargetangle and mtargetyawangle. It just does nothing is the problem.

I have tried comparing the Camera.cc's code to the RTSCamera.cc's code to try and make sense of exactly what I needed to do as well but they seem to be kinda apples and oranges and only faintly share similarities.
#2
10/07/2008 (7:39 pm)
Well I think i have narrowed my problem down some by comparing the runs of the set functions to runs of the changing variable and the only real difference i can find is that the interpolate tick is getting called with the set function but not with my code. I know almost nothing about the interpolate tick most importantly when/how it is run and why.

EDIT:
Ok found out why it does not work. As near as i can tell the mTargetAngle and mTargetYawAngle variables only hold the values i assign them in the process tick while the $mvYaw and $mvPitch exposed variables hold thier value.

I have hit a literal wall here and have no idea what the heck to do how the heck can i get the two class variables to acctually hold a value they are given furthermore what the heck is going on that they are getting cleared out in the first place. I am really hopeing thier is a very good reason this is happening because it is driving me insane here.
#3
10/10/2008 (10:05 pm)
I have acctualy kinda given up on getting direct input from a variable mostly because i do not think it is what is causing the problems with the camera. What I am noticing about how the set functions is that the RTS camera kinda seems to over rotate with large values and under rotate with small ones.

I am now working on evening it out. As near as i can tell the interpolate function of the RTS camera basicly does the same thing as the process tick in fact i put a empty return statement at the top of the interpolate function of the rts camera and found it seems to not acctualy change anything in the cameras behavior as near as i can tell.

Do you guys know if the interpolate function of the RTS camera is even needed.

EDIT:
Ok i found out what to change in my code to apparently make everything work right so all is gravy.

Apparently it is because the RTS camera is setup to only make incremental movements when you try and roate or pitch the cammera. It is a simple fix all you have to do is yank out the 2 if statements dealing with it and your good to go. Of course i am not sure what other problems might arise from doing this i will have to look into it some when i get back around to engine coding.

namely removing these seem to do the trick.

if (mTargetHeight != mCurrHeight)
{
if (mCurrHeight < mTargetHeight)
{
F32 step = mDataBlock->mMovementSpeed * TickSec;
if (mCurrHeight + step > mTargetHeight)
mCurrHeight = mTargetHeight;
else
mCurrHeight += step;
}
else
{
F32 step = -mDataBlock->mMovementSpeed * TickSec;
if (mCurrHeight + step < mTargetHeight)
mCurrHeight = mTargetHeight;
else
mCurrHeight += step;
}
}

if (mTargetAngle != mCurrAngle)
{//block1
if (mCurrAngle < mTargetAngle)
{
F32 step = gDegsPerTick;
if (mCurrAngle + step > mTargetAngle)
mCurrAngle = mTargetAngle;
else
mCurrAngle += step;
}
else
{
F32 step = -gDegsPerTick;
if (mCurrAngle + step < mTargetAngle)
mCurrAngle = mTargetAngle;
else
mCurrAngle += step;
}
}

if (mTargetYawAngle != mCurrYawAngle)
{//block2
if (mCurrYawAngle < mTargetYawAngle)
{
F32 step = gDegsPerTick;
if (mCurrYawAngle + step > mTargetYawAngle)
mCurrYawAngle = mTargetYawAngle;
else
mCurrYawAngle += step;
}
else
{
F32 step = -gDegsPerTick;
if (mCurrYawAngle + step < mTargetYawAngle)
mCurrYawAngle = mTargetYawAngle;
else
mCurrYawAngle += step;
}