Skyscraper 2.0
camera.h
Go to the documentation of this file.
1/*
2 Scalable Building Simulator - Camera Object
3 The Skyscraper Project - Version 2.0
4 Copyright (C)2004-2024 Ryan Thoryk
5 https://www.skyscrapersim.net
6 https://sourceforge.net/projects/skyscraper/
7 Contact - ryan@skyscrapersim.net
8
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22*/
23
24#ifndef _SBS_CAMERA_H
25#define _SBS_CAMERA_H
26
27namespace SBS {
28
45
46class SBSIMPEXP Camera : public Object
47{
48public:
49 int CurrentFloor; //floor camera's on
50 std::string CurrentFloorID; //indicator ID of camera's current floor
51 int StartFloor; //Starting floor
52 Real StartPositionX; //starting position on X axis
53 Real StartPositionZ; //starting position on Z axis
54 Real cfg_jumpspeed; //Initial speed of jumping.
55 Real cfg_walk_accelerate; //walk acceleration
56 Real cfg_walk_maxspeed; //walk maximum speed
57 Real cfg_walk_maxspeed_mult; //multiplier for max speed
58 Real cfg_walk_maxspeed_multreal; //is multiplier used?
59 Real cfg_walk_brake; //walk brake deceleration
60 Real cfg_rotate_accelerate; //rotate acceleration
61 Real cfg_rotate_maxspeed; //rotate maximum speed
62 Real cfg_rotate_brake; //rotate brake deceleration
63 Real cfg_body_height; //body height
64 Real cfg_body_width; //body width
65 Real cfg_legs_height; //legs height
66 Real cfg_legs_width; //legs width
67 Real cfg_lookspeed; //base look speed
68 Real cfg_turnspeed; //base turn speed
69 Real cfg_spinspeed; //base spin speed
70 Real cfg_floatspeed; //base float speed
71 Real cfg_stepspeed; //base step speed
72 Real cfg_strafespeed; //base strafe speed
73 Real cfg_speed; //camera speed multiplier
74 Real cfg_speedfast; //camera fast speed multiplier
75 Real cfg_speedslow; //camera slow speed multiplier
76 Real cfg_zoomspeed; //camera zoom speed
81 Real speed; //movement speed base
82 bool MouseLeftDown; //mouse left button status
83 bool MouseRightDown; //mouse right button status
84 bool ReportCollisions; //if true, print collisions on console
85 std::string LastHitMesh; //name of last hit mesh
86 int LastHitMeshNumber; //object number of last hit mesh
87 bool Freelook; //freelook (mouselook) is enabled/disabled
88 Real Freelook_speed; //freelook speed
89 Vector3 HitPosition; //last hit position
91 Real BinocularsFOV; //binoculars mode FOV
94 bool inside_vehicle; //is user inside a vehicle?
95 Vehicle *vehicle; //vehicle object, if user is inside
96
97 //mouse coordinates
98 int mouse_x, mouse_y;
99
100 //functions
101 Camera(Object *parent);
102 ~Camera();
103 void SetPosition(const Vector3 &position);
104 void SetDirection(const Vector3 &direction);
105 void SetRotation(const Vector3 &rotation);
106 Vector3 GetPosition(bool relative = false);
107 void GetDirection(Vector3 &front, Vector3 &top, bool global = false);
108 Vector3 GetRotation();
109 void UpdateCameraFloor();
110 bool Move(Vector3 vector, Real speed = 1.0, bool flip = true);
111 bool MovePosition(Vector3 vector, Real speed = 1.0);
112 void Rotate(const Vector3 &position, Real speed = 1.0);
113 void RotateLocal(const Vector3 &position, Real speed = 1.0);
114 void SetStartDirection(const Vector3 &direction);
115 Vector3 GetStartDirection();
116 void SetStartRotation(const Vector3 &rotation);
117 Vector3 GetStartRotation();
118 void SetToStartPosition(bool disable_current_floor);
119 void SetToStartDirection();
120 void SetToStartRotation();
121 void CheckElevator();
122 void CheckShaft();
123 void CheckStairwell();
124 Real ClickedObject(Camera *camera, bool shift, bool ctrl, bool alt, bool right, Real scale, bool center_only = false, bool hit_only = false);
125 void UnclickedObject();
126 Object* GetMeshParent(Object *object);
127 std::string GetClickedMeshName();
128 std::string GetClickedWallName();
129 int GetClickedObjectNumber();
130 int GetClickedObjectLine();
131 std::string GetClickedObjectCommand();
132 std::string GetClickedObjectCommandP();
133 void Loop();
134 void Strafe(Real speed = 1.0);
135 void Step(Real speed = 1.0);
136 void Float(Real speed = 1.0);
137 void Jump();
138 void Look(Real speed = 1.0);
139 void Turn(Real speed = 1.0);
140 void Spin(Real speed = 1.0);
141 void InterpolateMovement(Real delta);
142 void SetGravity(Real gravity, bool save_value = true, bool camera_only = true);
143 Real GetGravity();
144 void EnableGravity(bool value);
145 bool GetGravityStatus();
146 void SetFOVAngle(Real angle);
147 Real GetFOVAngle();
148 void SetToDefaultFOV();
149 Real GetHeight();
150 void SetViewMode(int mode);
151 void EnableCollisions(bool value);
152 bool CollisionsEnabled();
153 bool IsOnGround();
154 void Sync();
155 void SetMaxRenderDistance(Real value);
156 Real GetMaxRenderDistance();
157 void ShowDebugShape(bool value);
158 void MoveCharacter();
159 void ResetCollisions();
160 void GotoFloor(int floor, bool disable_current = true);
161 void Binoculars(bool value);
162 bool IsMeshVisible(MeshObject *mesh);
163 bool IsDynamicMeshVisible(DynamicMesh *mesh, int mesh_index);
164 void AttachModel(Model *model);
165 void DetachModel();
166 bool PickUpModel();
167 void DropModel();
168 bool IsModelAttached();
169 void ResetState();
170 void ResetView();
171 bool IsActive() { return (!Cameras.empty()); }
172 void Refresh();
173 bool Attach(std::vector<Ogre::Camera*> &cameras, bool init_state = true);
174 bool Detach();
175 void OnMove(bool parent);
176 void OnRotate(bool parent);
177 CameraState GetCameraState();
178 void SetCameraState(const CameraState &state, bool set_floor = true);
179 void RevertMovement();
180 void FreelookMove(const Vector3 &rotation);
181 bool MouseDown();
182 void CheckObjects();
183 void Teleport(Real X, Real Y, Real Z);
184 void Drive(bool left, bool right, bool down, bool up, bool key_down);
185 void Crouch(bool value);
186 void SetOrientation(const Quaternion &orientation);
187 void AttachToVehicle(bool value);
188 Ogre::Camera* GetOgreCamera(int index = 0);
189
190private:
191 std::vector<Ogre::Camera*> Cameras; //camera instances
192 Vector3 StartDirection; //direction camera faces on start
193 Vector3 StartRotation; //camera's startup rotation
194 std::string meshname; //last clicked mesh name
195 std::string wallname; //last clicked wall name
196 int object_number; //last clicked object number
197 int object_line; //script line number of last clicked object
198 std::string object_cmd; //original script command of last clicked object
199 std::string object_cmd_processed; //processed script command of last clicked object
200 int FloorTemp; //previous floor check value
205 Real FOV; //default FOV angle
208 bool Collisions; //collision detection status
218 bool BinocularsState; //binoculars enabled status
219
220 //Models
222
223 //collision/physics
224 OgreBulletDynamics::CharacterController* mCharacter;
225 OgreBulletCollisions::CollisionShape* mShape;
226
227 //used for restoring values when exiting vehicle
231};
232
233}
234
235#endif
std::string object_cmd_processed
Definition camera.h:199
Real cfg_walk_brake
Definition camera.h:59
Real FOV
Definition camera.h:205
Vector3 StartRotation
Definition camera.h:193
Real cfg_walk_maxspeed_mult
Definition camera.h:57
bool RotationStopped
Definition camera.h:209
std::string CurrentFloorID
Definition camera.h:50
Vector3 prev_accum_movement
Definition camera.h:213
Real Freelook_speed
Definition camera.h:88
Vector3 Rotation
Definition camera.h:207
Model * AttachedModel
Definition camera.h:221
bool BinocularsState
Definition camera.h:218
Quaternion old_character_orientation
Definition camera.h:229
Real cfg_body_height
Definition camera.h:63
int object_line
Definition camera.h:197
Real cfg_rotate_maxspeed
Definition camera.h:61
Real BinocularsFOV
Definition camera.h:91
bool Collisions
Definition camera.h:208
bool IsActive()
Definition camera.h:171
Real last_fov
Definition camera.h:206
OgreBulletCollisions::CollisionShape * mShape
Definition camera.h:225
int LastHitMeshNumber
Definition camera.h:86
Vector3 HitPosition
Definition camera.h:89
Real cfg_legs_width
Definition camera.h:66
std::vector< Ogre::Camera * > Cameras
Definition camera.h:191
Real FarClip
Definition camera.h:211
Real cfg_legs_height
Definition camera.h:65
std::string LastHitMesh
Definition camera.h:85
Real cfg_walk_accelerate
Definition camera.h:55
Real cfg_walk_maxspeed
Definition camera.h:56
Real cfg_rotate_accelerate
Definition camera.h:60
Real cfg_jumpspeed
Definition camera.h:54
Vector3 prev_position
Definition camera.h:217
bool inside_vehicle
Definition camera.h:94
Real cfg_lookspeed
Definition camera.h:67
std::string meshname
Definition camera.h:194
int mouse_x
Definition camera.h:98
int CurrentFloor
Definition camera.h:49
bool Freelook
Definition camera.h:87
bool MovementStopped
Definition camera.h:210
Real cfg_rotate_brake
Definition camera.h:62
Quaternion prev_orientation
Definition camera.h:216
std::string object_cmd
Definition camera.h:198
Real cfg_zoomspeed
Definition camera.h:76
Real StartPositionX
Definition camera.h:52
bool old_freelook_mode
Definition camera.h:230
bool MouseLeftDown
Definition camera.h:82
Real Gravity
Definition camera.h:201
Real cfg_spinspeed
Definition camera.h:69
Real cfg_strafespeed
Definition camera.h:72
Vehicle * vehicle
Definition camera.h:95
Real cfg_speedfast
Definition camera.h:74
std::string wallname
Definition camera.h:195
bool collision_reset
Definition camera.h:214
Real cfg_stepspeed
Definition camera.h:71
Vector3 angle_velocity
Definition camera.h:80
Real cfg_floatspeed
Definition camera.h:70
bool EnableBullet
Definition camera.h:90
bool FirstAttach
Definition camera.h:93
Vector3 desired_velocity
Definition camera.h:77
int object_number
Definition camera.h:196
OgreBulletDynamics::CharacterController * mCharacter
Definition camera.h:224
bool lastfloorset
Definition camera.h:204
Real cfg_speed
Definition camera.h:73
int lastfloor
Definition camera.h:203
Real StartPositionZ
Definition camera.h:53
bool GravityStatus
Definition camera.h:202
Real speed
Definition camera.h:81
Real cfg_speedslow
Definition camera.h:75
bool ReportCollisions
Definition camera.h:84
Real cfg_body_width
Definition camera.h:64
Vector3 desired_angle_velocity
Definition camera.h:79
bool use_startdirection
Definition camera.h:215
Vector3 velocity
Definition camera.h:78
Vector3 accum_movement
Definition camera.h:212
Vector3 StartDirection
Definition camera.h:192
int StartFloor
Definition camera.h:51
bool RestrictRotation
Definition camera.h:92
Real cfg_walk_maxspeed_multreal
Definition camera.h:58
Real cfg_turnspeed
Definition camera.h:68
Quaternion old_camera_orientation
Definition camera.h:228
bool MouseRightDown
Definition camera.h:83
int FloorTemp
Definition camera.h:200
Ogre::Vector3 Vector3
Definition globals.h:58
Ogre::Real Real
Definition globals.h:57
#define SBSIMPEXP
Definition globals.h:53
Ogre::Quaternion Quaternion
Definition globals.h:60
Vector3 velocity
Definition camera.h:38
Vector3 desired_velocity
Definition camera.h:37
bool collisions
Definition camera.h:34
Vector3 position
Definition camera.h:31
Vector3 angle_velocity
Definition camera.h:40
Vector3 accum_movement
Definition camera.h:41
Vector3 desired_angle_velocity
Definition camera.h:39
Vector3 rotation
Definition camera.h:32