1 #pragma once
2 
3 //********************************************************************************************
4 //*
5 //*    This file is part of Egoboo.
6 //*
7 //*    Egoboo is free software: you can redistribute it and/or modify it
8 //*    under the terms of the GNU General Public License as published by
9 //*    the Free Software Foundation, either version 3 of the License, or
10 //*    (at your option) any later version.
11 //*
12 //*    Egoboo is distributed in the hope that it will be useful, but
13 //*    WITHOUT ANY WARRANTY; without even the implied warranty of
14 //*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 //*    General Public License for more details.
16 //*
17 //*    You should have received a copy of the GNU General Public License
18 //*    along with Egoboo.  If not, see <http://www.gnu.org/licenses/>.
19 //*
20 //********************************************************************************************
21 
22 /// @file camera.h
23 
24 #include "egoboo_typedef.h"
25 #include "egoboo_math.h"
26 #include "physics.h"
27 
28 //--------------------------------------------------------------------------------------------
29 //--------------------------------------------------------------------------------------------
30 struct s_ego_mpd;
31 
32 //--------------------------------------------------------------------------------------------
33 //--------------------------------------------------------------------------------------------
34 
35 /// The camera mode
36 enum e_camera_mode
37 {
38     CAM_PLAYER = 0,
39     CAM_FREE,
40     CAM_RESET
41 };
42 
43 /// The mode that the camera uses to determine where is is looking
44 enum e_camera_turn_mode
45 {
46     CAM_TURN_NONE = bfalse,
47     CAM_TURN_AUTO = btrue,
48     CAM_TURN_GOOD = 255
49 };
50 
51 #define CAM_TRACK_X_AREA_LOW     100
52 #define CAM_TRACK_X_AREA_HIGH    180
53 #define CAM_TRACK_Y_AREA_MINLOW  320
54 #define CAM_TRACK_Y_AREA_MAXLOW  460
55 #define CAM_TRACK_Y_AREA_MINHIGH 460
56 #define CAM_TRACK_Y_AREA_MAXHIGH 600
57 
58 #define CAM_FOV                             60          ///< Field of view
59 #define CAM_TURN_JOY              (3.0f * 5.0f)         ///< Joystick camera rotation
60 #define CAM_TURN_KEY               CAM_TURN_JOY         ///< Keyboard camera rotation
61 #define CAM_TURN_TIME                       16          ///< Smooth turn
62 #define CAM_TRACK_FAR                     1200          ///< For outside modules...
63 #define CAM_TRACK_EDGE                     800          ///< Camtrack bounds
64 
65 /// Multi cam (uses macro to switch between old and new camera
66 #if !defined(OLD_CAMERA_MODE)
67 #    define CAM_ZOOM_MIN                         800         ///< Camera distance
68 #    define CAM_ZOOM_MAX                         700
69 #    define CAM_ZADD_MIN                         800         ///< Camera height
70 #    define CAM_ZADD_MAX                         2500
71 #    define CAM_UPDOWN_MIN                       (0.24f*PI)    ///< Camera updown angle
72 #    define CAM_UPDOWN_MAX                       (0.10f*PI)
73 #else
74 #    define CAM_ZOOM_MIN                         500         ///< Camera distance
75 #    define CAM_ZOOM_MAX                         600
76 #    define CAM_ZADD_MIN                         800         ///< Camera height
77 #    define CAM_ZADD_MAX                         1500  ///< 1000
78 #    define CAM_UPDOWN_MIN                       (0.24f*PI)    ///< Camera updown angle
79 #    define CAM_UPDOWN_MAX                       (0.18f*PI)// (0.15f*PI) ///< (0.18f*PI)
80 #endif
81 
82 //--------------------------------------------------------------------------------------------
83 //--------------------------------------------------------------------------------------------
84 
85 /// definition of the Egoboo camera object
86 struct s_camera
87 {
88     fmat_4x4_t mView, mViewSave;      ///< View Matrix
89     fmat_4x4_t mProjection;           ///< Projection Matrix
90 
91     Uint8  move_mode;               ///< what is the camera mode
92     Uint8  move_mode_old;           ///< the default movement mode
93     Uint8  turn_mode;               ///< what is the camera mode
94     Uint8  turn_time;               ///< time for the smooth turn
95 
96     int           swing;                   ///< Camera swingin'
97     int           swingrate;
98     float         swingamp;
99 
100     fvec3_t       pos;                       ///< Camera position (z = 500-1000)
101     orientation_t ori;
102 
103     float         zoom;                    ///< Distance from the trackee
104     fvec3_t       track_pos;                  ///< Trackee position
105     float         track_level;
106     fvec3_t       center;                 ///< Move character to side before tracking
107     float         zadd;                    ///< Camera height above terrain
108     float         zaddgoto;                ///< Desired z position
109     float         zgoto;
110     float         turn_z_rad;           ///< Camera rotations
111     float         turn_z_one;
112     float         turnadd;                 ///< Turning rate
113     float         sustain;                 ///< Turning rate falloff
114     float         turnupdown;
115     float         roll;
116     float         motion_blur;      ///< Blurry effect
117 
118     fvec3_t   vfw;                 ///< the camera forward vector
119     fvec3_t   vup;                 ///< the camera up vector
120     fvec3_t   vrt;                 ///< the camera right vector
121 };
122 
123 typedef struct s_camera camera_t;
124 
125 //--------------------------------------------------------------------------------------------
126 //--------------------------------------------------------------------------------------------
127 extern camera_t gCamera;
128 
129 //--------------------------------------------------------------------------------------------
130 //--------------------------------------------------------------------------------------------
131 // Function prototypes
132 
133 camera_t * camera_ctor( camera_t * pcam );
134 
135 void camera_reset( camera_t * pcam, struct s_ego_mpd * pmesh );
136 void camera_adjust_angle( camera_t * pcam, float height );
137 void camera_move( camera_t * pcam, struct s_ego_mpd * pmesh );
138 void camera_make_matrix( camera_t * pcam );
139 void camera_look_at( camera_t * pcam, float x, float y );
140 
141 bool_t camera_reset_target( camera_t * pcam, struct s_ego_mpd * pmesh );
142 void   camera_rotmesh__init();
143