载入中...
搜索中...
未找到
CameraController.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
6#include "common/Module.h"
7#include "common/Result.h"
9
10#include <glm/glm.hpp>
11
12#include <string>
13#include <cstdint>
14#include <deque>
15#include <vector>
16
17namespace eve::graphics {
18class Camera3D;
19}
20namespace eve::platform_event {
21class PlatformEvent;
22}
23namespace eve::scene {
24class SceneNodeRef;
25}
26
27namespace eve::camera {
28
34 std::string mode = "follow";
35 std::string activeRig;
36 float targetX = 0.f;
37 float targetY = 0.f;
38 float targetZ = 0.f;
39 float offsetX = 0.f;
40 float offsetY = 2.f;
41 float offsetZ = 6.f;
42 float lookAheadX = 0.f;
43 float lookAheadY = 0.f;
44 float lookAheadZ = 0.f;
45 float radius = 10.f;
46 float azimuth = 45.f;
47 float elevation = 30.f;
48 float yaw = 0.f;
49 float pitch = 0.f;
50 float fov = 60.f;
51 float smooth = 6.f;
52 float positionSmooth = 6.f;
53 float targetSmooth = 6.f;
54 float maxSpeed = 0.f;
55 float eyeX = 0.f;
56 float eyeY = 0.f;
57 float eyeZ = 0.f;
58 float lookX = 0.f;
59 float lookY = 0.f;
60 float lookZ = 0.f;
61 bool directorEnabled = false;
62 bool timelinePlaying = false;
63};
64
67 float postFxExposure = 13.5f;
68 int64_t postFxExposureMode = 0;
69 bool depthOfFieldActive = true;
71 float focusDistance = 100.f;
72 float aperture = 16.f;
73 float focalLength = 50.f;
74 int64_t kernelSize = 1;
75 int64_t savedFocusMode = 0;
76 int64_t focusModeHdrp = 0;
77 int64_t focusModeUrp = 0;
78 int64_t qualityHdrp = 1;
79 float nearBlurStart = 0.f;
80 float nearBlurEnd = 0.1f;
81 float farBlurStart = 200.f;
82 float farBlurEnd = 2000.f;
83 float blurStartUrp = 2.f;
84 float blurEndUrp = 1000.f;
85 float maximumBlurRadius = 1.f;
86 bool highQualityUrp = false;
87};
88
105public:
109 ~CameraController() override;
110
112 void setActionCuesEnabled(bool enabled);
114 [[nodiscard]] bool getActionCuesEnabled() const;
116 [[nodiscard]] bool supports(const LogicalId& cue) const noexcept override;
118 [[nodiscard]] Result<void> trigger(const action::ActionCameraCueBinding& binding,
119 const action::ActionNotifyContext& context) override;
120
121 // --- 绑定要驱动的摄像机 ---
123 void setCamera(graphics::Camera3D* cam);
125 graphics::Camera3D* getCamera() const;
126
127 // --- 目标 / 观察锚点 ---
129 void setTarget(float x, float y, float z);
131 void setTargetNode(scene::SceneNodeRef* node);
133 float getTargetX() const;
135 float getTargetY() const;
137 float getTargetZ() const;
139 void setOffset(float x, float y, float z);
141 void setLookAhead(float x, float y, float z);
146 void setSecondaryTarget(float x, float y, float z);
148 void clearSecondaryTarget();
150 [[nodiscard]] bool hasSecondaryTarget() const noexcept { return hasSecondaryTarget_; }
151 float getSecondaryTargetX() const;
153 float getSecondaryTargetY() const;
155 float getSecondaryTargetZ() const;
156
157 // --- 视角模式 ---
159 void setMode(const std::string& mode);
161 std::string getMode() const;
162
163 // --- orbit / topdown / ortho 参数 ---
165 void setRadius(float r); // orbit 半径 / topdown·ortho 高度
float getRadius() const { return radius_; }
168 [[nodiscard]] Result<void> setRadiusLimits(float minimum, float maximum);
float getMinimumRadius() const { return minimumRadius_; } float getMaximumRadius() const { return maximumRadius_; }
172 void setAzimuth(float deg); // orbit 方位角
174 void setElevation(float deg); // orbit 仰角
176 void setOrbitSpeed(float degPerSec); // 自动盘旋转速
181 void setOrthoHeight(float height);
183 float getOrthoHeight() const { return orthoHeight_; }
184
185 // --- firstperson 参数 ---
187 void setYaw(float deg);
189 void setPitch(float deg);
191 void addInput(float yawDeltaDeg, float pitchDeltaDeg, float zoomDelta);
192
194 void setPhotoModeAuthority(bool enabled);
196 bool getPhotoModeAuthority() const noexcept{return photoModeAuthority_;}
198 PhotoModeFieldAcceptance acceptsPhotoModeField(const PhotoModeAssignment& assignment) const noexcept override;
200 [[nodiscard]] Result<void> applyPhotoModeField(const PhotoModeAssignment& assignment) override;
202 [[nodiscard]] Result<void> setCameraRoll(float degrees);
204 float getCameraRoll() const noexcept{return cameraRollDeg_;}
206 float getPcgCullingDistance() const noexcept{return pcgCullingDistance_;}
208 const PcgPhotoModePostFxState& getPcgPostFxState() const noexcept{return pcgPostFxState_;}
209 // --- framing / lens ---
211 void setComposition(float screenX, float screenY);
213 void setDeadZone(float radius);
215 void setFov(float degrees);
217 float getFov() const;
218
219 // --- 平滑 ---
221 void setSmooth(float damping); // 每秒指数阻尼,越大越跟手
223 void setPositionSmooth(float damping);
225 void setTargetSmooth(float damping);
227 void setMaxSpeed(float unitsPerSec); // 0 = 不限速
229 void snap(); // 立即应用当前目标视角
230
231 // --- obstruction / collision ---
233 void setCollisionEnabled(bool enabled);
235 void setCollisionRadius(float radius);
237 void setCollisionRecovery(float damping);
239 void setCollisionMask(uint64_t maskBits);
241 void setCollisionIgnoredBody(int bodyId);
243 void clearCollisionBoxes();
245 void addCollisionBox(float minX, float minY, float minZ, float maxX, float maxY, float maxZ);
247 bool isObstructed() const;
249 int getCollisionBodyId() const;
250
251 // --- camera rigs / director ---
253 bool addRig(const std::string& name, const std::string& mode, int priority);
255 bool removeRig(const std::string& name);
257 bool setRigPriority(const std::string& name, int priority);
259 bool setRigEnabled(const std::string& name, bool enabled);
261 bool saveRigState(const std::string& name);
263 bool activateRig(const std::string& name, float blendTime);
265 std::string getActiveRig() const;
266
267 // --- additive modifiers ---
269 void addImpulse(float positionAmplitude, float rotationAmplitude, float duration, unsigned int seed = 0);
271 void addFovImpulse(float degrees, float duration);
273 void clearImpulses();
274
275 // --- cinematic / 自动切换视角 ---
277 void addView(const std::string& name, float ex, float ey, float ez, float tx, float ty, float tz);
282 [[nodiscard]] Result<void> setView(const std::string& name, float ex, float ey, float ez, float tx, float ty,
283 float tz, float fov);
285 bool switchTo(const std::string& name, float blendTime);
287 void playSequence(float stepTime); // 每隔 stepTime 秒切换到下一个 View
289 void stopSequence();
291 bool isPlaying() const;
292
297 [[nodiscard]] CameraFramingSnapshot captureFraming() const;
302 [[nodiscard]] Result<void> restoreFraming(const CameraFramingSnapshot& snapshot, float blendTime);
304 void setDirectorEnabled(bool enabled);
306 [[nodiscard]] bool getDirectorEnabled() const noexcept { return directorEnabled_; }
307
308 // --- timeline / events ---
310 void clearTimeline();
312 bool addTimelineCut(float time, const std::string& rigName, float blendTime);
314 bool addTimelineEvent(float time, const std::string& name, const std::string& data);
316 bool addTimelineFloat(float time, const std::string& property, float value);
318 void setEventSink(platform_event::PlatformEvent* sink);
320 void playTimeline(bool loop);
322 void pauseTimeline();
324 void stopTimeline();
326 void seekTimeline(float time, bool fireEvents = false);
328 bool isTimelinePlaying() const;
330 float getTimelineTime() const;
332 std::string consumeTimelineEvent();
334 std::string getTimelineEventData() const;
336 int getPendingTimelineEventCount() const;
338 float getTimelineDuration() const;
340 int getRigCount() const;
342 std::string serializeAsset() const;
344 bool deserializeAsset(const std::string& json);
345
346 // --- 每帧驱动 ---
348 void update(float dt);
349
350private:
351 struct View {
352 std::string name;
353 glm::vec3 eye{0.f};
354 glm::vec3 target{0.f};
355 float fov = 60.f;
356 };
357
358 struct Rig {
359 std::string name;
360 std::string mode;
361 int priority = 0;
362 bool enabled = true;
363 glm::vec3 target{0.f};
364 glm::vec3 offset{0.f, 2.f, 6.f};
365 glm::vec3 lookAhead{0.f};
366 glm::vec2 composition{0.f};
367 float radius = 10.f;
368 float azimuth = 45.f;
369 float elevation = 30.f;
370 float yaw = 0.f;
371 float pitch = 0.f;
372 float fov = 60.f;
373 float smooth = 6.f;
374 float maxSpeed = 0.f;
375 };
376
377 struct CollisionBox {
378 glm::vec3 min{0.f};
379 glm::vec3 max{0.f};
380 };
381 struct Impulse {
382 float positionAmplitude = 0.f;
383 float rotationAmplitude = 0.f;
384 float duration = 0.f;
385 float age = 0.f;
386 unsigned int seed = 0;
387 float fovAmplitude = 0.f;
388 };
389 struct TimelineCut {
390 float time = 0.f;
391 std::string rig;
392 float blend = 0.f;
393 bool fired = false;
394 };
395 struct TimelineEvent {
396 float time = 0.f;
397 std::string name;
398 std::string data;
399 bool fired = false;
400 };
401 struct TimelineFloat {
402 float time = 0.f;
403 std::string property;
404 float value = 0.f;
405 };
406
407 View desired() const;
408 void applyView(const View& v);
409 void easeToward(const View& v, float dt);
410 void updateTrackedTarget();
411 void updateDirector();
412 void applyCollision(View& v, float dt);
413 void applyModifiers(View& v, float dt);
414 void updateTimeline(float dt);
415 void evaluateTimelineFloats();
416 void emitTimelineEvent(const TimelineEvent& marker);
417 static bool validMode(const std::string& mode);
418 [[nodiscard]] Result<void> applyPcgPostFx(const PhotoModeAssignment& assignment);
419 void projectPcgPostFx();
420
421 graphics::Camera3D* cam_ = nullptr;
422 bool photoModeAuthority_ = false;
423 float cameraRollDeg_ = 0.f;
424 float pcgCullingDistance_ = 0.f;
425 PcgPhotoModePostFxState pcgPostFxState_{};
426
427 std::string mode_ = "follow";
428
429 glm::vec3 target_{0.f, 0.f, 0.f};
430 std::string targetNodeHost_;
431 std::string targetNodeId_;
432 glm::vec3 offset_{0.f, 2.f, 6.f};
433 glm::vec3 lookAhead_{0.f, 0.f, 0.f};
434 glm::vec3 secondaryTarget_{0.f};
435 bool hasSecondaryTarget_ = false;
436
437 float radius_ = 10.f;
438 float minimumRadius_ = 0.01f;
439 float maximumRadius_ = 100000.f;
440 float orthoHeight_ = 20.f;
441 float azimuthDeg_ = 45.f;
442 float elevationDeg_ = 30.f;
443 float orbitSpeedDeg_ = 20.f;
444
445 float yawDeg_ = 0.f;
446 float pitchDeg_ = 0.f;
447 glm::vec2 composition_{0.f};
448 float deadZone_ = 0.f;
449 glm::vec3 deadZoneTarget_{0.f};
450 bool deadZoneInitialized_ = false;
451 float fovDeg_ = 60.f;
452
453 float smooth_ = 6.f;
454 float positionSmooth_ = 6.f;
455 float targetSmooth_ = 6.f;
456 float maxSpeed_ = 0.f;
457 bool initialized_ = false;
458 View cur_{};
459
460 bool collisionEnabled_ = false;
461 float collisionRadius_ = 0.25f;
462 float collisionRecovery_ = 4.f;
463 float collisionDistance_ = -1.f;
464 bool obstructed_ = false;
465 uint64_t collisionMask_ = UINT64_MAX;
466 int collisionIgnoredBody_ = -1;
467 int collisionBodyId_ = -1;
468 std::vector<CollisionBox> collisionBoxes_;
469
470 std::vector<Rig> rigs_;
471 std::string activeRig_;
472 bool directorEnabled_ = false;
473 std::vector<Impulse> impulses_;
474
475 // cinematic
476 std::vector<View> views_;
477 int viewIndex_ = -1;
478 bool playing_ = false;
479 float stepTime_ = 3.f;
480 float timer_ = 0.f;
481 bool blending_ = false;
482 View blendFrom_{};
483 View blendTo_{};
484 float blendT_ = 0.f;
485 float blendDur_ = 1.f;
486
487 std::vector<TimelineCut> timelineCuts_;
488 std::vector<TimelineEvent> timelineEvents_;
489 std::vector<TimelineFloat> timelineFloats_;
490 platform_event::PlatformEvent* eventSink_ = nullptr;
491 float timelineTime_ = 0.f;
492 float timelineDuration_ = 0.f;
493 bool timelinePlaying_ = false;
494 bool timelineLoop_ = false;
495 std::deque<std::pair<std::string, std::string>> pendingTimelineEvents_;
496 std::string consumedTimelineEventData_;
497};
498
502class Camera : public Module {
503public:
506 Camera() = default;
508 ~Camera() override = default;
509};
510
511} // namespace eve::camera
Typed camera-cue action block contract.
double z
double y
double x
LogicalId target
float duration
float yaw
Definition BushMesh.cpp:37
int priority
float degrees
Definition CardTypes.cpp:38
std::string name
Definition ECS.cpp:154
#define EVENGINE_API_WORLD
Definition Export.h:109
float maximum[3]
float minimum[3]
double r
float v
float elevation
float blend
std::uint32_t height
size_t offset
double radius
Definition MeleeHit.cpp:42
double dt
eve::action::ActionVfxBinding binding
Object::Ptr value
glm::vec3 eye
Move-only, checked operation results for the common layer.
const RoadNode * node
uint32_t seed
Definition TreeMesh.cpp:276
const VegetationPresetContext & context
IPhotoModeFieldSink public API.
Human-readable, scoped identifier in the form namespace:name.
Definition Identity.h:414
EVENGINE_API_FOUNDATION public API.
Definition Module.h:48
Move-only operation result carrying either a value or Status.
Definition Result.h:176
Optional open target for instantaneous action camera cues.
3D 摄像机控制器(eve.Camera / eve.CameraController)。
bool hasSecondaryTarget() const noexcept
Return whether a lock-on look target is currently stored.
CameraController()
Camera controller.
bool getDirectorEnabled() const noexcept
Return whether the priority-rig director is selecting rigs.
const PcgPhotoModePostFxState & getPcgPostFxState() const noexcept
Return the complete retained Pcg post-processing state.
float getPcgCullingDistance() const noexcept
Return Pcg's signed culling-distance adjustment.
float getCameraRoll() const noexcept
Return current camera roll in degrees.
bool getPhotoModeAuthority() const noexcept
Return whether this controller currently publishes photo-mode camera fields.
float getOrthoHeight() const
Return the orthographic height used by mode "ortho".
摄像机模块命名空间(eve.Camera)。主要职责是把 CameraController 绑定进脚本。
Camera()=default
Constructs a Camera.
~Camera() override=default
Releases Camera resources.
EVENGINE_API_BACKENDS public API.
EVENGINE_API_FOUNDATION public API.
Script handle to a scene node (hostName + nodeId). Deliberately holds strings rather than arena point...
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition Animation.h:25
PhotoModeFieldAcceptance
Capability implemented by the composition root that routes assignments to domain owners.
bool enabled
One reversible field assignment in a photo-mode transaction.
Owning validated camera impulse shared by action runtime and camera targets.
Context linking a routed event to its action execution.
Serializable gameplay camera framing for story push/pop restore.
Complete Pcg photo-mode post-processing state retained across render-pipeline projections.