Advanced Camera
by Thomas \"Man of Ice\" Lund · 04/03/2008 (11:57 am) · 480 comments
Download Code File
Description
Over time a lot of people have released camera resources, but some do not work anymore, others are hard to implement etc.
I've tried to assemble a single class to add to the engine that implements them all in one go using the same basic architecture. This enables minimum code bloat and makes it way easier to keep the code up to date.
Change log
March 3rd, 2005
Manoel made some changes to the orbit camera. Works in multiplayer now and is much nicer by using console variables
February 3rd, 2005
Fixed small big in interpolation.
February 2nd, 2005
Major changes in this one with various contributors.
* Static camera mode
* Smooth interpolation and transition between modes
* Smooth orbit camera!!!
* Vertical freedom mode when in 3rd person
* Better collision check with terrain and interiors
* Mouse control of orbit camera
* Totally reworked codebase and lots of cleanups. Much more readable now
Manoel Neto contributed the new orbit camera and the interpolation
Zik Saleeba contributed the vertical freedom mode and better collision check
Thanks a lot!!!!
I have marked changes with a New in the text below for those who upgrade
January 23rd, 2005
Minor changes. Larger update soon with new functionality
* Now takes GameBase objects as target + player
* Removed debug message in orbit camera
* Added getters for player and target object
June 25th, 2004
Updated the bindings for orbit camera. Switched left+right.
June 23rd, 2004
A big thanks to Stephen Zepp for contributing with an orbit camera mode. Its added to the resource, and is perfect for RTS games and action adventures. It allows for a camera to rotate around a user as if placed on a sphere. The user can zoom in/out, rotate and tilt the camera.
June 9th, 2004
Added getter/setter for the 3 offset values accessible from script
Added a "follow terrain" mode for the third person camera, so the camera follows the terrain slope - doesnt work perfectly
April 5th, 2004
All camera modes now use a raycast to not get hidden behind terrain or interiors
April 3rd, 2004
This release is the first release, and might not be as "advanced" as the author would like, but its time to release it and get some feedback to further enhance it down the road.
Camera Modes Implemented
The resource currently implements the following camera systems:
* Track Mode
This is the same as the tracking camera resource posted by Cory Osborn. A stationary camera tracks the player and keeps him in focus.
* New Static Mode
Camera stays in its position and rotation. Useful for e.g. scene based adventures where the camera doesnt move with the players
* Third Person Mode
The camera is placed at an offset behind the player and rotates with the player. The camera itself is not controllable
* Third Person Track Mode
The camera is placed in third person mode but rotated so it always looks at a specified object, but with the player in full view
* God View
Camera is placed at an offset from the player and does not rotate with the player. This is your typical "Diablo" kind of camera.
* New Orbit Mode
Camera is placed on a sphere looking at the player, and can rotate/tilt and zoom controlled by the player. There are bindings to the mouse when in single player game (server and client on same machine)
Movie
Here is a small movie displaying the different camera modes (3 MB)
www.codejar.com/advancedcamerademo.wmv
How to Add
First off all you need to take the attached advancedCamera.cc/h files and add to engine\game and add them to the project.
Then you need to expose the camera object in GameConnection as described in Cory's resource www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=4720
I took the liberty to paste the relevant parts in here too
Exposing mCameraObject
The first thing you want to do is add console method's to access the GameConnection setCameraObject/getCameraObject methods. I added these to GameConnection.cc right after the console method for getControlObject:
After playing around with it, I also found you need some adjustments to the setCameraObject and setControlObject methods - otherwise the client connection can screw things up if you bounce the same object from your connection's control to camera or vice versa. Here is my GameConnection::setControlObject:
and here is my GameConnection::setCameraObject:
Camera read/write packets
None of this will work unless the client copy of the camera object gets packets updated. Here we're going to modify GameConnection::readPacket and GameConnection::writePacket.
In GameConnection::readPacket, find this block of code:
and change it to
In GameConnection::writePacket, find this block of code:
and change it to:
Recompile it all and the engine is ready to go.
Script
To use the camera you need to follow some of Corys resource, but with some modifications. Datablock and naming has changed
First, add a datablock for the tracking camera to /fps/server/scripts/camera.cs:
Next, add it to the connection just like is currently done with the base camera class. Add this inside GameConnection::onClientEnterGame (/fps/server/scripts/game.cs), right after %this.camera is set up:
We'll need to clean it up after the client leaves the game, so add this to GameConnection::onClientLeaveGame
We need to tell it what to do when added and assign the connection's camera object, so add this to the end of GameConnection::createPlayer:
And we'll want to unhook it when the player dies. Insert this at the beginning of GameConnection::onDeath:
The last thing to know, is if you're in first-person mode, GameConnection automatically uses the control object to render the engine rather than the camera object. So if you don't see this working when you first enter a mission, toggle out of first-person.
Orbit mode
To use the orbit camera, one needs to add some key binds to manipulating the camera.
All you need to do, is add the following to your client\config.cs or better to your client\scripts\default.bind.cs
Remember to comment out the mouse commands for the player movement, as these are overwritten by the orbit camera controls
Script API
To use the different camera modes you can use the following API
Selecting the camera mode is done with e.g.:
Prior to calling the above modes you have to set the PlayerObject using
To use the 3rd person target mode you also need to set a TargetObject using
To use the static or tracking camera you need to set the position the camera should be placed suing
To use the follow terrain mode in 3rd person you give a bool to
To use the vertical freedom mode in 3rd person you give a bool to
The offset values in the datablock can be changed for the camera object via script using
The orbit camera can be manipulated from script using
You can also manipulate the orbit camera directly by assigning values to the following variables
[code]
$advCamera::Yaw
$advCamera::Pitch
$advCamera::Zoom
$advCamera::azimuth
$advCamera::declination
$advCamera::zoomDistance
[code]
All camera modes coexist, so you can set the position, player object and target object once and then switch camera modes around as you see fit. Switching mode will not clear the old objects/positions.
Description
Over time a lot of people have released camera resources, but some do not work anymore, others are hard to implement etc.
I've tried to assemble a single class to add to the engine that implements them all in one go using the same basic architecture. This enables minimum code bloat and makes it way easier to keep the code up to date.
Change log
March 3rd, 2005
Manoel made some changes to the orbit camera. Works in multiplayer now and is much nicer by using console variables
February 3rd, 2005
Fixed small big in interpolation.
February 2nd, 2005
Major changes in this one with various contributors.
* Static camera mode
* Smooth interpolation and transition between modes
* Smooth orbit camera!!!
* Vertical freedom mode when in 3rd person
* Better collision check with terrain and interiors
* Mouse control of orbit camera
* Totally reworked codebase and lots of cleanups. Much more readable now
Manoel Neto contributed the new orbit camera and the interpolation
Zik Saleeba contributed the vertical freedom mode and better collision check
Thanks a lot!!!!
I have marked changes with a New in the text below for those who upgrade
January 23rd, 2005
Minor changes. Larger update soon with new functionality
* Now takes GameBase objects as target + player
* Removed debug message in orbit camera
* Added getters for player and target object
June 25th, 2004
Updated the bindings for orbit camera. Switched left+right.
June 23rd, 2004
A big thanks to Stephen Zepp for contributing with an orbit camera mode. Its added to the resource, and is perfect for RTS games and action adventures. It allows for a camera to rotate around a user as if placed on a sphere. The user can zoom in/out, rotate and tilt the camera.
June 9th, 2004
Added getter/setter for the 3 offset values accessible from script
Added a "follow terrain" mode for the third person camera, so the camera follows the terrain slope - doesnt work perfectly
April 5th, 2004
All camera modes now use a raycast to not get hidden behind terrain or interiors
April 3rd, 2004
This release is the first release, and might not be as "advanced" as the author would like, but its time to release it and get some feedback to further enhance it down the road.
Camera Modes Implemented
The resource currently implements the following camera systems:
* Track Mode
This is the same as the tracking camera resource posted by Cory Osborn. A stationary camera tracks the player and keeps him in focus.
* New Static Mode
Camera stays in its position and rotation. Useful for e.g. scene based adventures where the camera doesnt move with the players
* Third Person Mode
The camera is placed at an offset behind the player and rotates with the player. The camera itself is not controllable
* Third Person Track Mode
The camera is placed in third person mode but rotated so it always looks at a specified object, but with the player in full view
* God View
Camera is placed at an offset from the player and does not rotate with the player. This is your typical "Diablo" kind of camera.
* New Orbit Mode
Camera is placed on a sphere looking at the player, and can rotate/tilt and zoom controlled by the player. There are bindings to the mouse when in single player game (server and client on same machine)
Movie
Here is a small movie displaying the different camera modes (3 MB)
www.codejar.com/advancedcamerademo.wmv
How to Add
First off all you need to take the attached advancedCamera.cc/h files and add to engine\game and add them to the project.
Then you need to expose the camera object in GameConnection as described in Cory's resource www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=4720
I took the liberty to paste the relevant parts in here too
Exposing mCameraObject
The first thing you want to do is add console method's to access the GameConnection setCameraObject/getCameraObject methods. I added these to GameConnection.cc right after the console method for getControlObject:
ConsoleMethod( GameConnection, setCameraObject, bool, 3, 3, "(ShapeBase object)")
{
ShapeBase *gb;
if(!Sim::findObject(argv[2], gb))
return false;
object->setCameraObject(gb);
return true;
}
ConsoleMethod( GameConnection, getCameraObject, S32, 2, 2, "")
{
argv;
SimObject* cp = object->getCameraObject();
return cp ? cp->getId(): 0;
}
ConsoleMethod( GameConnection, clearCameraObject, void, 2, 2, "")
{
object->setCameraObject(NULL);
}After playing around with it, I also found you need some adjustments to the setCameraObject and setControlObject methods - otherwise the client connection can screw things up if you bounce the same object from your connection's control to camera or vice versa. Here is my GameConnection::setControlObject:
void GameConnection::setControlObject(ShapeBase *obj)
{
if(mControlObject == obj)
return;
if(mControlObject && mControlObject != mCameraObject)
mControlObject->setControllingClient(0);
if(obj)
{
// Nothing else is permitted to control this object.
if (ShapeBase* coo = obj->getControllingObject())
coo->setControlObject(0);
if (GameConnection *con = obj->getControllingClient())
{
if (this != con)
{
// was it controlled via camera or control?
if (con->getControlObject() == obj)
con->setControlObject(0);
else
con->setCameraObject(0);
}
}
// We are now the controlling client of this object.
obj->setControllingClient(this);
}
// Okay, set our control object.
mControlObject = obj;
if (mCameraObject.isNull())
setScopeObject(mControlObject);
}and here is my GameConnection::setCameraObject:
void GameConnection::setCameraObject(ShapeBase *obj)
{
if(mCameraObject == obj)
return;
if(mCameraObject && mCameraObject != mControlObject)
mCameraObject->setControllingClient(0);
if (obj) {
// Nothing else is permitted to control this object.
if (ShapeBase* coo = obj->getControllingObject())
coo->setControlObject(0);
if (GameConnection *con = obj->getControllingClient())
{
if (this != con)
{
// was it controlled via camera or control?
if (con->getControlObject() == obj)
con->setControlObject(0);
else
con->setCameraObject(0);
}
}
// We are now the controlling client of this object.
obj->setControllingClient(this);
}
// Okay, set our camera object.
mCameraObject = obj;
if (mCameraObject.isNull()) {
setScopeObject(mControlObject);
} else {
setScopeObject(mCameraObject);
// if this is a client then set the fov and active image
if(isServerConnection())
{
F32 fov = mCameraObject->getDefaultCameraFov();
GameSetCameraFov(fov);
}
}
}Camera read/write packets
None of this will work unless the client copy of the camera object gets packets updated. Here we're going to modify GameConnection::readPacket and GameConnection::writePacket.
In GameConnection::readPacket, find this block of code:
if (bstream->readFlag())
{
S32 gIndex = bstream->readInt(10);
ShapeBase* obj = static_cast<ShapeBase*>(resolveGhost(gIndex));
setCameraObject(obj);
}
else
setCameraObject(0);and change it to
if (bstream->readFlag())
{
S32 gIndex = bstream->readInt(NetConnection::GhostIdBitSize);
ShapeBase* obj = static_cast<ShapeBase*>(resolveGhost(gIndex));
setCameraObject(obj);
obj->readPacketData(this, bstream);
}
else
setCameraObject(0);In GameConnection::writePacket, find this block of code:
if (!mCameraObject.isNull() && mCameraObject != mControlObject)
{
gIndex = getGhostIndex(mCameraObject);
if (bstream->writeFlag(gIndex != -1))
bstream->writeInt(gIndex, 10);
}
else
bstream->writeFlag( false );and change it to:
if (!mCameraObject.isNull() && mCameraObject != mControlObject)
{
gIndex = getGhostIndex(mCameraObject);
if (bstream->writeFlag(gIndex != -1)) {
bstream->writeInt(gIndex, NetConnection::GhostIdBitSize);
mCameraObject->writePacketData(this, bstream);
}
}
else
bstream->writeFlag( false );Recompile it all and the engine is ready to go.
Script
To use the camera you need to follow some of Corys resource, but with some modifications. Datablock and naming has changed
First, add a datablock for the tracking camera to /fps/server/scripts/camera.cs:
...
datablock AdvancedCameraData(AdvCameraData)
{
lookAtOffset = "0 0 2";
thirdPersonOffset = "0 -3 3";
godViewOffset = "0 -20 20";
maxTerrainDiff = 2;
orbitMinMaxZoom = "5 100";
orbitMinMaxDeclination = "10 80";
damping = 0.25;
};
...Next, add it to the connection just like is currently done with the base camera class. Add this inside GameConnection::onClientEnterGame (/fps/server/scripts/game.cs), right after %this.camera is set up:
...
// create advanced camera
%this.advCamera = new AdvancedCamera() {
dataBlock = AdvCameraData;
};
MissionCleanup.add(%this.advCamera);
%this.advCamera.scopeToClient(%this);
...We'll need to clean it up after the client leaves the game, so add this to GameConnection::onClientLeaveGame
...
if (isObject(%this.advCamera))
%this.advCamera.delete();
...We need to tell it what to do when added and assign the connection's camera object, so add this to the end of GameConnection::createPlayer:
... // We set the camera system to run in 3rd person mode around the %player %this.advCamera.setPlayerObject(%player); %this.advCamera.setThirdPersonMode(); %this.advCamera.setFollowTerrainMode(false); %this.advCamera.setVerticalFreedomMode(false); %this.setCameraObject(%this.advCamera); ...
And we'll want to unhook it when the player dies. Insert this at the beginning of GameConnection::onDeath:
... // clear connections camera %this.advCamera.clearPlayerObject(); %this.advCamera.clearTargetObject(); %this.clearCameraObject(); ...
The last thing to know, is if you're in first-person mode, GameConnection automatically uses the control object to render the engine rather than the camera object. So if you don't see this working when you first enter a mission, toggle out of first-person.
Orbit mode
To use the orbit camera, one needs to add some key binds to manipulating the camera.
All you need to do, is add the following to your client\config.cs or better to your client\scripts\default.bind.cs
//------------------------------------------------------------------------------
// Advanced Camera Movement
//------------------------------------------------------------------------------
$cameraYawSpeed = -100.0;
$cameraPitchSpeed = -50.0;
$cameraZoomSpeed = -5.0;
function rotateCameraHorizontal(%val)
{
$advCamera::Yaw = getMouseAdjustAmount(%val)*$cameraYawSpeed ;
}
function rotateCameraVertical(%val)
{
$advCamera::Pitch = getMouseAdjustAmount(%val)*$cameraPitchSpeed;
}
function zoomCamera(%val)
{
$advCamera::Zoom = getMouseAdjustAmount(%val)*$cameraZoomSpeed;
}
moveMap.bind( mouse, xaxis, rotateCameraHorizontal);
moveMap.bind( mouse, yaxis, rotateCameraVertical );
moveMap.bind( mouse, zaxis, zoomCamera );Remember to comment out the mouse commands for the player movement, as these are overwritten by the orbit camera controls
//moveMap.bind( mouse, xaxis, yaw ); //moveMap.bind( mouse, yaxis, pitch );
Script API
To use the different camera modes you can use the following API
Selecting the camera mode is done with e.g.:
%this.advCamera.setTrackMode(); %this.advCamera.setThirdPersonMode(); %this.advCamera.setThirdPersonTargetMode(); %this.advCamera.setGodViewMode(); %this.advCamera.setOrbitMode(); %this.advCamera.setStaticMode();
Prior to calling the above modes you have to set the PlayerObject using
setPlayerObject();
To use the 3rd person target mode you also need to set a TargetObject using
setTargetObject();
To use the static or tracking camera you need to set the position the camera should be placed suing
setCameraPosition(Point3F pos);
To use the follow terrain mode in 3rd person you give a bool to
setFollowTerrainMode(true/false);
To use the vertical freedom mode in 3rd person you give a bool to
setVerticalFreedomMode(true/false);This only works if the player object is a Player, because it uses the head movement.
The offset values in the datablock can be changed for the camera object via script using
get/setLookAtOffset(); get/setThirdPersonOffset(); get/setGodViewOffset();The setters take a Point3F as argument.
The orbit camera can be manipulated from script using
get/setOrbitMinMaxZoom() get/setOrbitMinMaxDeclination()The min/max take a Point2F
You can also manipulate the orbit camera directly by assigning values to the following variables
[code]
$advCamera::Yaw
$advCamera::Pitch
$advCamera::Zoom
$advCamera::azimuth
$advCamera::declination
$advCamera::zoomDistance
[code]
All camera modes coexist, so you can set the position, player object and target object once and then switch camera modes around as you see fit. Switching mode will not clear the old objects/positions.
#322
Orbit camera centers on the player, and the mouse movements control the orbit around the player. It doesnt "auto rotate" if thats what you expect
God mode is your "diablo type" camera - it centers on the player. It is not an independent camera mode in terms of free roaming
12/21/2006 (6:39 am)
They work as you describe!Orbit camera centers on the player, and the mouse movements control the orbit around the player. It doesnt "auto rotate" if thats what you expect
God mode is your "diablo type" camera - it centers on the player. It is not an independent camera mode in terms of free roaming
#323
12/21/2006 (6:56 pm)
Great resource!
#324
orbitMinMaxDeclination = "10 80";
to
orbitMinMaxDeclination = "10 120";
i notice weird behavior when i pass the pure-horizontal 90 degrees. the camera gets closer to the player as i orbit toward and beyond 90 degrees..... also, when around 110,120 degrees, i get really weird zoom behavior: increasing the zoom zooms out for a while, then starts zooming in again (??)
has anyone dealt with this? seems like some bugs in the code with trig functions having arguments out of bounds.....
12/27/2006 (4:49 pm)
in orbit mode, i am having a slight problem with this otherwise fantastic mod. when i change the orbitMinMaxDeclination = "10 80";
to
orbitMinMaxDeclination = "10 120";
i notice weird behavior when i pass the pure-horizontal 90 degrees. the camera gets closer to the player as i orbit toward and beyond 90 degrees..... also, when around 110,120 degrees, i get really weird zoom behavior: increasing the zoom zooms out for a while, then starts zooming in again (??)
has anyone dealt with this? seems like some bugs in the code with trig functions having arguments out of bounds.....
#325
// if (mMode && mMode != TrackMode && playerObj != NULL) {
// cameraPosWorld = runCameraCollisionCheck(playerObj->getRenderPosition(), cameraPosWorld);
// }
it is pretty straightforward to put a boolean flag in there to control this via script....
i think the behavior where the camera collides with the terrain is good... when you zoom in and it collides, it moves the camera.... but it doesn't appear to update the internal spherical coordinates and distance.... so when you zoom out, it will rotate back out again.... this leads to some odd behavior at times.
12/28/2006 (11:43 am)
i figured out why my orbit mode was acting up -- the camera was colliding with the terrain. i commented out these lines in advancedCamera.cc to fix it up....// if (mMode && mMode != TrackMode && playerObj != NULL) {
// cameraPosWorld = runCameraCollisionCheck(playerObj->getRenderPosition(), cameraPosWorld);
// }
it is pretty straightforward to put a boolean flag in there to control this via script....
i think the behavior where the camera collides with the terrain is good... when you zoom in and it collides, it moves the camera.... but it doesn't appear to update the internal spherical coordinates and distance.... so when you zoom out, it will rotate back out again.... this leads to some odd behavior at times.
#326
worked great in 1.4....
Thanks for any Help
Dan
01/10/2007 (4:59 pm)
anyone gotten this to work with stock 1.5? recompiled, added the script changes and when i switch views i dont see anything (possibly because of the fog) but even when i reduce the distance between the camera and the player i still cant see anything. it also causes has some nice / random lockups that require a reboot. worked great in 1.4....
Thanks for any Help
Dan
#327
01/10/2007 (5:00 pm)
I'm currently using the Advanced Camera in 1.5. Admitedly, I'm using just the orbit mode, but so far so good.
#328
01/10/2007 (6:08 pm)
No major problems here with 1.5. I would think there is another issue working in combination causing your problems. Not sure I understand what you mean when you say you don't see anything. No change in the camera? Or seeing nothing at all on the screen?
#330
function toggleMouseLook(%val){
echo("mouse show");
if(%val)
{
if(Canvas.isCursorOn())
CursorOff();
else
CursorOn();
}
}
i need to show cursor but orbit effect does'nt work when cursor showed.
how to solve this problem.
01/19/2007 (8:26 pm)
why i use script like below:function toggleMouseLook(%val){
echo("mouse show");
if(%val)
{
if(Canvas.isCursorOn())
CursorOff();
else
CursorOn();
}
}
i need to show cursor but orbit effect does'nt work when cursor showed.
how to solve this problem.
#331
I am not find the bug, if anyone have the same problem, tell me please, and we can search together!
Thanks!
01/24/2007 (9:34 am)
I got a problem in 1.5 too, it's the same problem that Daniel have, sometimes happened, sometimes not happened. I am not find the bug, if anyone have the same problem, tell me please, and we can search together!
Thanks!
#332
01/24/2007 (9:39 am)
Are you using the advancedCamera.zip file from the link at the very top of the page? Because I have used it and installing is simply a matter of adding the two files in the zip to the project and recompiling. I've done it many times for both TGE1.4 and TGE1.5
#333
or no...
01/24/2007 (10:02 am)
yeah, I using it, I used it for 1.4 too and not have the problem, I think that can be something in datablock....or no...
#334
in advancedCamera.cc at the beginning of AdvancedCamera::setPosition change this:
to this:
I guess that little part either got left out or the code was changed since then.
01/28/2007 (11:42 pm)
I used Gustavo Carvalho's interpolation code, but I was getting the camera jumping back and forth between two places, so here's the fix:in advancedCamera.cc at the beginning of AdvancedCamera::setPosition change this:
Point3F tPos = getPosition();
to this:
Point3F tPos;
I guess that little part either got left out or the code was changed since then.
#335
Is it just me or does the camera position never change? It seems no matter where I move the player or rotate the camera, the gettransform() and getposition() never change from where the camera spawned when the mission was loaded.
01/28/2007 (11:54 pm)
One more thing:Is it just me or does the camera position never change? It seems no matter where I move the player or rotate the camera, the gettransform() and getposition() never change from where the camera spawned when the mission was loaded.
#336
Thats a known bug, and its the cause of objects suddenly going out of scope when you move to far away from the point of the camera spawn.
Never got around to fix it.
01/29/2007 (12:00 am)
@EntropyThats a known bug, and its the cause of objects suddenly going out of scope when you move to far away from the point of the camera spawn.
Never got around to fix it.
#337
01/29/2007 (5:24 am)
Entr0py & Thomas, see my posts from Sep 18, 2005 and Sep 23, 2005 above for why this occurs with this resource out of the box.
#338
I would say advanced camera needs to be derived from the camera class instead of shapebase, and camera pitch, camera yaw and camera zoom need to be added to the move struct and interpreted in camera::processtick to get the cam to be server controlled instead of entirely clientside (it wouldnt hurt for the stock tge camera to use these values as well).
Leaving it clientside poses huge security risks for a networked game, not to mention that most games will probably need to take camera control away from the player at some point for things such as cutscenes and death sequences.
Other than that this is a top notch resource, and I have been using it for some time, but I am just now getting around to working on my in-game movement controls.
I am going to take a look at implementing the above changes, but I may just end up modifying stock tge cameras to allow for simultaneous player/camera movement and different modes.
*edit* I am using TGEA so that may have something to do with my results.
01/30/2007 (5:10 pm)
Yeah it appears there is no information being sent between server and client other than the basic shapebase information (and offset limits). AdvancedCamera::read/writePacketData is not being touched at all, and also it is not making use of the move struct ( in fact the move struct is always NULL when it gets to AdvancedCamera::processtick).I would say advanced camera needs to be derived from the camera class instead of shapebase, and camera pitch, camera yaw and camera zoom need to be added to the move struct and interpreted in camera::processtick to get the cam to be server controlled instead of entirely clientside (it wouldnt hurt for the stock tge camera to use these values as well).
Leaving it clientside poses huge security risks for a networked game, not to mention that most games will probably need to take camera control away from the player at some point for things such as cutscenes and death sequences.
Other than that this is a top notch resource, and I have been using it for some time, but I am just now getting around to working on my in-game movement controls.
I am going to take a look at implementing the above changes, but I may just end up modifying stock tge cameras to allow for simultaneous player/camera movement and different modes.
*edit* I am using TGEA so that may have something to do with my results.
#339
Wouldn't a simple setMaskBits(MoveMask) in an appropriate place solve most of the issues. Woudn't this cause a packupdate/unpack to be sent either from the client to the server or vice versa? This way positional data could be sync (or synced at a reasonable rate) to ensure this doesn't happen. I could be way off here and poking around at things that don't make enough sense to me yet.
I am not exactly sure how to replicate the bug either.. Is the position/rotational data not being updated on the client or the server.
02/05/2007 (7:53 am)
I am trying to piece together a TDN wiki engine code section on controllable objects. Been looking at the advanced camera resource and base camera code trying figure out some basics. I did a walkthrough of the advance camera code to figure some things out and would like to clarify the raised 'bug' on the camera position not changing?Wouldn't a simple setMaskBits(MoveMask) in an appropriate place solve most of the issues. Woudn't this cause a packupdate/unpack to be sent either from the client to the server or vice versa? This way positional data could be sync (or synced at a reasonable rate) to ensure this doesn't happen. I could be way off here and poking around at things that don't make enough sense to me yet.
I am not exactly sure how to replicate the bug either.. Is the position/rotational data not being updated on the client or the server.
#340
The problem was that advancedcamera had no access to the move struct, and therefore its movement was completely client-side. I added Pitch Yaw and Zoom to the move struct, and had to add a line in gameprocess.cpp to give the serverside camera object access to the move struct. Once this was done, a lot of the information the server was sending to the client was no longer necessary and therefore removed from pack/unpack. There were a few more changes, mostly moving things around that the client no longer needed.
02/05/2007 (12:01 pm)
It's not so much a bug as the code being unfinished. I have the camera position and rotation updating but I am having problems interpolating between ticks so the camera shakes. Once I get it worked out I will post my code here.The problem was that advancedcamera had no access to the move struct, and therefore its movement was completely client-side. I added Pitch Yaw and Zoom to the move struct, and had to add a line in gameprocess.cpp to give the serverside camera object access to the move struct. Once this was done, a lot of the information the server was sending to the client was no longer necessary and therefore removed from pack/unpack. There were a few more changes, mostly moving things around that the client no longer needed.

Torque Owner Amr Bekhit
--Amr