Help for the Start - 3rd Person view
Hi @ll,
I tried to figure out the things by myself - but I don't even get an idea how to start with my Ideas:
* Player is in 3rd person view
* Holding LMB and moving (4 directions!) moves the camera
* (optional) scrolling moves the camera away or towards the player (nearest is 1st Person view)
* (optional optional) Holding RMB like lmb but also turns player with the camera.
If you could give me some little detailed hints I think I will be able to figure out the next steps by myself.
Thank you alot!
I tried to figure out the things by myself - but I don't even get an idea how to start with my Ideas:
* Player is in 3rd person view
* Holding LMB and moving (4 directions!) moves the camera
* (optional) scrolling moves the camera away or towards the player (nearest is 1st Person view)
* (optional optional) Holding RMB like lmb but also turns player with the camera.
If you could give me some little detailed hints I think I will be able to figure out the next steps by myself.
Thank you alot!
Project Status: Code architecture definition
6 Programmers, 1 Photographer, 1 Architect, 1 Game designer
6 Programmers, 1 Photographer, 1 Architect, 1 Game designer
Re: Help for the Start - 3rd Person view
Hi Haimi,
well, these are tough questions, especially as I fear that the current game code, as-is, needs some nontrivial changes to support this (one of the reasons why I plan to revise and improve it).
A side question ahead: Are you familiar with Git?
I'm currently toying with it and plan to migrate the Cafu Subversion repository to it sometime during this year, and it would be a nice tool to (possibly collaboratively) develop a "3rd person view" branch.
Git however, in its full depth, is not exactly easy to learn, so it's okay if for 3rd person view we proceed without it as well.
Well, the pure rendering of a 3rd person model in the HumanPlayer code should not be terribly difficult.
How it is done technically you can see e.g. in the CompanyBot code and in almost any non-player character entity code.
More difficult will it be to create a proper mental "model" for the 3rd person view:
For example, at this time, all entities can only have state as described in
One (relatively easy) way for avoiding this is changing the core engine to render the world not from the viewpoint of the local human player entity, but from a given distance.
A second option that just occurred to me but that I haven't fully thought-out would be to keep the 3rd person entity entirely separate from the human player "camera". That is, loosely speaking, these changes might achieve a similar effect:
For example, if the human player fires, it would only carry the state "I'm firing", but take no own action. Instead, the modified CompanyBot would figure out that "its" human player wants to fire, and carry out the fire action itself.
As all this might involve client-server communications until the CompanyBot does something, it might turn out to suffer from internet latency. On the plus side, it would keep the camera and the character very independent of each other: E.g. the camera could take a detour at any time in mid game, then return to the 3rd person character, which might be interesting in it's own right.
But as said above, I've not fully thought this out...
Finally, 3rd person view has been discussed before, please see this thread, which also has technical details and source code:
http://www.cafu.de/forum/viewtopic.php?f=8&t=760
I'm happy to help you in this regard, and it would be wonderful if we could eventually change Cafu to have optional 3rd person view built-in by default...
well, these are tough questions, especially as I fear that the current game code, as-is, needs some nontrivial changes to support this (one of the reasons why I plan to revise and improve it).
A side question ahead: Are you familiar with Git?
I'm currently toying with it and plan to migrate the Cafu Subversion repository to it sometime during this year, and it would be a nice tool to (possibly collaboratively) develop a "3rd person view" branch.
Git however, in its full depth, is not exactly easy to learn, so it's okay if for 3rd person view we proceed without it as well.
Well, the pure rendering of a 3rd person model in the HumanPlayer code should not be terribly difficult.
How it is done technically you can see e.g. in the CompanyBot code and in almost any non-player character entity code.
More difficult will it be to create a proper mental "model" for the 3rd person view:
For example, at this time, all entities can only have state as described in
struct EntityStateT
. With 3rd person view, if it was all to be built into the EntHumanPlayerT
class, we had not only to store the position, orientation, etc. of the "true", first-person camera, but also the position and orientation of the 3rd person model.One (relatively easy) way for avoiding this is changing the core engine to render the world not from the viewpoint of the local human player entity, but from a given distance.
A second option that just occurred to me but that I haven't fully thought-out would be to keep the 3rd person entity entirely separate from the human player "camera". That is, loosely speaking, these changes might achieve a similar effect:
- the human player entity code would render no own body(parts), but remain responsible for the (fly/orbit-mode) camera where the world is rendered from,
- the CompanyBot would be copied and made to act or "mimic" / "carry out" the humay player entities intentions.
For example, if the human player fires, it would only carry the state "I'm firing", but take no own action. Instead, the modified CompanyBot would figure out that "its" human player wants to fire, and carry out the fire action itself.
As all this might involve client-server communications until the CompanyBot does something, it might turn out to suffer from internet latency. On the plus side, it would keep the camera and the character very independent of each other: E.g. the camera could take a detour at any time in mid game, then return to the 3rd person character, which might be interesting in it's own right.
But as said above, I've not fully thought this out...
Finally, 3rd person view has been discussed before, please see this thread, which also has technical details and source code:
http://www.cafu.de/forum/viewtopic.php?f=8&t=760
I'm happy to help you in this regard, and it would be wonderful if we could eventually change Cafu to have optional 3rd person view built-in by default...
Best regards,
Carsten
Carsten
Re: Help for the Start - 3rd Person view
Okay, I tried some things - but I realize that I have to grow my C++ Skills a little further ![Wink ;)](./images/smilies/icon_wink.gif)
But I realize the 3rd person view modular, so it can easily be exported.
And - I will SURE give you the sources, the better this rad engine grows, the better.
OT: Next week (Tue-Thu) my team is meeting for a 3-Day Jam to get the base game running a little quicker. So there will be 6-8 People be working 72 hours with Cafu![Smile :)](./images/smilies/icon_smile.gif)
![Wink ;)](./images/smilies/icon_wink.gif)
But I realize the 3rd person view modular, so it can easily be exported.
And - I will SURE give you the sources, the better this rad engine grows, the better.
OT: Next week (Tue-Thu) my team is meeting for a 3-Day Jam to get the base game running a little quicker. So there will be 6-8 People be working 72 hours with Cafu
![Smile :)](./images/smilies/icon_smile.gif)
Project Status: Code architecture definition
6 Programmers, 1 Photographer, 1 Architect, 1 Game designer
6 Programmers, 1 Photographer, 1 Architect, 1 Game designer
Re: Help for the Start - 3rd Person view
Wow, that's good to hear!Haimi wrote:OT: Next week (Tue-Thu) my team is meeting for a 3-Day Jam to get the base game running a little quicker. So there will be 6-8 People be working 72 hours with Cafu
![WOW :wohow:](./images/smilies/wohow.gif)
I'll try to arrange my time so that I can, if necessary during these days, reply to forum posts quickly and thoroughly.
![Thumb Up :up:](./images/smilies/thumbup.gif)
Best regards,
Carsten
Carsten
Re: Help for the Start - 3rd Person view
Wow, i'd appreciate that very, very much!
That would be really cool!
That would be really cool!
Project Status: Code architecture definition
6 Programmers, 1 Photographer, 1 Architect, 1 Game designer
6 Programmers, 1 Photographer, 1 Architect, 1 Game designer
Re: Help for the Start - 3rd Person view
So the 3rd Person view works very well! I think the changes in the engine may be exported very easily.
I will also chance the EntityStateT to define the camera positions from inside here.
So the topic is fulfilled
I understand the code now
THANKS ALOT!
![Thanks :thanks:](./images/smilies/thanks.gif)
I will also chance the EntityStateT to define the camera positions from inside here.
So the topic is fulfilled
![Smile :)](./images/smilies/icon_smile.gif)
THANKS ALOT!
![Thanks :thanks:](./images/smilies/thanks.gif)
Project Status: Code architecture definition
6 Programmers, 1 Photographer, 1 Architect, 1 Game designer
6 Programmers, 1 Photographer, 1 Architect, 1 Game designer
Re: Help for the Start - 3rd Person view
Hi,
I managed to encapsulate the trick![Smile :)](./images/smilies/icon_smile.gif)
BaseEntity.hpp:56
BaseEntity.cpp:53ff
And in the ClientWorld.cpp:310ff:
... and replaced every
with
Next, in the HumanPlayer.cpp:954 I changet the
to This is to make it possible to leave the first person perspective if the camera is scrolled out.
Then I had to change every EntityStateT Constructor Call to add the new and required setting CameraPosition. And Voilà, it works like a charm.
I managed to encapsulate the trick
![Smile :)](./images/smilies/icon_smile.gif)
BaseEntity.hpp:56
Code: Select all
float CameraDistance; // Distance from camera to model
Code: Select all
EntityStateT::EntityStateT(const VectorT& Origin_, const VectorT& Velocity_,
const BoundingBox3T<double>& Dimensions_, unsigned short Heading_,
unsigned short Pitch_, unsigned short Bank_, char StateOfExistance_,
char Flags_, char ModelIndex_, char ModelSequNr_, float ModelFrameNr_,
char Health_, char Armor_, unsigned long HaveItems_, unsigned long HaveWeapons_,
char ActiveWeaponSlot_, char ActiveWeaponSequNr_, float ActiveWeaponFrameNr_,
float CameraDistance_)
: Origin(Origin_),
Velocity(Velocity_),
Dimensions(Dimensions_),
CameraDistance(CameraDistance_),
Code: Select all
Vector3dT CameraOrigin = DrawState->Origin;
if (DrawState->CameraDistance > 0) {
CameraOrigin.x -= sin(float(DrawState->Heading)*(M_PI /32768.0f)) *
DrawState->CameraDistance *cos(float(DrawState->Pitch )*(M_PI /32768.0f));
CameraOrigin.y -= cos(float(DrawState->Heading)*(M_PI /32768.0f)) *
DrawState->CameraDistance *cos(float(DrawState->Pitch )*(M_PI /32768.0f));
CameraOrigin.z += sin(float(DrawState->Pitch )*(M_PI /32768.0f)) *
DrawState->CameraDistance;
cf::ClipSys::TraceResultT Result;
Ca3DEWorld->CollModel->TraceRay(DrawState->Origin,
CameraOrigin - DrawState->Origin, MaterialT::Clip_AllBlocking, Result);
Result.Fraction *= 0.85;
CameraOrigin=CameraOrigin * Result.Fraction + DrawState->Origin * (1.0 - Result.Fraction);
}
Code: Select all
DrawState->Origin
Code: Select all
CameraOrigin
Code: Select all
if (FirstPersonView)
Code: Select all
if (FirstPersonView && State.CameraDistance == 0.0)
Then I had to change every EntityStateT Constructor Call to add the new and required setting CameraPosition. And Voilà, it works like a charm.
Project Status: Code architecture definition
6 Programmers, 1 Photographer, 1 Architect, 1 Game designer
6 Programmers, 1 Photographer, 1 Architect, 1 Game designer
Re: Help for the Start - 3rd Person view
So again I tried and managed to add the PlayerCommand to change the camera distance on mousewheel and in HumanPlayer.cpp I added
Which definitely works (I tried with console output), but every second tick it reverts to my default distance. Do I have to save anything from one tick to another?
Code: Select all
// Update Camera Distance
State.CameraDistance += PlayerCommands[PCNr].DeltaCameraDistance;
Project Status: Code architecture definition
6 Programmers, 1 Photographer, 1 Architect, 1 Game designer
6 Programmers, 1 Photographer, 1 Architect, 1 Game designer
Re: Help for the Start - 3rd Person view
Hmmmmm... well, I don't know the code that you wrote, but this sounds as if the client prediction is interfering with your custom code:
You apparently added member
For testing, you can try to set at the command line and see if that makes any difference.
The "proper" fix is probably (remember, I'm just guessing your code here!) to find all places marked like this: and to update the relevant code accordingly.
In order to work-around the problem in a simpler manner, you might simply "mis-use" e.g. one of the members of
This is a bit awkward, but you can rely on the existing code to handle everything right regarding the prediction issue.
You apparently added member
CameraDistance
to struct EntityStateT
, which the client prediction code manipulates frequently without directly telling the game code (a misfortune and general design error that I'll have to fix large-scale asap).For testing, you can try to set
Code: Select all
usePrediction = false;
The "proper" fix is probably (remember, I'm just guessing your code here!) to find all places marked like this:
Code: Select all
/*** EntityStateT field changes FORCE protocol changes in ALL places that are marked *like this* (use grep)! ***/
In order to work-around the problem in a simpler manner, you might simply "mis-use" e.g. one of the
Code: Select all
unsigned short HaveAmmo[16];
EntityStateT
, e.g. the last one at index 15, or the first one for which you have no use.This is a bit awkward, but you can rely on the existing code to handle everything right regarding the prediction issue.
Best regards,
Carsten
Carsten
Re: Help for the Start - 3rd Person view
This is some Kind of weird, I did the "Proper" fix first, but it changed nothing.
Then I entered the console-command to turn off prediction and ended up with scrolling does nothing at all... Any other Ideas?
here is my code snippet for the catching of the mousewheel event, the rest of my code is already (near all of it
) in this thread
:
ClientStateInGame.cpp: added llines
Then I entered the console-command to turn off prediction and ended up with scrolling does nothing at all... Any other Ideas?
here is my code snippet for the catching of the mousewheel event, the rest of my code is already (near all of it
![Laughing :lol:](./images/smilies/icon_lol.gif)
![Very Happy :D](./images/smilies/icon_biggrin.gif)
ClientStateInGame.cpp: added llines
Code: Select all
case CaMouseEventT::CM_MOVE_Z: // Wheel
{
PlayerCommand.DeltaCameraDistance += (short)(ME.Amount);
break;
}
Project Status: Code architecture definition
6 Programmers, 1 Photographer, 1 Architect, 1 Game designer
6 Programmers, 1 Photographer, 1 Architect, 1 Game designer
Re: Help for the Start - 3rd Person view
[Ah, sorry, I didn't see your larger post with the code above the smaller one earlier...]
members as I suggested above, then no.
With your existing approach as-is, could you send me (or attach here) a diff with your changes?
I'd rather have a look at the complete picture...
(If possible, please put only the related 3rd person view changes into the diff, not also the GUI issues etc.)
At the moment, and if you don't what to undertake the bit-fiddling adventure regarding mis-using theHaimi wrote:Any other Ideas?
Code: Select all
unsigned short HaveAmmo[16];
With your existing approach as-is, could you send me (or attach here) a diff with your changes?
I'd rather have a look at the complete picture...
(If possible, please put only the related 3rd person view changes into the diff, not also the GUI issues etc.)
Best regards,
Carsten
Carsten
Re: Help for the Start - 3rd Person view
The Bigger Post above is the complete changelist i did... This is enough to make a real 3rd Person view.
Project Status: Code architecture definition
6 Programmers, 1 Photographer, 1 Architect, 1 Game designer
6 Programmers, 1 Photographer, 1 Architect, 1 Game designer
Re: Help for the Start - 3rd Person view
Unfortunately, as the big comment suggests, adding fields to the
This, unfortunately, until this problem is solved more thoroughly as discussed in another thread, is the only proper way to add new members to
Code: Select all
/*** EntityStateT field changes FORCE protocol changes in ALL places that are marked *like this* (use grep)! ***/
EntityStateT
class requires also changes to the related code in EngineEntity.cpp
and EntityManager.cpp
in [url=http://trac.cafu.de/browser/cafu/trunk/Ca3DE/Both?rev=483]Ca3DE/Both/[/url]
…This, unfortunately, until this problem is solved more thoroughly as discussed in another thread, is the only proper way to add new members to
EntityStateT
.Best regards,
Carsten
Carsten
Who is online
Users browsing this forum: No registered users and 127 guests