wavelength 1.0.0
Loading...
Searching...
No Matches
rndcam.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <list>
5
6#include "math/frustum.h"
7#include "math/rect.h"
8#include "math/transform.h"
9#include "math/vector2.h"
10#include "os/mem.h"
11#include "rnd/rndcollideable.h"
12#include "rnd/rnddrawable.h"
13#include "rnd/rndtex.h"
15
23class RndCam : public RndDrawable, public RndTransformable, public RndCollideable {
24public:
32 explicit RndCam(const char *pszName);
33
40 ~RndCam() override;
41
48 void *operator new(size_t nSize) {
49 return PoolMemAlloc(static_cast<int>(nSize), "Cam", 0);
50 }
51
57 void operator delete(void *pBlock) {
58 PoolMemFree(pBlock);
59 }
60
69 static RndObject *New(const char *pszName) {
70 return new RndCam(pszName);
71 }
72
80 void ListDrawObjects(std::list<RndObject *> &objects) override;
81
89 void ListDrawables(std::list<RndDrawable *> &drawables) override;
90
98 int DrawShowing() override;
99
109 int UpdateWorldXfm(RndTransformable *pParent, int bForce) override;
110
112
122 void Collide(const Vector2 &point, std::list<Collision> &collisions) override;
123
133 void DumpText(PrnStream &stream) override;
134
142 void Save(BinStream &stream) override;
143
152 void Replace(RndObject *pFrom, RndObject *pTo) override;
153
161 const char *ClassName() const override {
162 return sClassName;
163 }
164
173 void Copy(const RndObject *pSource, int nFlags) override;
174
182 void Load(BinStream &stream) override;
183
195 void WorldToScreen(const Vector3 &world, Vector2 &screen) const;
196
204 void SetTargetTex(RndTex *pTex);
205
217 void SetFrustum(float fNear, float fFar, float fFov);
218
226
236
245 static void CreateDefault();
246
259 static float ConvertFov(float fFrom, float fTo, float fFov);
260
268
276
283 static const char *sClassName;
284
291 static int sRev;
292
294 float GetFarPlane() const {
295 return mFarPlane;
296 }
297
299 float GetFov() const {
300 return mFov;
301 }
302
304 const Transform &GetInvWorldXfm() const {
305 return mInvWorldXfm;
306 }
307
309 const Transform &GetLocalProject() const {
310 return mLocalProject;
311 }
312
314 float GetNearPlane() const {
315 return mNearPlane;
316 }
317
320 return mOrthoWorldXfm;
321 }
322
324 const Rect &GetScreenRect() const {
325 return mScreenRect;
326 }
327
329 void SetScreenRect(const Rect &rect) {
330 mScreenRect = rect;
331 }
332
335 return mTargetTex;
336 }
337
339 const Frustum &GetWorldFrustum() const {
340 return mWorldFrustum;
341 }
342
344 const Vector2 &GetZRange() const {
345 return mZRange;
346 }
347
349 void SetZRange(const Vector2 &range) {
350 mZRange = range;
351 }
352
353protected:
363
373
375
377
379
381
383
385
387
389
391
392 float mFarPlane;
393
394 float mFov;
395
397
399
401};
Stream of raw bytes, the base of the memory, file, and network streams.
Definition binstream.h:22
Six-plane view volume.
Definition frustum.h:16
Text output stream.
Definition prnstream.h:16
void SetFrustum(float fNear, float fFar, float fFov)
Set the view volume.
const Transform & GetInvWorldXfm() const
Definition rndcam.h:304
static RndObject * New(const char *pszName)
Create a camera.
Definition rndcam.h:69
~RndCam() override
Release the camera and stop drawing through it.
int DrawShowing() override
Make the camera current.
static int sRev
The format version Save() writes and Load() accepts.
Definition rndcam.h:291
RndCam(const char *pszName)
Construct a camera looking along y with a quarter-turn field of view, from 1 to 1000 units.
float GetFov() const
Definition rndcam.h:299
static float ConvertFov(float fFrom, float fTo, float fFov)
Report the field of view that covers the same extent at another aspect.
const Frustum & GetWorldFrustum() const
Definition rndcam.h:339
void DumpText(PrnStream &stream) override
Write a description of the camera and its bases.
Transform mInvWorldProject
Definition rndcam.h:384
RndTex * mTargetTex
Definition rndcam.h:400
static void CreateDefault()
Create the internal camera [default cam], 150 units back along y.
float mFarPlane
Definition rndcam.h:392
static const char * sClassName
The class name a .rnd file writes, Cam.
Definition rndcam.h:283
float GetNearPlane() const
Definition rndcam.h:314
void Save(BinStream &stream) override
Write the camera and its bases.
void SetTargetTex(RndTex *pTex)
Render into a texture rather than the display, or stop.
void Copy(const RndObject *pSource, int nFlags) override
Copy another camera and its bases.
void SetZRange(const Vector2 &range)
Definition rndcam.h:349
void Load(BinStream &stream) override
Read what Save() wrote, or an earlier version of it.
Transform mLocalProject
Definition rndcam.h:378
const Rect & GetScreenRect() const
Definition rndcam.h:324
Rect mScreenRect
Definition rndcam.h:398
Transform mOrthoWorldXfm
Definition rndcam.h:374
Vector2 mZRange
Definition rndcam.h:396
Frustum mWorldFrustum
Definition rndcam.h:388
void Replace(RndObject *pFrom, RndObject *pTo) override
Replace a referenced object with another.
Transform mInvWorldXfm
Definition rndcam.h:376
float mFov
Definition rndcam.h:394
const char * ClassName() const override
Report the class name.
Definition rndcam.h:161
static RndCam * sDefault
The internal camera CreateDefault() made.
Definition rndcam.h:275
Transform mInvLocalProject
Definition rndcam.h:380
RndTex * GetTargetTex() const
Definition rndcam.h:334
Frustum mLocalFrustum
Definition rndcam.h:386
void WorldToScreen(const Vector3 &world, Vector2 &screen) const
Project a world point to a screen point through mWorldProject and mScreenRect.
const Transform & GetLocalProject() const
Definition rndcam.h:309
void ListDrawObjects(std::list< RndObject * > &objects) override
Add the camera itself to a list.
void SetScreenRect(const Rect &rect)
Definition rndcam.h:329
float GetFarPlane() const
Definition rndcam.h:294
int UpdateWorldXfm(RndTransformable *pParent, int bForce) override
Recompute the world transform, and the world projection when it changed.
void UpdateProjection()
Rebuild the local projection and the local view volume, then the world projection.
void ListDrawables(std::list< RndDrawable * > &drawables) override
Make the camera current and add the drawables of the children to a list.
void UpdateWorldProject()
Rebuild the world projection and the world view volume from the world transform.
void AcquireTargetTex()
Take a reference on mTargetTex and rebuild the projection.
const Vector2 & GetZRange() const
Definition rndcam.h:344
void ReleaseTargetTex()
Drop the reference on mTargetTex.
Transform mWorldProject
Definition rndcam.h:382
float mNearPlane
Definition rndcam.h:390
void Collide(const Vector2 &point, std::list< Collision > &collisions) override
Record the camera as struck when a screen point falls inside mScreenRect, then test the children.
static RndCam * sCurrent
The camera drawing is set up for.
Definition rndcam.h:267
const Transform & GetOrthoWorldXfm() const
Definition rndcam.h:319
virtual void Collide(const Segment &segment, std::list< Collision > &collisions)
Test a segment against the collideable and add what it strikes to a list.
RndCollideable()
Construct a collideable without children.
Definition rndcollideable.h:34
RndDrawable()
Construct a showing drawable without a highlight or children.
Definition rnddrawable.h:23
RndObject(const char *pszName)
Construct an object and register it under a name.
Texture, a bitmap loaded from a file or rendered to.
Definition rndtex.h:17
RndTransformable()
Construct a transformable with identity transforms, no origin offset, and no billboard.
void * PoolMemAlloc(int nSize, const char *pszTag, int nAlign)
Allocate a block from the pool heaps and bill it to a tag.
void PoolMemFree(void *pBlock)
Return a block PoolMemAlloc() handed out to the pool heap that owns it.
Axis-aligned rectangle given by a corner and a size.
Definition rect.h:11
Affine transform stored as three basis rows and a translation row.
Definition transform.h:18
Two-component vector, used for texture coordinates.
Definition vector2.h:12
Three-component vector, padded to a PlayStation 2 quadword.
Definition vector3.h:14