Cutscenes with rotating camera

I have made a possible solution for the cutscenes with rotating camera angle.

Instead of using a flag on individual layers I have added a pivot point for the camera:
1
2
3
4
5
6
7
struct layered_scene
{
   ...
   bool CameraDoPivot;
   v3 CameraPivot;
   ...
};

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
internal void
RenderLayeredScene(game_assets *Assets, render_group *RenderGroup, loaded_bitmap *DrawBuffer,
                   layered_scene *Scene, r32 tNormal)
{
    ...
                if(Scene->CameraDoPivot)
                {
                    Transform.OffsetP.xy = P.xy - (CameraPivot.xy + ((P.z - CameraPivot.z)/(CameraOffset.z - CameraPivot.z))*(CameraOffset.xy - CameraPivot.xy));
                }
                else
                {
                    Transform.OffsetP.xy = P.xy - CameraOffset.xy;
                }
    ...
}

Because the speed is impossible to get right I have added a function to layered_scene:
1
2
3
4
5
struct layered_scene
{
   ...
   r32 (*CameraMovementTiming)(r32);
};

I use this in the following way:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
internal void
RenderLayeredScene(game_assets *Assets, render_group *RenderGroup, loaded_bitmap *DrawBuffer,
                   layered_scene *Scene, r32 tNormal)
{
    ...
    v3 CameraOffset = Lerp(CameraStart, CameraMovementTiming ? Clamp01MapToRange(CameraMovementTiming(0.0f), CameraMovementTiming(tNormal), CameraMovementTiming(1.0f)) : tNormal, CameraEnd);
    ...
}

internal r32
IntroLayer3CameraMovementTiming(r32 tNormal)
{
    r32 Result = ATan2((tNormal - 0.4f) * 5.0f, 1.0f);
    
    return(Result);
}


The values:
1
{INTRO_SHOT(3), 20.0f, {0.0f, 0.3f, 0.0f}, {0.0f, 3.0f, -2.0f}, 0.0f, true, {0.0f, 0.45f, -2.5f}, IntroLayer3CameraMovementTiming}


Edit:
I have now changed the calculation of the z-coordinate as well. There is no correct answer to distance from the camera to a plane at an angle to the direction of the camera. I decided to keep the distance from the plane to the pivot point constant as the feature is used to look down at the floor, which conceptually is closer than the wall:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
if(Scene->CameraDoPivot)
{
    v3 CameraOffsetFromPivot = CameraOffset - CameraPivot;
    Transform.OffsetP.xy = P.xy - (CameraPivot.xy + ((P.z - CameraPivot.z) / CameraOffsetFromPivot.z) * CameraOffsetFromPivot.xy);
                    Transform.OffsetP.z = P.z - CameraPivot.z - Length(CameraOffsetFromPivot);
}
else
{
    Transform.OffsetP = P - CameraOffset;
}



The values:
1
{INTRO_SHOT(3), 20.0f, {0.0f, 0.3f, 0.0f}, {0.0f, 3.0f, -2.0f}, 0.0f, true, {0.0f, 0.45f, -2.5f}, IntroLayer3CameraMovementTiming}

Edited by Benjamin Pedersen on Reason: I forgot to put the values for the scene in.
Cool! How does it look?

- Casey
Oh, I forgot to put the points up. I'll edit my first post.

It looks pretty good:
  • Everything seems to be moving correctly in relation to each other
  • Towards the end, the wall seems to move away a bit
  • I added the movementTimer to prevent the camera to turn to fast towards the end.

Now, I think that the new z-value should be based on the actual z-value to the layer.
Also using angles could maybe solve the second problem. I will upload a new solution, when I get the time.

Edited by Benjamin Pedersen on