Help for the Start - 3rd Person view

Get technical support about the C++ source code and about Lua scripts for maps, entities, GUIs, the console, materials, etc. Also covered are the Cafu libraries and APIs, as well as compiling, linking, and the build system.
User avatar
Haimi
Posts: 85
Joined: 2011-11-23, 09:28

Help for the Start - 3rd Person view

Postby Haimi » 2012-02-08, 22:07

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!
Project Status: Code architecture definition
6 Programmers, 1 Photographer, 1 Architect, 1 Game designer
User avatar
Carsten
Site Admin
Posts: 2007
Joined: 2004-08-19, 13:46
Location: Germany
Contact:

Re: Help for the Start - 3rd Person view

Postby Carsten » 2012-02-09, 12:19

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 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.
Then this would work as if the Company Bot was an "allied" character, but (made to) feel like the human players own character.
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:
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
User avatar
Haimi
Posts: 85
Joined: 2011-11-23, 09:28

Re: Help for the Start - 3rd Person view

Postby Haimi » 2012-02-22, 11:32

Okay, I tried some things - but I realize that I have to grow my C++ Skills a little further ;)

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 :)
Project Status: Code architecture definition
6 Programmers, 1 Photographer, 1 Architect, 1 Game designer
User avatar
Carsten
Site Admin
Posts: 2007
Joined: 2004-08-19, 13:46
Location: Germany
Contact:

Re: Help for the Start - 3rd Person view

Postby Carsten » 2012-02-22, 18:17

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, that's good to hear! :wohow:
I'll try to arrange my time so that I can, if necessary during these days, reply to forum posts quickly and thoroughly. :up:
Best regards,
Carsten
User avatar
Haimi
Posts: 85
Joined: 2011-11-23, 09:28

Re: Help for the Start - 3rd Person view

Postby Haimi » 2012-02-22, 18:22

Wow, i'd appreciate that very, very much!
That would be really cool!
Project Status: Code architecture definition
6 Programmers, 1 Photographer, 1 Architect, 1 Game designer
User avatar
Haimi
Posts: 85
Joined: 2011-11-23, 09:28

Re: Help for the Start - 3rd Person view

Postby Haimi » 2012-02-23, 15:37

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:
Project Status: Code architecture definition
6 Programmers, 1 Photographer, 1 Architect, 1 Game designer
User avatar
Haimi
Posts: 85
Joined: 2011-11-23, 09:28

Re: Help for the Start - 3rd Person view

Postby Haimi » 2012-02-25, 15:54

Hi,

I managed to encapsulate the trick :)
BaseEntity.hpp:56

Code: Select all

 float    CameraDistance; // Distance from camera to model

BaseEntity.cpp:53ff

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_),


And in the ClientWorld.cpp:310ff:

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);
   }

... and replaced every

Code: Select all

DrawState->Origin
with

Code: Select all

CameraOrigin

Next, in the HumanPlayer.cpp:954 I changet the

Code: Select all

if (FirstPersonView)
to

Code: Select all

if (FirstPersonView && State.CameraDistance == 0.0)
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.
Project Status: Code architecture definition
6 Programmers, 1 Photographer, 1 Architect, 1 Game designer
User avatar
Haimi
Posts: 85
Joined: 2011-11-23, 09:28

Re: Help for the Start - 3rd Person view

Postby Haimi » 2012-02-25, 18:05

So again I tried and managed to add the PlayerCommand to change the camera distance on mousewheel and in HumanPlayer.cpp I added

Code: Select all

 // Update Camera Distance
State.CameraDistance += PlayerCommands[PCNr].DeltaCameraDistance;

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?
Project Status: Code architecture definition
6 Programmers, 1 Photographer, 1 Architect, 1 Game designer
User avatar
Carsten
Site Admin
Posts: 2007
Joined: 2004-08-19, 13:46
Location: Germany
Contact:

Re: Help for the Start - 3rd Person view

Postby Carsten » 2012-02-27, 02:09

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 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;
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:

Code: Select all

/*** EntityStateT field changes FORCE protocol changes in ALL places that are marked *like this* (use grep)! ***/
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

Code: Select all

    unsigned short HaveAmmo[16];
members of 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
User avatar
Haimi
Posts: 85
Joined: 2011-11-23, 09:28

Re: Help for the Start - 3rd Person view

Postby Haimi » 2012-02-27, 03:19

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 :lol: ) in this thread :D:
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
User avatar
Carsten
Site Admin
Posts: 2007
Joined: 2004-08-19, 13:46
Location: Germany
Contact:

Re: Help for the Start - 3rd Person view

Postby Carsten » 2012-02-28, 01:55

[Ah, sorry, I didn't see your larger post with the code above the smaller one earlier...]

Haimi wrote:Any other Ideas?

At the moment, and if you don't what to undertake the bit-fiddling adventure regarding mis-using the

Code: Select all

unsigned short HaveAmmo[16];
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.)
Best regards,
Carsten
User avatar
Haimi
Posts: 85
Joined: 2011-11-23, 09:28

Re: Help for the Start - 3rd Person view

Postby Haimi » 2012-02-28, 13:49

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
User avatar
Carsten
Site Admin
Posts: 2007
Joined: 2004-08-19, 13:46
Location: Germany
Contact:

Re: Help for the Start - 3rd Person view

Postby Carsten » 2012-02-29, 00:10

Unfortunately, as the big

Code: Select all

/*** EntityStateT field changes FORCE protocol changes in ALL places that are marked *like this* (use grep)! ***/
comment suggests, adding fields to the EntityStateT class requires also changes to the related code in EngineEntity.cpp and EntityManager.cpp in Ca3DE/Both/

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

Return to “Coding and Scripting”

Who is online

Users browsing this forum: No registered users and 2 guests