Advanced Camera
by Thomas \"Man of Ice\" Lund · 04/03/2008 (11:57 am) · 479 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.
#462
01/23/2009 (6:26 am)
I also have problems with not seeing my projectiles half the time, but the other half I can... I am using "WoW Style Player Controls" which includes this Advanced Camera resource. Not very "advanced" if it has such a MAJOR flaw...
#463
I got this working great in TGEA 1.7.1. Although, when going into multiplayer it seems that only the host can use the advanced camera and not any of the clients. After reading some of the posts in this resource, I realize that this is because the camera code is written on the server side. Does anyone have any suggestions on how to get the advanced camera working on both the client and server?
02/13/2009 (6:32 pm)
Hi everyone,I got this working great in TGEA 1.7.1. Although, when going into multiplayer it seems that only the host can use the advanced camera and not any of the clients. After reading some of the posts in this resource, I realize that this is because the camera code is written on the server side. Does anyone have any suggestions on how to get the advanced camera working on both the client and server?
#464
02/17/2009 (8:10 am)
Anyone?
#465
im using 152 engine and have implemented everything up until the script API using the starter FPS as a base.
the script API confuses me though, can someone please give an example of how and where this should be implemented and how i would set the camera to orbit mode in the starter fps ?
thanks.
03/02/2009 (5:20 am)
hey, hope someone can help me with this as ive been scratching my head for ages.....im using 152 engine and have implemented everything up until the script API using the starter FPS as a base.
the script API confuses me though, can someone please give an example of how and where this should be implemented and how i would set the camera to orbit mode in the starter fps ?
thanks.
#466
03/10/2009 (5:07 pm)
So, this will work with TGEA? i hope it will work with the future Torque's like T3D.
#467
Where is the resource about TGEA? Or just try "Advanced Camera"?
Thanks!
03/26/2009 (11:35 pm)
Hi All,I just want to move Player with "AWSD" like ARPG or MMORPG does.Where is the resource about TGEA? Or just try "Advanced Camera"?
Thanks!
#468
05/24/2009 (4:33 am)
If only the MAN OF ICE, in all his great wisdom, would join the Torque 3D community, and add new features and robustness and stability to this great resource... Then the land of torque would truly be free from the confines of restricted styles of camera movement!
#469
I have moved on to greener pastures in Unity land a year ago, and wont be updating this resource anymore.
/Thomas
05/24/2009 (1:56 pm)
I am sorry Peter - I'm pretty sure you are on your own there.I have moved on to greener pastures in Unity land a year ago, and wont be updating this resource anymore.
/Thomas
#470
05/28/2009 (4:00 am)
What script changes do i make to get this working in a game with AFX? I am using 1.7.1 with AFX coretech
#471
Oh no, "greener pastures"? Ahhhhh, but Torque 3D adds new features :-p
[Edit: I think I mean 3rd person mode, rather than orbit mode]
06/06/2009 (10:55 pm)
Btw, Advanced Camera resource ported well into Torque 3D, although I haven't figured out how to do the (Myth:TFL) (Myth: The Fallen Lords) style camera yet. Although maybe I just need to use the orbit camera with an invisible flying player.Oh no, "greener pastures"? Ahhhhh, but Torque 3D adds new features :-p
[Edit: I think I mean 3rd person mode, rather than orbit mode]
#472
06/14/2009 (7:55 am)
I am trying to get the advanced camera resource working in T3D, but I keep hitting snags, Could anyone possibly point me in the right direction?
#473
When I map a command to adjust the pitch and yaw of the camera (using OrbitMode currently) to the mouse, it works just fine. However, when I try to use an analog stick (using an Xbox 360 controller with Xinput), it "impulses" in the appropriate direction by an amount based on what the stick is set to - however, there is not constant movement here. I looked into advancedCamera.cc and looked at what happens in AdvancedCamera::updateMovementValues, and I found this:
So the yaw, pitch, and zoom are resetting, which would cause this effect to happen. However, with an analog stick as such, I want the positional shift of the camera to be constant. I fixed this by taking advantage of the fact that when you center an axis, it still updates again (in which case, I have it set based on the value of the analog press - releasing sets it to zero) - my solution was to simply comment out the aforementioned lines in the source.
The only problem, is that this utterly breaks mouse-based camera movement, which I still want as an option.
Does anyone have any suggestions as to how one would go about patching in analog joystick support while keeping mouse functionality? Or did I miss some completely obvious, already-existing solution?
[EDIT] - Forgot to mention: TGE 1.5.2 is what I'm using.
06/15/2009 (12:51 am)
I just implemented this into a project I'm working on - and it works great. There is one issue, though.When I map a command to adjust the pitch and yaw of the camera (using OrbitMode currently) to the mouse, it works just fine. However, when I try to use an analog stick (using an Xbox 360 controller with Xinput), it "impulses" in the appropriate direction by an amount based on what the stick is set to - however, there is not constant movement here. I looked into advancedCamera.cc and looked at what happens in AdvancedCamera::updateMovementValues, and I found this:
//Reset the increment console variables Con::setFloatVariable( "$advCamera::Yaw", 0.0 ); Con::setFloatVariable( "$advCamera::Pitch", 0.0 ); Con::setFloatVariable( "$advCamera::Zoom", 0.0 );
So the yaw, pitch, and zoom are resetting, which would cause this effect to happen. However, with an analog stick as such, I want the positional shift of the camera to be constant. I fixed this by taking advantage of the fact that when you center an axis, it still updates again (in which case, I have it set based on the value of the analog press - releasing sets it to zero) - my solution was to simply comment out the aforementioned lines in the source.
The only problem, is that this utterly breaks mouse-based camera movement, which I still want as an option.
Does anyone have any suggestions as to how one would go about patching in analog joystick support while keeping mouse functionality? Or did I miss some completely obvious, already-existing solution?
[EDIT] - Forgot to mention: TGE 1.5.2 is what I'm using.
#474
fatal error C1083: Cannot open include file: 'atlbase.h': No such file or directory c:\torque\torque 3d 2009 beta 2\genre kits\fps genre kit\web\source\activex\stdafx.h 19
I have no idea why this error is occuring, I carn't see where I alter anything relating to this file. Does anyone have any ideas?
Thanks
06/15/2009 (11:02 am)
I decide to try and port the advanced camera resource to T3D and I am almost there, turned out to be failly straight-forward, just a few name changes. However, I have hit one snag that I carnt seem to figure out. When I rebuild the engine I get one fatal error:fatal error C1083: Cannot open include file: 'atlbase.h': No such file or directory c:\torque\torque 3d 2009 beta 2\genre kits\fps genre kit\web\source\activex\stdafx.h 19
I have no idea why this error is occuring, I carn't see where I alter anything relating to this file. Does anyone have any ideas?
Thanks
#475
Basically, I made it so that the mouse pitch/yaw adjustment functions call a schedule to reset the pitch/yaw adjustment being made, but also so that each time the function is called, it resets the previous schedule.
So, with these lines commented out from advancedCamera.cc, in AdvancedCamera::updateMovementValues:
And then, in wherever you put your bound functions:
And, of course, similar ones for the pitch. They actually work pretty well, it just feels hackish to me, but the end result isn't all that bad.
Of course, it also works for having normal first-person controls, allowing for a very dynamic and variable gameplay experience, being able to switch between a third-person action/adventure sort of view, and being able to use a first-person view with FPS-style controls.
06/15/2009 (9:42 pm)
I did manage to get the mouse-controlled orbit camera working with the aforementioned change in source, though the way I did it feels awfully hackish.Basically, I made it so that the mouse pitch/yaw adjustment functions call a schedule to reset the pitch/yaw adjustment being made, but also so that each time the function is called, it resets the previous schedule.
So, with these lines commented out from advancedCamera.cc, in AdvancedCamera::updateMovementValues:
//Reset the increment console variables Con::setFloatVariable( "$advCamera::Yaw", 0.0 ); Con::setFloatVariable( "$advCamera::Pitch", 0.0 ); Con::setFloatVariable( "$advCamera::Zoom", 0.0 );
And then, in wherever you put your bound functions:
function rotateCameraHorizontalMouse(%val)
{
cancel($cameraYawSchedule);
$cameraYawSchedule = schedule(200, 0, resetYaw);
$advCamera::Yaw = getMouseAdjustAmount(%val)*$cameraYawSpeed ;
}
function resetYaw()
{
$advCamera::Yaw = 0;
}
function mouseYaw(%val) // Bind this one to mouse xaxis
{
if($firstperson)
{
yaw(%val);
}
else
rotateCameraHorizontalMouse(%val);
}And, of course, similar ones for the pitch. They actually work pretty well, it just feels hackish to me, but the end result isn't all that bad.
Of course, it also works for having normal first-person controls, allowing for a very dynamic and variable gameplay experience, being able to switch between a third-person action/adventure sort of view, and being able to use a first-person view with FPS-style controls.
#476
Im using a standard AFX combo 1.8.1 build, with a bit of code that makes the player face the mouse cursor.
I have my camera set up in godview mode and it works perfectly.
I start up a multiplayer server and it all loads, and works perfect for the host.
When any more clients connect to the server, they start in the eye node of the character and any attempt to change views crashes their instance of the game.
I have honestly no idea where to start looking for the problem, and it might be something really simple ive overlooked. I will take any suggestions, please.
Thank you all for reading.
08/06/2009 (2:30 am)
I have an odd bug here that isnt listed anywhere in the 25 pages of replies, it took over an hour to read them all, so here it is.Im using a standard AFX combo 1.8.1 build, with a bit of code that makes the player face the mouse cursor.
I have my camera set up in godview mode and it works perfectly.
I start up a multiplayer server and it all loads, and works perfect for the host.
When any more clients connect to the server, they start in the eye node of the character and any attempt to change views crashes their instance of the game.
I have honestly no idea where to start looking for the problem, and it might be something really simple ive overlooked. I will take any suggestions, please.
Thank you all for reading.
#477
How do you fix the compile errors reported by Dizzo and Jacobo so long ago? (2007)
1>..\..\..\..\..\engine\source\T3D\gameConnection.cpp(1594) : error C2556: 'S32 cGameConnectionsetCameraObject(GameConnection *,S32,const char **)' : overloaded function differs only by return type from 'bool cGameConnectionsetCameraObject(GameConnection *,S32,const char **)'
1> ..\..\..\..\..\engine\source\T3D\gameConnection.cpp(1400) : see declaration of 'cGameConnectionsetCameraObject'
1>..\..\..\..\..\engine\source\T3D\gameConnection.cpp(1594) : error C2371: 'cGameConnectionsetCameraObject' : redefinition; different basic types
1> ..\..\..\..\..\engine\source\T3D\gameConnection.cpp(1400) : see declaration of 'cGameConnectionsetCameraObject'
1>.
The errors go on, but you get the idea.
09/05/2009 (4:23 pm)
Maybe my sight is going in my old age but I've looked through the resource and couldn't find an answer to this question. Many say they have implemented this resource fine so I thought I would ask. How do you fix the compile errors reported by Dizzo and Jacobo so long ago? (2007)
1>..\..\..\..\..\engine\source\T3D\gameConnection.cpp(1594) : error C2556: 'S32 cGameConnectionsetCameraObject(GameConnection *,S32,const char **)' : overloaded function differs only by return type from 'bool cGameConnectionsetCameraObject(GameConnection *,S32,const char **)'
1> ..\..\..\..\..\engine\source\T3D\gameConnection.cpp(1400) : see declaration of 'cGameConnectionsetCameraObject'
1>..\..\..\..\..\engine\source\T3D\gameConnection.cpp(1594) : error C2371: 'cGameConnectionsetCameraObject' : redefinition; different basic types
1> ..\..\..\..\..\engine\source\T3D\gameConnection.cpp(1400) : see declaration of 'cGameConnectionsetCameraObject'
1>.
The errors go on, but you get the idea.
#478
The only change that I noticed to the code is to the GameConnection::setControlObject(ShapeBase *obj) method. TGE 1.4 added some camera features if I recall with very similar code behind it.
Knowing that is this resource obsolete at this point i.e. does stock T3D have a better camera system.
09/14/2011 (6:59 am)
I know its been some time since a posting was made on this resource; I used it long ago and have dusted off the old TGE. To answer the question above by D.Isaac the reason is that setCameraObject, getCameraObject and clearCameraObject are already defined in the engine (same file just a bit lower).The only change that I noticed to the code is to the GameConnection::setControlObject(ShapeBase *obj) method. TGE 1.4 added some camera features if I recall with very similar code behind it.
Knowing that is this resource obsolete at this point i.e. does stock T3D have a better camera system.
#479
02/13/2012 (9:14 am)
There are some features here that are not in stock T3D. If you need "WoW - style" controls, you might want to get this resource into your project.
Torque Owner Jason Fox