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.
#182
www.garagegames.com/mg/forums/result.thread.php?qt=34775
Also, I began an Option B approach above and ran into some issues with assumptions GameBase makes about what the client and server objects are. So, I took a variation of the Option A route and it seems to be working well so far, even if it is a workaround.
09/22/2005 (7:06 pm)
You may find this topic useful as it relates to a bug with 3rd person cameras in a networked environment.www.garagegames.com/mg/forums/result.thread.php?qt=34775
Also, I began an Option B approach above and ran into some issues with assumptions GameBase makes about what the client and server objects are. So, I took a variation of the Option A route and it seems to be working well so far, even if it is a workaround.
#183
From the log:
CTC.demo/server/scripts/game.cs (233): Unable to instantiate non-conobject class AdvancedCamera.
Set::add: Object "0" doesn't exist
CTC.demo/server/scripts/game.cs (235): Unable to find object: '0' attempting to call function 'scopeToClient'
CTC.demo/server/scripts/game.cs (352): Unable to find object: '0' attempting to call function 'setPlayerObject'
CTC.demo/server/scripts/game.cs (353): Unable to find object: '0' attempting to call function 'setThirdPersonMode'
CTC.demo/server/scripts/game.cs (354): Unable to find object: '0' attempting to call function 'setFollowTerrainMode'
CTC.demo/server/scripts/game.cs (355): Unable to find object: '0' attempting to call function 'setVerticalFreedomMode'
Which led me to believe that I missed something on the source side. But, all the code changes seem to be right, the files are in the project tree, I've recompiled at least four or five and times and still the same result. I'm using TBE to compile it, I'm starting to wonder if it could TBE causing the problems. I know the solution to this is staring me right in the face, but its been almost 2 years since I've messed with Torque and things are coming back to me a bit slowly. Any help would be appreciated.
EDIT:
Nevermind, its all fixed now. I needed to add advanceCamera.cc to the makefile. Not used to compiling with makefiles.
10/03/2005 (11:18 am)
First of all this looks like a great resource. Its a great idea to have everything in one resource for convenient one stop shopping. On to the problem at hand. I'm having trouble getting the Advanced Camera up and running.From the log:
CTC.demo/server/scripts/game.cs (233): Unable to instantiate non-conobject class AdvancedCamera.
Set::add: Object "0" doesn't exist
CTC.demo/server/scripts/game.cs (235): Unable to find object: '0' attempting to call function 'scopeToClient'
CTC.demo/server/scripts/game.cs (352): Unable to find object: '0' attempting to call function 'setPlayerObject'
CTC.demo/server/scripts/game.cs (353): Unable to find object: '0' attempting to call function 'setThirdPersonMode'
CTC.demo/server/scripts/game.cs (354): Unable to find object: '0' attempting to call function 'setFollowTerrainMode'
CTC.demo/server/scripts/game.cs (355): Unable to find object: '0' attempting to call function 'setVerticalFreedomMode'
Which led me to believe that I missed something on the source side. But, all the code changes seem to be right, the files are in the project tree, I've recompiled at least four or five and times and still the same result. I'm using TBE to compile it, I'm starting to wonder if it could TBE causing the problems. I know the solution to this is staring me right in the face, but its been almost 2 years since I've messed with Torque and things are coming back to me a bit slowly. Any help would be appreciated.
EDIT:
Nevermind, its all fixed now. I needed to add advanceCamera.cc to the makefile. Not used to compiling with makefiles.
#184
Thanks
10/04/2005 (5:27 am)
Hey there I hope someone is listening. I need 1 piece of information. What is the GameBase *obj variable passed to setTargetObject() I can find no reference to GameBase *obj. I think it is the %obj variable but which one and where do I put it. I am lost on where to put the camera changes and how to set them up.Thanks
#185
I have the same Entr0py's problem, but...
... this solution don't work for me :(
Any help?
Thanks in advance.
10/08/2005 (5:26 pm)
Quote:I implemented this, and I when I run it, the loading bar fills up but I never get into the game. So I have to hit cancel to get out of it, but the game doesnt crash or anything. I have rechecked everything 3 times and I got everything in exactly as is directed. (I am running it in starter.fps mode). Please help, thanx.
I have the same Entr0py's problem, but...
Quote: Ok I got it to work. In game.cs function GameConnection::createPlayer, I had to comment out this line:
%this.advCamera.delete();
(How the hell did that get there?!)
Very nice resource thanks a lot :)
Edited on Jun 26, 2004 10:08
... this solution don't work for me :(
Any help?
Thanks in advance.
#186
10/09/2005 (7:28 am)
I'm going to have a go on making this work with TSE this week. Hopefully i'll get it to work.. Then i'll post it as a resource. (with the right credits to Thomas offcourse :) )
#187
This looks like a great resource but it's CRASHING AT MISSION LOAD on me. I'm in LightingPack SDK 1.3.5-beta, and Windows using VC6 for now.
Basically I followed the instructions above, exactly. I can load into the main menu but when I hit "load Mission" the progress bar finishes "loading objects" and then TGE crashes completely, before switching from the loading screen.
Unfortunetly it leaves no errors (at least none that didn't come stock with the SDK...) in the console log to point me to the problem.
Here's some log below FWIW..
I'll recheck that I copied everything exact in the morning but I was really careful. Also read comments above going back to Dec-2004, but didn't see this one listed. Any suggestions on where to look? Has anyone gotten this to work with the Lighting Pack Recently?
Yes I recompiled, and yes it was working FINE right before this resource.
Much Thanks,
Raven
------------------------------------------------------
FIXED
------------------------------------------------------
Turnes out I had done this in "writePacket" section:
Maybe this will help someone...
console.log
------------------------------------
*** Phase 1: Download Datablocks & Targets
Mapping string: MissionStartPhase1Ack to index: 0
Error: shape zelda/data/shapes/crossbow/ammo.dts-collision detail 0 (Collision-3) bounds box invalid!
Could not locate texture: zelda/data/shapes/player/base.lmale
Could not locate texture: zelda/data/shapes/player/base.lmale
Could not locate texture: zelda/data/shapes/player/crossbow
Could not locate texture: zelda/data/shapes/player/clip
Validation required for shape: zelda/data/shapes/player/player.dts
Could not locate texture: ~/data/environment/lightning.dml
Mapping string: MissionStartPhase2 to index: 9
*** Phase 2: Download Ghost Objects
Mapping string: MissionStartPhase2Ack to index: 1
Ghost Always objects received.
Mapping string: MissionStartPhase3 to index: 10
Client Replication Startup has Happened!
fxFoliageReplicator - Client Foliage Replication Startup is complete.
*** Phase 3: Mission Lighting
Successfully loaded mission lighting file: 'zelda/data/missions/zelda_005_7b68ee91.ml'
Mission lighting done
Mapping string: MissionStartPhase3Ack to index: 2
------------------------------------------------
It Crashes Here - this is the end!
------------------------------------------------
EDIT:
The last line isn't actually recorded in the console.log, and gets cut-off on-screen in the real-time console by the windows "your program crashed" dialog, but Torsion-debugger captured it.
*As a side note TORSION is great - if you don't have it get it. I thought i didn't need it cuz I have several notepad replacements, but once i tried it I couldn't go back. it's nice for T-scripts! :-)
10/18/2005 (1:23 am)
Hey all,This looks like a great resource but it's CRASHING AT MISSION LOAD on me. I'm in LightingPack SDK 1.3.5-beta, and Windows using VC6 for now.
Basically I followed the instructions above, exactly. I can load into the main menu but when I hit "load Mission" the progress bar finishes "loading objects" and then TGE crashes completely, before switching from the loading screen.
Unfortunetly it leaves no errors (at least none that didn't come stock with the SDK...) in the console log to point me to the problem.
Here's some log below FWIW..
I'll recheck that I copied everything exact in the morning but I was really careful. Also read comments above going back to Dec-2004, but didn't see this one listed. Any suggestions on where to look? Has anyone gotten this to work with the Lighting Pack Recently?
Yes I recompiled, and yes it was working FINE right before this resource.
Much Thanks,
Raven
------------------------------------------------------
FIXED
------------------------------------------------------
Turnes out I had done this in "writePacket" section:
if (!mCameraObject.isNull() && mCameraObject != mControlObject)
{
gIndex = getGhostIndex(mCameraObject);
// Changed for Adv-Cam //
// if (bstream->writeFlag(gIndex != -1))
// bstream->writeInt(gIndex, NetConnection::GhostIdBitSize);
if (bstream->writeFlag(gIndex != -1))
{
bstream->writeInt(gIndex, NetConnection::GhostIdBitSize);
mCameraObject->writePacketData(this, bstream);
}
/////////////////////////
[b] if (bstream->writeFlag(gIndex != -1))
bstream->writeInt(gIndex, NetConnection::GhostIdBitSize); [/b]
}
else
bstream->writeFlag( false );Maybe this will help someone...
console.log
------------------------------------
*** Phase 1: Download Datablocks & Targets
Mapping string: MissionStartPhase1Ack to index: 0
Error: shape zelda/data/shapes/crossbow/ammo.dts-collision detail 0 (Collision-3) bounds box invalid!
Could not locate texture: zelda/data/shapes/player/base.lmale
Could not locate texture: zelda/data/shapes/player/base.lmale
Could not locate texture: zelda/data/shapes/player/crossbow
Could not locate texture: zelda/data/shapes/player/clip
Validation required for shape: zelda/data/shapes/player/player.dts
Could not locate texture: ~/data/environment/lightning.dml
Mapping string: MissionStartPhase2 to index: 9
*** Phase 2: Download Ghost Objects
Mapping string: MissionStartPhase2Ack to index: 1
Ghost Always objects received.
Mapping string: MissionStartPhase3 to index: 10
Client Replication Startup has Happened!
fxFoliageReplicator - Client Foliage Replication Startup is complete.
*** Phase 3: Mission Lighting
Successfully loaded mission lighting file: 'zelda/data/missions/zelda_005_7b68ee91.ml'
Mission lighting done
Mapping string: MissionStartPhase3Ack to index: 2
------------------------------------------------
It Crashes Here - this is the end!
------------------------------------------------
EDIT:
The last line isn't actually recorded in the console.log, and gets cut-off on-screen in the real-time console by the windows "your program crashed" dialog, but Torsion-debugger captured it.
*As a side note TORSION is great - if you don't have it get it. I thought i didn't need it cuz I have several notepad replacements, but once i tried it I couldn't go back. it's nice for T-scripts! :-)
#188
10/18/2005 (6:23 am)
you could try applying it to a clean 1.3. Maybe something is interfering with it.
#189
Hope you understand.
10/18/2005 (9:54 am)
I'll not (and that goes for all my resources) port them to any beta or alpha releases - e.g. 1.4 rc2. I'll wait until they are done before doing so.Hope you understand.
#190
In default.bind.cs I want to do somthing like this:
10/18/2005 (1:53 pm)
Does anyone know how I can test which of these camera modes or First-Person-view the player is in?In default.bind.cs I want to do somthing like this:
function joymovex(%val)
{
switch$ (%camMode)
case "FPS"
if ($pref::Input::Deadzone < %val | - $pref::Input::Deadzone > %val)
{
$mvRightAction = %val * $pref::Input::Sensitivity;
}
else
$mvRightAction = 0;
case "3rd-Person"
DO OTHER STUFF
case "Orbit"
DO NEW STUFF
}
#191
10/18/2005 (2:39 pm)
well you allready know in what he is, since another part of the script put him there. Just store it before you change it
#192
10/19/2005 (4:03 pm)
For the record it patches clean to 1.3.5-beta (that would be the lightingPack), as long as you don't make stupid mistakes as I reported above.
#193
I am working on a RTS style game where I have several avatars, each of them implemented as AIPlayers. By default the camera is set in toggleCameraFly mode. I tried to add the Advanced Camera to the application because I want to add third person mode for avatars. I want that each avatar can be "followed" by the camera.
My first problem was how to get the pointer of the GameConnection object because I am not using the GameConnection::createPlayer() Finally I decided to create a global variable which will get the value of %this in GameConnection::createPlayer() and use it for assigning the advanced camera object with an avatar.
I tried the above implementation but it isn't working. When I call the below lines:
$gGameConnection.advCamera.setPlayerObject(%avatar);
$gGameConnection.advCamera.setThirdPersonMode();
$gGameConnection.advCamera.setFollowTerrainMode(false);
$gGameConnection.advCamera.setVerticalFreedomMode(false);
$gGameConnection.setCameraObject($gGameConnection.advCamera);
it does nothing. The camera remains in the old position, which is the old camera object in toggleCameraFly mode. I checked with the debugger and the $gGameConnection, $gGameConnection.advCamera and %avatar are valid objects and also the AdvancedCamera::advanceTime() is called periodically.
Any idea what the problem can be? I am wondering if I should switch the camera from the old camera to the new Advanced Camera? Is there anybody who has experienced the same problem?
Any suggestion is welcome.
Thanks.
11/01/2005 (1:19 pm)
Hi,I am working on a RTS style game where I have several avatars, each of them implemented as AIPlayers. By default the camera is set in toggleCameraFly mode. I tried to add the Advanced Camera to the application because I want to add third person mode for avatars. I want that each avatar can be "followed" by the camera.
My first problem was how to get the pointer of the GameConnection object because I am not using the GameConnection::createPlayer() Finally I decided to create a global variable which will get the value of %this in GameConnection::createPlayer() and use it for assigning the advanced camera object with an avatar.
I tried the above implementation but it isn't working. When I call the below lines:
$gGameConnection.advCamera.setPlayerObject(%avatar);
$gGameConnection.advCamera.setThirdPersonMode();
$gGameConnection.advCamera.setFollowTerrainMode(false);
$gGameConnection.advCamera.setVerticalFreedomMode(false);
$gGameConnection.setCameraObject($gGameConnection.advCamera);
it does nothing. The camera remains in the old position, which is the old camera object in toggleCameraFly mode. I checked with the debugger and the $gGameConnection, $gGameConnection.advCamera and %avatar are valid objects and also the AdvancedCamera::advanceTime() is called periodically.
Any idea what the problem can be? I am wondering if I should switch the camera from the old camera to the new Advanced Camera? Is there anybody who has experienced the same problem?
Any suggestion is welcome.
Thanks.
#194
Thats my best bet on what you see.
11/01/2005 (1:22 pm)
You need to switch the camera away from the "camera fly" mode, and into thirdperson mode.Thats my best bet on what you see.
#195
In advancedCamera.h (new code in bold):
In advancedCamera.cc inside the AdvancedCamera::AdvancedCamera()
Inside the AdvancedCamera::writePacketData(GameConnection *connection, BitStream *bstream)
Inside the AdvancedCamera::readPacketData(GameConnection *connection, BitStream *bstream)
Now need to set some variable to true if need send data when is necessary
Hope this help for this resource over network problem and also Thomas can updated this if he want to because this resource are amazing!
11/03/2005 (6:35 pm)
In advance camera, there are large data transfering between client and server for every movement which make my game lagging even in the single player, so I reduce the data and it successfull. See code belowIn advancedCamera.h (new code in bold):
Point3F mCameraPos; ///< Position of camera in tracking mode [b]bool bCameraPos;[/b] Point3F mRot; ///< Current pitch/yaw angles StateDelta delta; ///< Used for interpolation on the client. @see StateDelta /// @} F32 mZoomDistance; ///< Current orbit offset in SPHERICAL Coords F32 mDeclination; F32 mAzimuth; F32 mDamping; SimObjectPtr<GameBase> mPlayerObject; ///< Points to the shapebase object we use ///< in tracking and 3rd person mode SimObjectPtr<GameBase> mTargetObject; ///< Points to the shapebase object we use ///< in 3rd person target mode int mMode; ///< The mode the camera is in bool mFollowTerrain; ///< Keep camera level with terrain in 3rd person bool mVerticalFreedom; ///< Allow head pitch to control view in 3rd person Point3F mCurrentGodViewOffset; [b]bool bCurrentGodViewOffset;[/b] Point3F mCurrentThirdPersonOffset; [b]bool bCurrentThirdPersonOffset;[/b] Point3F mCurrentLookAtOffset; [b]bool bCurrentLookAtOffset;[/b] Point3F mCurrentOrbitOffset; [b]bool bCurrentOrbitOffset;[/b] Point2F mCurrentOrbitMinMaxZoom; [b]bool bCurrentOrbitMinMaxZoom;[/b] Point2F mCurrentOrbitMinMaxDeclination; [b]bool bCurrentOrbitMinMaxDeclination;[/b]
In advancedCamera.cc inside the AdvancedCamera::AdvancedCamera()
mRot = Point3F(0,0,0); [b] bCameraPos = false; bCurrentGodViewOffset = false; bCurrentThirdPersonOffset = false; bCurrentLookAtOffset = false; bCurrentOrbitOffset = false; bCurrentOrbitMinMaxZoom = false; bCurrentOrbitMinMaxDeclination = false; [/b] mPlayerObject = NULL;
Inside the AdvancedCamera::writePacketData(GameConnection *connection, BitStream *bstream)
bstream->setCompressionPoint(pos); mathWrite(*bstream, pos); [b] bstream->writeFlag(bCameraPos); if (bCameraPos) mathWrite(*bstream, mCameraPos); bCameraPos = false; bstream->writeFlag(bCurrentLookAtOffset); if (bCurrentLookAtOffset) mathWrite(*bstream, mCurrentLookAtOffset); bCurrentLookAtOffset = false; bstream->writeFlag(bCurrentThirdPersonOffset); if (bCurrentThirdPersonOffset) mathWrite(*bstream, mCurrentThirdPersonOffset); bCurrentThirdPersonOffset = false; bstream->writeFlag(bCurrentGodViewOffset); if (bCurrentGodViewOffset) mathWrite(*bstream, mCurrentGodViewOffset); bCurrentGodViewOffset = false; bstream->writeFlag(bCurrentOrbitOffset); if (bCurrentOrbitOffset) mathWrite(*bstream, mCurrentOrbitOffset); bCurrentOrbitOffset = false; bstream->writeFlag(bCurrentOrbitMinMaxZoom); if (bCurrentOrbitMinMaxZoom) mathWrite(*bstream, mCurrentOrbitMinMaxZoom); bCurrentOrbitMinMaxZoom = false; bstream->writeFlag(bCurrentOrbitMinMaxDeclination); if (bCurrentOrbitMinMaxDeclination) mathWrite(*bstream, mCurrentOrbitMinMaxDeclination); bCurrentOrbitMinMaxDeclination = false; [/b] U32 writeMode = mMode; bstream->writeRangedU32(writeMode, CameraFirstMode, CameraLastMode); bstream->writeFlag(mFollowTerrain); bstream->writeFlag(mVerticalFreedom);
Inside the AdvancedCamera::readPacketData(GameConnection *connection, BitStream *bstream)
mathRead(*bstream, &pos); bstream->setCompressionPoint(pos); [b] bCameraPos = bstream->readFlag(); if (bCameraPos) mathRead(*bstream, &mCameraPos); bCameraPos = false; bCurrentLookAtOffset = bstream->readFlag(); if (bCurrentLookAtOffset) mathRead(*bstream, &mCurrentLookAtOffset); bCurrentLookAtOffset = false; bCurrentThirdPersonOffset = bstream->readFlag(); if (bCurrentThirdPersonOffset) mathRead(*bstream, &mCurrentThirdPersonOffset); bCurrentThirdPersonOffset = false; bCurrentGodViewOffset = bstream->readFlag(); if (bCurrentGodViewOffset) mathRead(*bstream, &mCurrentGodViewOffset); bCurrentGodViewOffset = false; bCurrentOrbitOffset = bstream->readFlag(); if (bCurrentOrbitOffset) mathRead(*bstream, &mCurrentOrbitOffset); bCurrentOrbitOffset = false; bCurrentOrbitMinMaxZoom = bstream->readFlag(); if (bCurrentOrbitMinMaxZoom) mathRead(*bstream, &mCurrentOrbitMinMaxZoom); bCurrentOrbitMinMaxZoom = false; bCurrentOrbitMinMaxDeclination = bstream->readFlag(); if (bCurrentOrbitMinMaxDeclination) mathRead(*bstream, &mCurrentOrbitMinMaxDeclination); bCurrentOrbitMinMaxDeclination = false; [/b] mMode = bstream->readRangedU32(CameraFirstMode, CameraLastMode); mFollowTerrain = bstream->readFlag(); mVerticalFreedom = bstream->readFlag();
Now need to set some variable to true if need send data when is necessary
void AdvancedCamera::setCameraPosition(const Point3F& pos) {
mCameraPos = pos;
[b]bCameraPos = true;[/b]
setPosition(mCameraPos);
}
void AdvancedCamera::setLookAtOffset(Point3F offset) {
mCurrentLookAtOffset = offset;
[b]bCurrentLookAtOffset = true;[/b]
}
void AdvancedCamera::setThirdPersonOffset(Point3F offset) {
mCurrentThirdPersonOffset = offset;
[b]bCurrentThirdPersonOffset = true;[/b]
}
void AdvancedCamera::setGodViewOffset(Point3F offset) {
mCurrentGodViewOffset = offset;
[b]bCurrentGodViewOffset = true;[/b]
}
void AdvancedCamera::setOrbitOffset(Point3F offset) {
mCurrentOrbitOffset = offset;
[b]bCurrentOrbitOffset = true;[/b]
}
void AdvancedCamera::setOrbitMinMaxZoom(Point2F zoom) {
mCurrentOrbitMinMaxZoom = zoom;
[b]bCurrentOrbitMinMaxZoom = true;[/b]
}
void AdvancedCamera::setOrbitMinMaxDeclination(Point2F declination) {
mCurrentOrbitMinMaxDeclination = declination;
[b]bCurrentOrbitMinMaxDeclination = true;[/b]
}Hope this help for this resource over network problem and also Thomas can updated this if he want to because this resource are amazing!
#196
I dont know why...
11/07/2005 (8:19 am)
I lose my camera's mouse control when tried your code, Shannon :(I dont know why...
#197
- mCameraPos (if this variable change then set this variable bCameraPos to be true)
- mCurrentLookAtOffset (if this variable change then set this variable bCurrentLookAtOffset to be true)
- mCurrentThirdPersonOffset (if this variable change then set this variable bCurrentThirdPersonOffset to be true)
- mCurrentGodViewOffset (if this variable change then set this variable bCurrentGodViewOffset to be true)
- mCurrentOrbitOffset (if this variable change then set this variable bCurrentOrbitOffset to be true)
- mCurrentOrbitMinMaxZoom (if this variable change then set this variable bCurrentOrbitMinMaxZoom to be true)
- mCurrentOrbitMinMaxDeclination (if this variable change then set this variable bCurrentOrbitMinMaxDeclination to be true)
I let you know that I'm not good at english. :)
11/07/2005 (6:03 pm)
Did you modify code in advanced camera? if so then please check if you update any of those variables:- mCameraPos (if this variable change then set this variable bCameraPos to be true)
- mCurrentLookAtOffset (if this variable change then set this variable bCurrentLookAtOffset to be true)
- mCurrentThirdPersonOffset (if this variable change then set this variable bCurrentThirdPersonOffset to be true)
- mCurrentGodViewOffset (if this variable change then set this variable bCurrentGodViewOffset to be true)
- mCurrentOrbitOffset (if this variable change then set this variable bCurrentOrbitOffset to be true)
- mCurrentOrbitMinMaxZoom (if this variable change then set this variable bCurrentOrbitMinMaxZoom to be true)
- mCurrentOrbitMinMaxDeclination (if this variable change then set this variable bCurrentOrbitMinMaxDeclination to be true)
I let you know that I'm not good at english. :)
#198
I'm having problems with the orbit-camera "flying" from the orgin to the spawn point. The same thing happens when the player "teleports", the camera flys from one spot to the next. I need to have a clean transition.
I tried adding the following to: void AdvancedCamera::advanceTime(F32 dt)
It didn't work. if i check for "< 5" at the bottom it's too close. Anything else and nothing happens. The idea was if the camera is too far away from player we're going to move it to the player...
Any ideas, or a better solution is welcome.
Thanks,
Raven
11/07/2005 (11:42 pm)
If this is in the above comments, I couldn't find it:I'm having problems with the orbit-camera "flying" from the orgin to the spawn point. The same thing happens when the player "teleports", the camera flys from one spot to the next. I need to have a clean transition.
I tried adding the following to: void AdvancedCamera::advanceTime(F32 dt)
It didn't work. if i check for "< 5" at the bottom it's too close. Anything else and nothing happens. The idea was if the camera is too far away from player we're going to move it to the player...
//Check distance between player/camera (SP)
camDistance = sqrt(
MathUtils::getSquare(fabs(myPlayerPos.x - cameraPosWorld.x)) +
MathUtils::getSquare(fabs(myPlayerPos.y - cameraPosWorld.y)) +
MathUtils::getSquare(fabs(myPlayerPos.z - cameraPosWorld.z)) );
if (camDistance > 5)
{
cameraPosWorld = myPlayerPos;
//cameraPosWorld *= myPlayerPos;
}Any ideas, or a better solution is welcome.
Thanks,
Raven
#199
I've changed the variables, but still dont work... Can you control the camera with mouse after this code?
PS: Your english is better than mine :P
11/08/2005 (5:09 am)
@Shannon,I've changed the variables, but still dont work... Can you control the camera with mouse after this code?
PS: Your english is better than mine :P
#200
11/09/2005 (9:17 am)
I'm using your camera in third-person mode. Please tell me how I can control the distance between your camera and the target. Thank you. 
Torque Owner Aaron Oneal
Those are never synced with their server-side copy that I can tell. This means that on the client you can face the camera one direction while on the server it is facing the other direction. What implications does this have? I believe downstream objects behind you on the server, though in front of you on the client, are likely to fall out of scope and not be updated, or potentially, rendered.
Originally I was thinking an entirely client side camera would be possible, but it makes sense that position and orientation information needs to be known by the server for scoping purposes. I'm now of the opinion that an achievable compromise would be a kind of reverse ghost. Essentially, the client side object would be in control of position / orientation and send its updates (perhaps on a lower priority) to the server instead of the other way around. Maybe I'm overcomplicating this, but to do that I see two options:
Option A) Use the existing model in a way it probably wasn't intended.
1) "Fake out" the existing model by not putting any position related updates for transfer from server to client in writePacketData.
2) Use commandToServer / sendRemoteCommand or some other client to server messaging commands to sync object state.
Option B) Reverse ghost model
1) I think it's possible for a client connection to ghost just as the server connection does. This means you could create the object client side and have its state ghosted to the server using all the nifty underlying connectivity that NetConnection/GameConnection already provides. This might be a simple as enabling ghosting in both directions on both the client and server connections in GameConnection::onConnectionEstablished():
2) You would then create the camera object client-side and presumably it would be ghosted to the server. The prediction code necessary on the server side would basically be no longer required since other clients probably don't care about up to the second information on the camera of another client, and the server only cares to get a fairly recent position/orientation for scoping. Meaning, drop a couple isClientObject() calls into the advanced camera code to determine if you're running on the server or client, and only update when you're on the client. Incidentally, in case some tries this, since isClientObject() simply returns isGhost(), and the server side would be the ghost, the server side would actually be isClientObject() and the client would be isServerObject(). Clear as mud? :-)