Call for Advanced Camera new features/changes/fixes
by Thomas \"Man of Ice\" Lund · in Torque Game Engine · 01/16/2005 (3:55 am) · 65 replies
I'm going to give the advanced camera resource another update soon, and from what I hear a lot of people are using it (nice)
Thus I would like to call out to you all and ask you to dig into your modifications and new features + consider if you would like to contribute those to the general public.
Anything goes, so feel free to send anything you have. I'll update the resource and give proper credit naturally.
From my own hand I'm considering working on:
* general code cleanup - removing unused code
* API cleanup and renaming - e.g. changing the setTargetObject to setLookAtObject and other API changes that make it more intuitive to use. This will most likely break your code unless I put in some deprecation warnings in the old methods and keep them there
* make it possible to use GameBase objects instead of ShapeBase objects as "Look At" and "Tracking" objects - for vehicles, projectiles and similar
* client side orbit camera instead of current server side
Hope to recieve a lot of great additions :-)
If you have general ideas, those are also welcome
My email is in my profile
Thus I would like to call out to you all and ask you to dig into your modifications and new features + consider if you would like to contribute those to the general public.
Anything goes, so feel free to send anything you have. I'll update the resource and give proper credit naturally.
From my own hand I'm considering working on:
* general code cleanup - removing unused code
* API cleanup and renaming - e.g. changing the setTargetObject to setLookAtObject and other API changes that make it more intuitive to use. This will most likely break your code unless I put in some deprecation warnings in the old methods and keep them there
* make it possible to use GameBase objects instead of ShapeBase objects as "Look At" and "Tracking" objects - for vehicles, projectiles and similar
* client side orbit camera instead of current server side
Hope to recieve a lot of great additions :-)
If you have general ideas, those are also welcome
My email is in my profile
#22
01/21/2005 (7:30 pm)
@David: I use triggers. I also added a static camera mode to the advanced camera; it smoothy transition in/out of static mode.
#23
Hmm, maybe I added advanceTime too but forgot to tag it as a change... let me see...
Ah yes, I really added advanceTime to my version. I'll check if there are any more changes using WinDiff and post them.
--EDIT--
There were some other changes here and there. I find it's better to post the modified files isntead of trying to explain all those in the forum:
www.station-zero.com/medion/code/advancedcameraupdate.zip
This one also contains a cheesy interpolation for 3rd person mode.
01/22/2005 (5:19 am)
Quote:I tried to implement your codemanoel but I have no AdvancedCamera::advanceTime method, maybe you did this on a previous version, I guess only thomas can tell.
Hmm, maybe I added advanceTime too but forgot to tag it as a change... let me see...
Ah yes, I really added advanceTime to my version. I'll check if there are any more changes using WinDiff and post them.
--EDIT--
There were some other changes here and there. I find it's better to post the modified files isntead of trying to explain all those in the forum:
www.station-zero.com/medion/code/advancedcameraupdate.zip
This one also contains a cheesy interpolation for 3rd person mode.
#24
I'm a bit behind my own schedule, but I hope to start implementing the larger, contributed parts next weekend.
-----
Updated
01/23/2005 (2:00 am)
@Sam - I'll update the resource today with those minor changes.I'm a bit behind my own schedule, but I hope to start implementing the larger, contributed parts next weekend.
-----
Updated
#25
But I found that my camera is very far under the player.
what happend? what should I do?
01/23/2005 (11:19 am)
I've done as the post "advcamera".But I found that my camera is very far under the player.
what happend? what should I do?
#26
@Wangxu - is the camera moving with the player?
There are offsets in the datablock.
Try adjusting them, maybe something like this: thirdPersonOffset = "0 -10 40";
If the camera isn't moving, you probably made a mistake in GameConnection::onClientEnterGame
01/23/2005 (12:24 pm)
@Thomas - Thank you. @Wangxu - is the camera moving with the player?
There are offsets in the datablock.
Try adjusting them, maybe something like this: thirdPersonOffset = "0 -10 40";
If the camera isn't moving, you probably made a mistake in GameConnection::onClientEnterGame
#27
At first,I don't know what happend.
When I turn to World Edit mod,I found that the camera is far under the ground.
I've tride to adjust the offset,it's no use.
Maybe there is some mistake in the GameConnection::onClientEnterGame.
01/23/2005 (1:40 pm)
Camera can't move no matter in which mod.But player can move well.At first,I don't know what happend.
When I turn to World Edit mod,I found that the camera is far under the ground.
I've tride to adjust the offset,it's no use.
Maybe there is some mistake in the GameConnection::onClientEnterGame.
#28
01/23/2005 (1:44 pm)
BTW,the advcamera should replace or attach the sys camera?
#29
Following the resource description should give you a running 3rd person camera.
01/23/2005 (1:53 pm)
The advanced camera goes into action when you press tab (go into 3rd person mode)Following the resource description should give you a running 3rd person camera.
#30
I think there's one more file moveManager.h, I managed to get rid of most compiling errors by adding identifiers and members to Move and MoveManager but there's still one error I don't know where I can correct, there's an undefined identifier called mCameraRelativeControl this is used in an if on GameConnectionMoves.cc but I don't know where I should declare it.
Thanks
01/24/2005 (9:13 pm)
@Manoel, I think there's one more file moveManager.h, I managed to get rid of most compiling errors by adding identifiers and members to Move and MoveManager but there's still one error I don't know where I can correct, there's an undefined identifier called mCameraRelativeControl this is used in an if on GameConnectionMoves.cc but I don't know where I should declare it.
Thanks
#31
it would be nice to have the 3rd person camera perform occlusion avoidance, so that the camera orbits to different positions to keep the character it is tracking in view when the view is blocked by other characters or objects
thanks
01/25/2005 (7:08 pm)
Hiit would be nice to have the 3rd person camera perform occlusion avoidance, so that the camera orbits to different positions to keep the character it is tracking in view when the view is blocked by other characters or objects
thanks
#32
I got the code to compile by adding the definitions you mentioned into moveManager.h and commenting out the mCameraRelativeControl. It seems like nothing is affected by the removal. I aslo added this to default.bind.cs and config.cs to get the zoom working:
function AddZoomCamera(%val)
{
if ( %val < 0 )
localClientConnection.advCamera.addZoom(0.5);
else if (%val > 0)
localClientConnection.advCamera.addZoom(-0.5);
}
moveMap.bind( mouse0, zaxis, AddZoomCamera );
@Manoel,
Thanks for the changes. The movement is very smooth. Please do tell us the purpose of mCameraRelativeControl.
Nathan.
01/26/2005 (11:27 am)
@Pablo,I got the code to compile by adding the definitions you mentioned into moveManager.h and commenting out the mCameraRelativeControl. It seems like nothing is affected by the removal. I aslo added this to default.bind.cs and config.cs to get the zoom working:
function AddZoomCamera(%val)
{
if ( %val < 0 )
localClientConnection.advCamera.addZoom(0.5);
else if (%val > 0)
localClientConnection.advCamera.addZoom(-0.5);
}
moveMap.bind( mouse0, zaxis, AddZoomCamera );
@Manoel,
Thanks for the changes. The movement is very smooth. Please do tell us the purpose of mCameraRelativeControl.
Nathan.
#33
(The changes are all in the last "else" block)
I set the DISTANCE_FROM_COLLISION to about 0.4m which seems to work fairly well.
Note that this improves the behaviour of the camera but doesn't prevent it from penetrating walls in all situations. But at least it's not causing problems all the time now.
01/30/2005 (11:59 pm)
I found that the third person camera tended to penetrate walls and ceilings, particularly when used indoors. I changed AdvancedCamera::runCameraCollisionCheck() to back off a certain distance from walls to reduce the chance of penetration.Point3F AdvancedCamera::runCameraCollisionCheck(const Point3F& startpos, const Point3F& endpos) {
U32 mask = InteriorObjectType | TerrainObjectType;
RayInfo collisionInfo;
// Pad the start position with the lookAtOffset, so the camera doesnt move strange when a little bump
// in the terrain is between camera and the player feet
// Cast ray and check for collision with terrain and interiors
if (!gClientContainer.castRay(startpos + mCurrentLookAtOffset, endpos, mask, &collisionInfo)) {
// No collision, so return endpos
return endpos;
} else {
// We collided, so return the point of collision
// subtract a slight offset so we don't show clipping
Point3F LookDir = startpos + mCurrentLookAtOffset - collisionInfo.point;
LookDir.normalize();
Point3F AntiClippingOffset = LookDir * DISTANCE_FROM_COLLISION;
return collisionInfo.point + AntiClippingOffset;
}
}(The changes are all in the last "else" block)
I set the DISTANCE_FROM_COLLISION to about 0.4m which seems to work fairly well.
#define DISTANCE_FROM_COLLISION 0.4 // move the camera this many meters towards the player from a nearby wall
Note that this improves the behaviour of the camera but doesn't prevent it from penetrating walls in all situations. But at least it's not causing problems all the time now.
#34
Find this in advancedCamera.h:
Add this straight after:
Next find this (again in advancedCamera.h):
Add this straight after:
Now move to advancedCamera.cc and find:
Add this somewhere around there:
Find:
And add:
Now find the whole chunk which says:
And change it to:
Now look for a second segment of code which is identical to the one above (except it's missing the comment) and make the same changes to it.
(continued...)
01/31/2005 (3:53 am)
I had people commenting that the third person camera mode was annoyingly restrictive - you can look around but you can't look up and down. There seemed to be no good reason not to permit this so I've implemented a new "vertical freedom" mode. This seems much more natural when you're playing. I've implemented it as a mode so it can be turned on or off as you like.Find this in advancedCamera.h:
int mMode; ///< The mode the camera is in bool mFollowTerrain; ///< Keep camera level with terrain in 3rd person
Add this straight after:
bool mVerticalFreedom; ///< Allow head pitch to control view in 3rd person
Next find this (again in advancedCamera.h):
/// Method to set terrain follow mode void setFollowTerrainMode(bool enable);
Add this straight after:
/// Method to set vertical control of third person mode void setVerticalFreedomMode(bool enable);
Now move to advancedCamera.cc and find:
#include "game/gameConnection.h"
Add this somewhere around there:
#include "game/player.h"
Find:
mPlayerObject = NULL;
mTargetObject = NULL;
mFollowTerrain = false;And add:
mVerticalFreedom = false;
Now find the whole chunk which says:
case ThirdPersonMode :
{
// Move camera to third person offset position
GameBase *castObj = mPlayerObject;
ShapeBase* playerObj = dynamic_cast<ShapeBase*>(castObj);
if( playerObj != NULL ) {
Point3F cameraPosWorld;
MatrixF objToWorld = playerObj->getRenderTransform();
objToWorld.mulP(mCurrentThirdPersonOffset, &cameraPosWorld);
if (mFollowTerrain == true) {
cameraPosWorld = adjustCameraToTerrain(playerObj->getRenderPosition(), cameraPosWorld);
}
cameraPosWorld = runCameraCollisionCheck(playerObj->getRenderPosition(), cameraPosWorld);
setPosition(cameraPosWorld);
}
break;
}And change it to:
case ThirdPersonMode :
{
// Move camera to third person offset position
GameBase *castObj = mPlayerObject;
Player* playerObj = dynamic_cast<Player*>(castObj);
if( playerObj != NULL ) {
Point3F cameraPosWorld;
MatrixF objToWorld;
if (mVerticalFreedom) {
Point3F DistanceBehindHead(0, mCurrentThirdPersonOffset.y, 0);
Point3F DistanceAboveGround(0, 0, mCurrentThirdPersonOffset.z);
objToWorld = playerObj->getRenderTransform();
Point3F HeadRotation = playerObj->getHeadRotation();
F32 HeadPitch = HeadRotation.x;
MatrixF HeadPitchMatrix( EulerF( HeadPitch, 0, 0 ) );
objToWorld.mul(HeadPitchMatrix);
objToWorld.mulP(DistanceBehindHead, &cameraPosWorld);
cameraPosWorld += DistanceAboveGround;
}
else {
objToWorld = playerObj->getRenderTransform();
objToWorld.mulP(mCurrentThirdPersonOffset, &cameraPosWorld);
}
if (mFollowTerrain == true) {
cameraPosWorld = adjustCameraToTerrain(playerObj->getRenderPosition(), cameraPosWorld);
}
cameraPosWorld = runCameraCollisionCheck(playerObj->getRenderPosition(), cameraPosWorld);
setPosition(cameraPosWorld);
}
break;
}Now look for a second segment of code which is identical to the one above (except it's missing the comment) and make the same changes to it.
(continued...)
#35
Add this straight afterwards (order is important here):
In AdvancedCamera::readPacketData() find:
Add this straight afterwards (order is important here too):
Now find the AdvancedCamera::setFollowTerrainMode():
And after it add:
Search for:
And after it add:
Finally you can tell the system to turn the mode on if you want to use it. Go to starter.fps/server/scripts and at the bottom of GameConnection::createPlayer() you'll see something like:
To turn it on, I change it to:
01/31/2005 (3:54 am)
Jump down to AdvancedCamera::writePacketData() and find:bstream->writeFlag(mFollowTerrain);
Add this straight afterwards (order is important here):
bstream->writeFlag(mVerticalFreedom);
In AdvancedCamera::readPacketData() find:
mFollowTerrain = bstream->readFlag();
Add this straight afterwards (order is important here too):
mVerticalFreedom = bstream->readFlag();
Now find the AdvancedCamera::setFollowTerrainMode():
void AdvancedCamera::setFollowTerrainMode(bool enable) {
mFollowTerrain = enable;
}And after it add:
void AdvancedCamera::setVerticalFreedomMode(bool enable) {
mVerticalFreedom = enable;
}Search for:
ConsoleMethod( AdvancedCamera, setFollowTerrainMode, bool, 3, 3, "(bool enable)") {
AdvancedCamera *camObj = (AdvancedCamera *) object;
camObj->setFollowTerrainMode(dAtob(argv[2]));
return true;
}And after it add:
ConsoleMethod( AdvancedCamera, setVerticalFreedomMode, bool, 3, 3, "(bool enable)") {
AdvancedCamera *camObj = (AdvancedCamera *) object;
camObj->setVerticalFreedomMode(dAtob(argv[2]));
return true;
}Finally you can tell the system to turn the mode on if you want to use it. Go to starter.fps/server/scripts and at the bottom of GameConnection::createPlayer() you'll see something like:
%this.advCamera.setPlayerObject(%player); %this.advCamera.setThirdPersonMode(); %this.advCamera.setFollowTerrainMode(false); %this.setCameraObject(%this.advCamera);
To turn it on, I change it to:
%this.advCamera.setPlayerObject(%player); %this.advCamera.setThirdPersonMode(); %this.advCamera.setFollowTerrainMode(false); %this.advCamera.setVerticalFreedomMode(true); %this.setCameraObject(%this.advCamera);
#36
Else I've went into "hack it up" time now. Expect a new release soon, and thanks to you all
02/01/2005 (8:35 am)
Thanks Zik - I've included it and modified slightly so that one can use other kinds of objects than player objects (just a little check if the current playerobject is really a player or not before applying the vertical freedom)Else I've went into "hack it up" time now. Expect a new release soon, and thanks to you all
#37
Camera also does nice interpolation now in all modes
I didnt need to modify anything in the gameConnectionMoves BTW - it all worked out of the box. Is there anything in there that should be added anyways? All changes in connectionMoves look like Cory's move manager resource and not something for the orbit camera
I'll also make some small code tid bits to the keymappings, so that they only apply when in the orbit mode. If you run a game in mixed camera modes, then the mouse mappings override control of the player. Would be nice to turn that on/off dynamically using some client/server commands (I got some similar code, so I'll just cook that up in no time)
Fantastic. Thanks a lot
I've got most of the stuff implemented now. With a little cleanup and the small extras I'll release it most likely tomorrow evening.
02/01/2005 (2:45 pm)
@Manoel - wow. Cool modification of the orbit camera. Really nice. And good way to redo the advanceTime vs. processTick/interpolateTick. I didnt realize that there was an advanceTime that could be used this way.Camera also does nice interpolation now in all modes
I didnt need to modify anything in the gameConnectionMoves BTW - it all worked out of the box. Is there anything in there that should be added anyways? All changes in connectionMoves look like Cory's move manager resource and not something for the orbit camera
I'll also make some small code tid bits to the keymappings, so that they only apply when in the orbit mode. If you run a game in mixed camera modes, then the mouse mappings override control of the player. Would be nice to turn that on/off dynamically using some client/server commands (I got some similar code, so I'll just cook that up in no time)
Fantastic. Thanks a lot
I've got most of the stuff implemented now. With a little cleanup and the small extras I'll release it most likely tomorrow evening.
#38
02/04/2005 (4:17 pm)
@Thomas- Did you get anything useful out of my advanced camera?
#39
02/05/2005 (5:21 am)
Hey Josh. Sorry. Got your email, but have been damn busy on the new Flash GUI component the last few days. Will definitely roam your code and fish out any good parts that you coded :-)
#40
02/16/2005 (5:15 am)
Why when i set the third person camera to my bike the camera shakes a lot with the movement?
Torque Owner Sam3d
Will have to try this with the pathShape resource when Thomas opens up GameBase objects.