wavelength 1.0.0
Loading...
Searching...
No Matches
rndline.h
Go to the documentation of this file.
1#pragma once
2
3#include <list>
4#include <memory>
5#include <vector>
6
7#include "math/color.h"
8#include "math/plane.h"
9#include "math/vector2.h"
10#include "math/vector3.h"
11#include "os/binstream.h"
12#include "os/prnstream.h"
13#include "rnd/rndcollideable.h"
14#include "rnd/rnddrawable.h"
15#include "rnd/rndmat.h"
16#include "rnd/rndmesh.h"
18
26class RndLine : public RndDrawable, public RndTransformable, public RndCollideable {
27public:
33 class Point {
34 public:
37 mPoint.x = 0.0f;
38 mPoint.y = 0.0f;
39 mPoint.z = 0.0f;
40 mColor.r = 1.0f;
41 mColor.a = 1.0f;
42 mColor.g = 1.0f;
43 mColor.b = 1.0f;
44 }
45
47 const Vector3 &GetCamPoint() const {
48 return mCamPoint;
49 }
50
53 return mCamPoint;
54 }
55
57 void SetCamPoint(const Vector3 &point) {
58 mCamPoint = point;
59 }
60
62 const Color &GetColor() const {
63 return mColor;
64 }
65
68 return mColor;
69 }
70
72 void SetColor(const Color &color) {
73 mColor = color;
74 }
75
77 const Vector2 &GetDir() const {
78 return mDir;
79 }
80
83 return mDir;
84 }
85
87 void SetDir(const Vector2 &dir) {
88 mDir = dir;
89 }
90
92 const Vector2 &GetOffset() const {
93 return mOffset;
94 }
95
98 return mOffset;
99 }
100
102 void SetOffset(const Vector2 &offset) {
103 mOffset = offset;
104 }
105
107 const Vector3 &GetPoint() const {
108 return mPoint;
109 }
110
113 return mPoint;
114 }
115
117 void SetPoint(const Vector3 &point) {
118 mPoint = point;
119 }
120
122 const Vector2 &GetScreen() const {
123 return mScreen;
124 }
125
128 return mScreen;
129 }
130
131 private:
132 Vector3 mPoint;
133 Color mColor;
134 Vector3 mCamPoint;
135 Vector2 mScreen;
136 Vector2 mDir;
137 Vector2 mOffset;
138 };
139
149
157 explicit RndLine(const char *pszName);
158
165 ~RndLine() override;
166
176 void ListDrawObjects(std::list<RndObject *> &objects) override;
177
185 void ListDrawables(std::list<RndDrawable *> &drawables) override;
186
196 void SetHighlight(int nHighlight) override;
197
208 int DrawShowing() override;
209
211
223 void Collide(const Segment &segment, std::list<Collision> &collisions) override;
224
232 void DumpText(PrnStream &stream) override;
233
241 void Save(BinStream &stream) override;
242
251 void Replace(RndObject *pFrom, RndObject *pTo) override;
252
260 const char *ClassName() const override {
261 return sClassName;
262 }
263
272 void Copy(const RndObject *pSource, int nFlags) override;
273
281 void Load(BinStream &stream) override;
282
290 RndMat *Mat() const;
291
299 void SetMat(RndMat *pMat);
300
310 void SetFoldAngle(float fAngle);
311
320 void SetNumPoints(int nPoints);
321
330 void SetPoint(int nIndex, const Vector3 &point);
331
342 void SetPointColor(int nIndex, const Color &color);
343
354 void FindPointVerts(int nIndex, PointVerts &verts);
355
365
374 void BuildMesh();
375
387 void BuildStrip(Point *pFirst, Point *pLast);
388
400 void BuildPair(Point *pFirst, Point *pSecond);
401
410 static RndObject *New(const char *pszName) {
411 return new RndLine(pszName);
412 }
413
420 static const char *sClassName;
421
427 static int sRev;
428
430 const std::vector<Point> &GetPoints() const {
431 return mPoints;
432 }
433
435 float GetWidth() const {
436 return mWidth;
437 }
438
440 void SetWidth(float fWidth) {
441 mWidth = fWidth;
442 }
443
444private:
445 RndMat *mMat;
446 float mWidth;
447 std::vector<Point> mPoints;
448 std::unique_ptr<RndMesh> mMesh;
449 int mHasCaps;
450 int mLinePairs;
451 float mFoldAngle;
452 float mFoldCos;
453};
454
465
476
Stream of raw bytes, the base of the memory, file, and network streams.
Definition binstream.h:22
Text output stream.
Definition prnstream.h:16
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
One point and what drawing derives from it.
Definition rndline.h:33
Vector2 & GetDir()
Definition rndline.h:82
const Vector2 & GetOffset() const
Definition rndline.h:92
const Vector3 & GetPoint() const
Definition rndline.h:107
void SetDir(const Vector2 &dir)
Definition rndline.h:87
const Vector3 & GetCamPoint() const
Definition rndline.h:47
Vector3 & GetPoint()
Definition rndline.h:112
Vector2 & GetScreen()
Definition rndline.h:127
const Vector2 & GetScreen() const
Definition rndline.h:122
Vector2 & GetOffset()
Definition rndline.h:97
const Color & GetColor() const
Definition rndline.h:62
void SetCamPoint(const Vector3 &point)
Definition rndline.h:57
void SetPoint(const Vector3 &point)
Definition rndline.h:117
Point()
Construct a white point at the origin.
Definition rndline.h:36
void SetColor(const Color &color)
Definition rndline.h:72
const Vector2 & GetDir() const
Definition rndline.h:77
void SetOffset(const Vector2 &offset)
Definition rndline.h:102
Color & GetColor()
Definition rndline.h:67
Vector3 & GetCamPoint()
Definition rndline.h:52
int DrawShowing() override
Build the ribbon facing the current camera and draw it.
static RndObject * New(const char *pszName)
Create a line.
Definition rndline.h:410
float GetWidth() const
Definition rndline.h:435
~RndLine() override
Delete the mesh.
const char * ClassName() const override
Report the class name.
Definition rndline.h:260
void ListDrawables(std::list< RndDrawable * > &drawables) override
Add the line, when its mesh has something to draw, then the children, to a list.
void BuildMesh()
Create the mesh for the points.
void BuildStrip(Point *pFirst, Point *pLast)
Fill the mesh positions with a ribbon through a run of points, extending the clipped points outside t...
const std::vector< Point > & GetPoints() const
Definition rndline.h:430
RndLine(const char *pszName)
Construct a white, unit-width line without points, with caps and a fold at a quarter turn.
void FindPointVerts(int nIndex, PointVerts &verts)
Find the mesh vertices of a point.
void SetPoint(int nIndex, const Vector3 &point)
Set the position of a point.
void SetHighlight(int nHighlight) override
Set the highlight of the mesh.
static const char * sClassName
The class name a .rnd file writes, Line.
Definition rndline.h:420
void Copy(const RndObject *pSource, int nFlags) override
Copy another line and its bases, then rebuild the mesh.
void Load(BinStream &stream) override
Read what Save() wrote, or an earlier version of it, then rebuild the mesh.
static int sRev
The format version Save() writes and Load() accepts.
Definition rndline.h:427
void Save(BinStream &stream) override
Write the line and its bases.
void ReleaseMesh()
Delete the mesh.
void DumpText(PrnStream &stream) override
Write a description of the line and its bases.
void BuildPair(Point *pFirst, Point *pSecond)
Fill the mesh positions with one segment of a line of pairs, or collapse it when both points are the ...
void SetFoldAngle(float fAngle)
Set the angle between segments at and beyond which the ribbon folds over.
void Collide(const Segment &segment, std::list< Collision > &collisions) override
Add each face of the mesh the segment strikes, as strikes of the line, then what the children strike,...
void SetPointColor(int nIndex, const Color &color)
Set the colour of a point and of its mesh vertices.
void ListDrawObjects(std::list< RndObject * > &objects) override
Add the material of the mesh to a list.
void SetWidth(float fWidth)
Definition rndline.h:440
void SetMat(RndMat *pMat)
Set the material of the mesh.
void Replace(RndObject *pFrom, RndObject *pTo) override
Replace a referenced object with another in the bases.
void SetNumPoints(int nPoints)
Set the number of points, then size the mesh, its texture coordinates, colours, and faces to match.
RndMat * Mat() const
Report the material of the mesh.
Surface description: blending, lighting colours, culling, and a list of texture stages.
Definition rndmat.h:20
One vertex.
Definition rndmesh.h:78
RndObject(const char *pszName)
Construct an object and register it under a name.
RndTransformable()
Construct a transformable with identity transforms, no origin offset, and no billboard.
BinStream & operator>>(BinStream &stream, RndLine::Point &point)
Read a point the point writer wrote.
PrnStream & operator<<(PrnStream &stream, const RndLine::Point &point)
Write a point's position and colour.
Linear colour with four float components.
Definition color.h:12
The mesh vertices of a point.
Definition rndline.h:145
RndMesh::Vert * mVerts
Definition rndline.h:147
int mCaps
Definition rndline.h:146
Two points that fix a line or a segment.
Definition plane.h:39
Two-component vector, used for texture coordinates.
Definition vector2.h:12
Three-component vector, padded to a PlayStation 2 quadword.
Definition vector3.h:14