Got the Advanced Camera ressource to work with TGEA 1.8.1
by Julien Jassaud · in Torque Game Engine Advanced · 04/10/2009 (10:46 pm) · 18 replies
Hello all,
I managed to get Advanced Camera resource to work with TGEA 1.8.1. I followed the directions from www.garagegames.com/community/resource/view/5471/ and adapted them to the TGEA 1.8.1 engine directory structure and headers. Maybe there is a better way, but here is what worked for me :
1. Copy the files (advancedCamera.cc and advancedCamera.h) downloaded from the Advanced Camera resource page to engine/source/T3D. Add the files to your project (on a Mac, right click or ctrl click the Code->engine->T3D folder and select Add->Existing files then chose the 2 files).
2. Modify advancedCamera.h. Find this block of code :
and replace it by :
3. Modify advancedCamera.cc. Replace all the #include section by :
4. Recompile the project.
5. Follow instructions from the Advance Camera resource from the Script section.
6. When you run your game (in my case the Template project), the camera automatically starts in FPS view. Press tab to switch to third person view.
Thanks to Thomas \"Man of Ice\" Lund for the original resource.
I hope this helps.
Julien
I managed to get Advanced Camera resource to work with TGEA 1.8.1. I followed the directions from www.garagegames.com/community/resource/view/5471/ and adapted them to the TGEA 1.8.1 engine directory structure and headers. Maybe there is a better way, but here is what worked for me :
1. Copy the files (advancedCamera.cc and advancedCamera.h) downloaded from the Advanced Camera resource page to engine/source/T3D. Add the files to your project (on a Mac, right click or ctrl click the Code->engine->T3D folder and select Add->Existing files then chose the 2 files).
2. Modify advancedCamera.h. Find this block of code :
#ifndef _SHAPEBASE_H_ #include "game/shapeBase.h" #endif
and replace it by :
#ifndef _SHAPEBASE_H_ #include "T3D/shapeBase.h" #endif
3. Modify advancedCamera.cc. Replace all the #include section by :
#include "T3D/advancedCamera.h" #include "T3D/gameConnection.h" #include "T3D/camera.h" #include "T3D/moveManager.h" #include "T3D/player.h" #include "platform/platform.h" #include "gfx/gfxDrawUtil.h" #include "T3D/gameBase.h" #include "math/mMath.h" #include "console/simBase.h" #include "console/console.h" #include "console/consoleTypes.h" #include "core/stream/bitStream.h" #include "core/dnet.h" #include "math/mathIO.h" #include "gui/missionEditor/editor.h" #include "math/mathUtils.h" #include <string.h> #include <stdlib.h>
4. Recompile the project.
5. Follow instructions from the Advance Camera resource from the Script section.
6. When you run your game (in my case the Template project), the camera automatically starts in FPS view. Press tab to switch to third person view.
Thanks to Thomas \"Man of Ice\" Lund for the original resource.
I hope this helps.
Julien
About the author
#2
04/11/2009 (12:32 pm)
There's already a method to go directly to third person when you enter the game. Simply add this one line to the end of GameConnection::onClientEnterGame() in the Template project: %this.setFirstPerson(false);In the other projects you would add that one line to GameConnection::createPlayer()
#3
Another questions comes to mind : how would you prevent the user to switch back to first person view ?
04/12/2009 (8:47 am)
Thank you very much for the precisions.Another questions comes to mind : how would you prevent the user to switch back to first person view ?
#4
04/12/2009 (9:43 am)
In default.bind.cs simply remove the keybind and toggle for 1st/3rd person:function toggleFirstPerson(%val)
{
if (%val)
{
ServerConnection.setFirstPerson(!ServerConnection.isFirstPerson());
}
}
moveMap.bind(keyboard, tab, toggleFirstPerson );Just comment (or remove) the function and the bind command.
#5
C:\Torque\TGEA_1_7_1\...\server\scripts\game.cs
GameConnection::onClientEnterGame()
where you modified?
I follow "Script" section from
www.garagegames.com/community/resource/view/5471/
and the mouse action can't work.
Thanks!
04/13/2009 (2:03 am)
Hello,Can you post the C:\Torque\TGEA_1_7_1\...\server\scripts\game.cs
GameConnection::onClientEnterGame()
where you modified?
I follow "Script" section from
www.garagegames.com/community/resource/view/5471/
and the mouse action can't work.
Thanks!
#6
- To ccljyc : I am working with TGEA 1.8.1, so maybe there are differences. I modified /server/scripts/games.cs like this :
. functions GameConnection::onClientEnterGame() and GameConnection::onCLientLeaveGame()
. at the very beginning of GameConnection::onDeath()
. at the very end of GameConnection::createPlayer()
I hope this helps.
04/13/2009 (8:50 am)
- To Michael Hall : thanks !- To ccljyc : I am working with TGEA 1.8.1, so maybe there are differences. I modified /server/scripts/games.cs like this :
. functions GameConnection::onClientEnterGame() and GameConnection::onCLientLeaveGame()
function GameConnection::onClientEnterGame(%this)
{
commandToClient(%this, 'SyncClock', $Sim::Time - $Game::StartTime);
// Create a new camera object.
%this.advCamera = new AdvancedCamera() {
dataBlock = AdvCameraData;
};
MissionCleanup.add( %this.advCamera );
%this.advCamera.scopeToClient(%this);
// Setup game parameters, the onConnect method currently starts
// everyone with a 0 score.
%this.score = 0;
%this.setControlObject(%this.camera);
%spawnPoint = pickSpawnPoint();
//%this.camera.setTransform( %spawnPoint );
// Create a player object.
%this.spawnPlayer();
}
function GameConnection::onClientLeaveGame(%this)
{
if (isObject(%this.advCamera))
%this.advCamera.delete();
if (isObject(%this.player))
%this.player.delete();
}. at the very beginning of GameConnection::onDeath()
function GameConnection::onDeath(%this, %sourceObject, %sourceClient, %damageType, %damLoc)
{
// clear connections camera
%this.advCamera.clearPlayerObject();
%this.advCamera.clearTargetObject();
%this.clearCameraObject();
// Clear out the name on the corpse
%this.player.setShapeName("");. at the very end of GameConnection::createPlayer()
// Give the client control of the player %this.player = %player; %this.setControlObject(%player); // We set the camera system to run in 3rd person mode around the %player %this.advCamera.setPlayerObject(%player); %this.advCamera.setGodViewMode(); %this.setFirstPerson(false); %this.advCamera.setFollowTerrainMode(false); %this.advCamera.setVerticalFreedomMode(false); %this.setCameraObject(%this.advCamera); }
I hope this helps.
#9
04/14/2009 (6:42 pm)
To ccljyc : I think what you want is called orbit mode. I don't know so much about it since this is not the mode I am using. It is thoroughly describe in the Advanced Camera resource (www.garagegames.com/community/resource/view/5471/), though.
#10
I see you are using the GodView in your script and so am I. Have you tried using the resource that changes player controls relative to the camera (http://www.garagegames.com/community/resources/view/5474) sort of like diablo? The article is from 2004 so I thought I'd ask if you have tried it before I try it in TGEA 1.8.1.
Also, have you noticed jitter in the camera? If so, do you know the best way to fix that? None of the fixes in the original resource seem to help.
04/22/2009 (3:30 pm)
Hi Julien,I see you are using the GodView in your script and so am I. Have you tried using the resource that changes player controls relative to the camera (http://www.garagegames.com/community/resources/view/5474) sort of like diablo? The article is from 2004 so I thought I'd ask if you have tried it before I try it in TGEA 1.8.1.
Also, have you noticed jitter in the camera? If so, do you know the best way to fix that? None of the fixes in the original resource seem to help.
#11
in setPosition find:
replace with:
Try different values of tInterpolation.
I found on low level hardware,jittering is missing.
04/23/2009 (9:29 am)
Ben,you can experiment with cosine interpolation.in setPosition find:
Point3F tPos = getPosition(); F32 tInterpolation = 0.333333333; tPos = pos;
replace with:
Point3F tPos = getPosition(); F32 tInterpolation = 0.333333333f; F32 mu2; mu2 = (1-mCos(tInterpolation*M_PI))/2; tPos = pos*(1-mu2) + tPos*mu2;
Try different values of tInterpolation.
I found on low level hardware,jittering is missing.
#12
Just for anyone who is interested, I implemented the resource for relative player movements with a fixed camera (http://www.garagegames.com/community/resources/view/5474) and got it to work with 1.8.1.
Here are the changes that I made to make it work:
In T3D/movelist.cpp, in the function getNextMove(), add the following lines:
Between
and
04/23/2009 (10:46 pm)
Picasso, that interpolation method worked beautifully! I really appreciate it.Just for anyone who is interested, I implemented the resource for relative player movements with a fixed camera (http://www.garagegames.com/community/resources/view/5474) and got it to work with 1.8.1.
Here are the changes that I made to make it work:
In T3D/movelist.cpp, in the function getNextMove(), add the following lines:
if (!mConnection->isFirstPerson() && mConnection->getControlObject() && mConnection->getCameraObject() && (curMove.x || curMove.y)) {
// get the camera's transform and forward vector
MatrixF camTrans = mConnection->getCameraObject()->getRenderTransform();
VectorF camF;
camTrans.getColumn(1, &camF);
// translate f,b,l,r (x,y) to rotational changes
// relative to the camera object
VectorF dirVec;
if (mFabs(camF.z) < M_SQRTHALF) {
dirVec = VectorF(curMove.x, curMove.y, 0);
} else {
dirVec = VectorF(curMove.x, 0, curMove.y);
}
VectorF dirVecTrans;
camTrans.mulV(dirVec, &dirVecTrans);
F32 dirYaw, dirPitch;
// Move player in a direction relative to the camera vector
MathUtils::getAnglesFromVector(dirVecTrans, dirYaw, dirPitch);
MathUtils::getAnglesFromVector(dirVec, dirYaw, dirPitch);
F32 curYaw = mConnection->getControlObject()->getTransform().toEuler().z;
curMove.yaw = dirYaw - curYaw;
curMove.x = 0;
// adjust how far forward we move based on the length
// this is useful for joystick/gamepad control
// if you want to move faster or use a script-based
// movement speed, feel free to adjust
F32 lenSqr = dirVec.lenSquared();
curMove.y = lenSqr >= 0.75 ? 1.0 :
(lenSqr >= 0.50 ? 0.5 :
(lenSqr >= 0.25 ? 0.25 : 0));
}Between
for(U32 i = 0; i < MaxTriggerKeys; i++)
{
curMove.trigger[i] = false;
if(MoveManager::mTriggerCount[i] & 1)
curMove.trigger[i] = true;
else if(!(MoveManager::mPrevTriggerCount[i] & 1) && MoveManager::mPrevTriggerCount[i] != MoveManager::mTriggerCount[i])
curMove.trigger[i] = true;
MoveManager::mPrevTriggerCount[i] = MoveManager::mTriggerCount[i];
}and
if (mConnection->getControlObject())
mConnection->getControlObject()->preprocessMove(&curMove);
curMove.clamp(); // clamp for net traffic
return true;
#13
05/16/2009 (10:02 pm)
Hey, i got it working with your game.cs, but it doesnt respond to any of the mouse controls on any mode. Any ideas? im sort of new to coding.
#14
05/19/2009 (10:31 pm)
The mouse movement works only when you are in a certain mode. try setting your camera to orbit mode and see if that helps.
#15
What did you do in your gameConnection.cpp?
I've been trying to get the adv. cam to work with 1.8.1 but i keep getting errors on the build?
Just any help would do :P - im basically "hello world" level in C++ so, im pretty lost...
06/02/2009 (4:58 am)
Hi Julian;What did you do in your gameConnection.cpp?
I've been trying to get the adv. cam to work with 1.8.1 but i keep getting errors on the build?
Just any help would do :P - im basically "hello world" level in C++ so, im pretty lost...
#16
The changes to gameConnection.cpp in the Advanced Camera resource were already incorporated in the engine so you shouldn't have to modify anything there and just follow that resource from the script section. The minor changes I did to advancedCamera.h only reflect the new source structure of the engine.
I am sorry I can't help more. This was a long time ago and I sinced moved to TGB.
Julien
06/02/2009 (6:01 am)
Sebastian,The changes to gameConnection.cpp in the Advanced Camera resource were already incorporated in the engine so you shouldn't have to modify anything there and just follow that resource from the script section. The minor changes I did to advancedCamera.h only reflect the new source structure of the engine.
I am sorry I can't help more. This was a long time ago and I sinced moved to TGB.
Julien
#17
Time to try again. :P
anyway... thx!
Seb.
06/02/2009 (7:48 am)
hmm, okay... maybe i screwed it up somewhere else...Time to try again. :P
anyway... thx!
Seb.
#18
06/14/2009 (7:53 am)
Has anyone managed to port the advanced camera resource to T3D yet? Im trying, but I keep running into problem's.
Torque Owner Ivan Mandzhukov
Liman
movelist.cpp
in MoveList::getNextMove(Move &curMove)
..... if ( !mConnection->isFirstPerson() && mConnection->getCameraObject() && mConnection->getControlObject() && (curMove.x || curMove.y) && !gEditingMission) {......} .....