Thanks alot, works so far. I just needed to include ClipSys/TraceResult.hpp and MaterialSystem/Material.hpp and correct 2 or 3 small things.

So, for everyone who also tried to implement a third person camera, here are the changes made so far:

in /games/deathmatch/code/HumanPlayer.cpp

EntHumanPlayerT::Draw (line 940)

Code: Select all

```
if (FirstPersonView)
{
//draw player in third person
if (State.StateOfExistance!=StateOfExistance_Alive && State.StateOfExistance!=StateOfExistance_Dead) return;
const float OffsetZ=(State.StateOfExistance!=StateOfExistance_Dead) ? -32.0f : -32.0f+float(State.Dimensions.Min.z+1728.8)/25.4f;
MatSys::Renderer->GetCurrentLightSourcePosition()[2]-=OffsetZ;
MatSys::Renderer->GetCurrentEyePosition ()[2]-=OffsetZ;
MatSys::Renderer->Translate(MatSys::RendererI::MODEL_TO_WORLD, 0.0f, 0.0f, OffsetZ);
// Draw the own player body model and the "_p" (player) model of the active weapon as sub-model of the body.
ModelProxyT& PlayerModel=GetModelFromPlayerModelIndex(State.ModelIndex);
PlayerModel.Draw(State.ModelSequNr, State.ModelFrameNr, LodDist, (State.HaveWeapons & (1 << State.ActiveWeaponSlot)) ? &CarriedWeaponT::GetCarriedWeapon(State.ActiveWeaponSlot)->GetPlayerWeaponModel() : NULL);
}
```

Basically thats a copy/paste from the code below it that is used to draw the other players. You could as well just remove the If-statement and use the same code for both of them, I kept it this way to keep the ability to have both rendered differently.

in /Ca3DE/Client/ClientWorld.cpp

add to the given includes:

Code: Select all

```
#define _USE_MATH_DEFINES
#include "math.h"
#include "ClipSys/TraceResult.hpp"
#include "MaterialSystem/Material.hpp"
```

and then in CaClientWorldT::Draw (line 327)

Code: Select all

```
Vector3dT ThirdPersonOrigin=DrawState->Origin;
float CameraDistance = 1600.0;
ThirdPersonOrigin.x -= sin(float(DrawState->Heading)*(M_PI /32768.0f)) * CameraDistance *cos(float(DrawState->Pitch )*(M_PI /32768.0f));
ThirdPersonOrigin.y -= cos(float(DrawState->Heading)*(M_PI /32768.0f)) * CameraDistance *cos(float(DrawState->Pitch )*(M_PI /32768.0f));
ThirdPersonOrigin.z += sin(float(DrawState->Pitch )*(M_PI /32768.0f)) * CameraDistance;
cf::ClipSys::TraceResultT Result;
Ca3DEWorld->CollModel->TraceRay(DrawState->Origin, ThirdPersonOrigin - DrawState->Origin, MaterialT::Clip_AllBlocking, Result);
Result.Fraction*=0.85;
ThirdPersonOrigin=ThirdPersonOrigin*Result.Fraction + DrawState->Origin*(1.0-Result.Fraction);
```

Then replace every "DrawState->Origin" with "ThirdPersonOrigin".

This is for a third person camera that aims directly at the player. This however wouldnt work with any game where you need to aim at something, e.g. shooters, because your head will occlude your target.

Code: Select all

```
Vector3dT ThirdPersonOrigin=DrawState->Origin;
float CameraDistance = 600.0;
float SideDistance = 150.0;
ThirdPersonOrigin.x -= SideDistance * sin((float(DrawState->Heading)*(M_PI /32768.0f))-(M_PI/2));
ThirdPersonOrigin.y -= SideDistance * cos((float(DrawState->Heading)*(M_PI /32768.0f))-(M_PI/2));
ThirdPersonOrigin.x -= sin(float(DrawState->Heading)*(M_PI /32768.0f)) * CameraDistance *cos(float(DrawState->Pitch )*(M_PI /32768.0f));
ThirdPersonOrigin.y -= cos(float(DrawState->Heading)*(M_PI /32768.0f)) * CameraDistance *cos(float(DrawState->Pitch )*(M_PI /32768.0f));
ThirdPersonOrigin.z += sin(float(DrawState->Pitch )*(M_PI /32768.0f)) * CameraDistance;
cf::ClipSys::TraceResultT Result;
Ca3DEWorld->CollModel->TraceRay(DrawState->Origin, ThirdPersonOrigin - DrawState->Origin, MaterialT::Clip_AllBlocking, Result);
Result.Fraction*=0.85;
ThirdPersonOrigin=ThirdPersonOrigin*Result.Fraction + DrawState->Origin*(1.0-Result.Fraction);
```

This will place the camera a little to the right, like an over-the-shoulder view. Its not perfect yet, but thats an idea how to do it. Working on a better solution though.

For those who dont understand the math:

We have:

A = player positon

c = camera distance

? (angle alpha) = heading

We need:

B = camera position, which consists of

a = value added to player pos on x-axis

b = value added to player pos on y-axis

Go check trigonometric functions on wikipedia:

http://en.wikipedia.org/wiki/Sine#Sine. ... nd_tangent
Same for z axis then as well of course.

PS: Yes, almost everyone disliked them at school. We still need them.