Skip to content

Commit 35f9c8e

Browse files
committed
Removed float* operator from math classes.
1 parent 6a26e60 commit 35f9c8e

File tree

8 files changed

+85
-80
lines changed

8 files changed

+85
-80
lines changed

common/lc_application.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -604,15 +604,15 @@ lcCommandLineOptions lcApplication::ParseCommandLineOptions()
604604
}
605605
else if (Option == QLatin1String("--camera-angles"))
606606
{
607-
if ((Options.SetCameraAngles = ParseFloatArray(2, (float*)Options.CameraLatLon, true)) && (fabsf(Options.CameraLatLon[0]) > 360.0f || fabsf(Options.CameraLatLon[1]) > 360.0f))
607+
if ((Options.SetCameraAngles = ParseFloatArray(2, Options.CameraLatLon.GetFloats(), true)) && (fabsf(Options.CameraLatLon[0]) > 360.0f || fabsf(Options.CameraLatLon[1]) > 360.0f))
608608
{
609609
Options.StdErr += tr("Invalid parameter value(s) specified for the '%1' option: limits are +/- 360.\n").arg(Option);
610610
Options.ParseOK = false;
611611
}
612612
}
613613
else if (Option == QLatin1String("--camera-position") || Option == QLatin1String("--camera-position-ldraw"))
614614
{
615-
if ((Options.SetCameraPosition = ParseFloatArray(9, (float*)Options.CameraPosition[0], true)))
615+
if ((Options.SetCameraPosition = ParseFloatArray(9, Options.CameraPosition[0].GetFloats(), true)))
616616
{
617617
if (Option == QLatin1String("--camera-position-ldraw"))
618618
{
@@ -646,7 +646,7 @@ lcCommandLineOptions lcApplication::ParseCommandLineOptions()
646646
Options.SetFoV = ParseFloat(Options.FoV, 1.0f, 180.0f);
647647
else if (Option == QLatin1String("--zplanes"))
648648
{
649-
if ((Options.SetZPlanes = ParseFloatArray(2, (float*)Options.ZPlanes, false)) && (Options.ZPlanes[0] < 1.0 || Options.ZPlanes[0] >= Options.ZPlanes[1]))
649+
if ((Options.SetZPlanes = ParseFloatArray(2, Options.ZPlanes.GetFloats(), false)) && (Options.ZPlanes[0] < 1.0 || Options.ZPlanes[0] >= Options.ZPlanes[1]))
650650
{
651651
Options.StdErr += tr("Invalid parameter value(s) specified for the '%1' option: requirements are: 1 <= <near> < <far>.\n").arg(Option);
652652
Options.ParseOK = false;

common/lc_context.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,7 +1344,7 @@ void lcContext::FlushState()
13441344
if (mWorldMatrixDirty)
13451345
{
13461346
if (Program.WorldMatrixLocation != -1)
1347-
glUniformMatrix4fv(Program.WorldMatrixLocation, 1, false, mWorldMatrix);
1347+
glUniformMatrix4fv(Program.WorldMatrixLocation, 1, false, mWorldMatrix.GetFloats());
13481348
}
13491349

13501350
if (mViewMatrixDirty)
@@ -1355,35 +1355,35 @@ void lcContext::FlushState()
13551355
if (Program.LightPositionLocation != -1)
13561356
{
13571357
lcVector3 LightPosition = ViewPosition + lcMul30(lcVector3(300.0f, 300.0f, 0.0f), InverseViewMatrix);
1358-
glUniform3fv(Program.LightPositionLocation, 1, (float*)LightPosition);
1358+
glUniform3fv(Program.LightPositionLocation, 1, LightPosition.GetFloats());
13591359
}
13601360

13611361
if (Program.EyePositionLocation != -1)
1362-
glUniform3fv(Program.EyePositionLocation, 1, (float*)ViewPosition);
1362+
glUniform3fv(Program.EyePositionLocation, 1, ViewPosition.GetFloats());
13631363
}
13641364

1365-
glUniformMatrix4fv(Program.WorldViewProjectionMatrixLocation, 1, false, lcMul(mWorldMatrix, mViewProjectionMatrix));
1365+
glUniformMatrix4fv(Program.WorldViewProjectionMatrixLocation, 1, false, lcMul(mWorldMatrix, mViewProjectionMatrix).GetFloats());
13661366
mWorldMatrixDirty = false;
13671367
mViewMatrixDirty = false;
13681368
mProjectionMatrixDirty = false;
13691369
}
13701370

13711371
if (mColorDirty && Program.MaterialColorLocation != -1)
13721372
{
1373-
glUniform4fv(Program.MaterialColorLocation, 1, (float*)mColor);
1373+
glUniform4fv(Program.MaterialColorLocation, 1, mColor.GetFloats());
13741374
mColorDirty = false;
13751375
}
13761376

13771377
if (mHighlightParamsDirty && Program.HighlightParamsLocation != -1)
13781378
{
1379-
glUniform4fv(Program.HighlightParamsLocation, 4, (float*)mHighlightParams[0]);
1379+
glUniform4fv(Program.HighlightParamsLocation, 4, mHighlightParams[0].GetFloats());
13801380
mHighlightParamsDirty = false;
13811381
}
13821382
}
13831383
else
13841384
{
13851385
#if LC_FIXED_FUNCTION
1386-
glColor4fv((float*)mColor);
1386+
glColor4fv(mColor.GetFloats());
13871387

13881388
if (mWorldMatrixDirty || mViewMatrixDirty)
13891389
{
@@ -1393,7 +1393,7 @@ void lcContext::FlushState()
13931393
mMatrixMode = GL_MODELVIEW;
13941394
}
13951395

1396-
glLoadMatrixf(lcMul(mWorldMatrix, mViewMatrix));
1396+
glLoadMatrixf(lcMul(mWorldMatrix, mViewMatrix).GetFloats());
13971397
mWorldMatrixDirty = false;
13981398
mViewMatrixDirty = false;
13991399
}
@@ -1406,7 +1406,7 @@ void lcContext::FlushState()
14061406
mMatrixMode = GL_PROJECTION;
14071407
}
14081408

1409-
glLoadMatrixf(mProjectionMatrix);
1409+
glLoadMatrixf(mProjectionMatrix.GetFloats());
14101410
mProjectionMatrixDirty = false;
14111411
}
14121412
#endif

common/lc_file.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class lcFile
156156
lcVector3 ReadVector3()
157157
{
158158
lcVector3 Vector;
159-
ReadFloats((float*)Vector, 3);
159+
ReadFloats(Vector.GetFloats(), 3);
160160
return Vector;
161161
}
162162

@@ -277,7 +277,7 @@ class lcFile
277277

278278
void WriteVector3(const lcVector3& Vector)
279279
{
280-
WriteFloats((const float*)Vector, 3);
280+
WriteFloats(Vector.GetFloats(), 3);
281281
}
282282

283283
void WriteQString(const QString& String)

common/lc_math.h

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -88,24 +88,24 @@ class lcVector2
8888
{
8989
}
9090

91-
explicit operator const float*() const
91+
const float& operator[](int i) const
9292
{
93-
return (const float*)this;
93+
return ((float*)this)[i];
9494
}
9595

96-
explicit operator float*()
96+
float& operator[](int i)
9797
{
98-
return (float*)this;
98+
return ((float*)this)[i];
9999
}
100100

101-
const float& operator[](int i) const
101+
const float* GetFloats() const
102102
{
103-
return ((float*)this)[i];
103+
return (const float*)this;
104104
}
105105

106-
float& operator[](int i)
106+
float* GetFloats()
107107
{
108-
return ((float*)this)[i];
108+
return (float*)this;
109109
}
110110

111111
bool IsNan() const
@@ -130,24 +130,24 @@ class lcVector3
130130

131131
explicit lcVector3(const lcVector4& v);
132132

133-
explicit operator const float*() const
133+
const float& operator[](int i) const
134134
{
135-
return (const float*)this;
135+
return ((float*)this)[i];
136136
}
137137

138-
explicit operator float*()
138+
float& operator[](int i)
139139
{
140-
return (float*)this;
140+
return ((float*)this)[i];
141141
}
142142

143-
const float& operator[](int i) const
143+
const float* GetFloats() const
144144
{
145-
return ((float*)this)[i];
145+
return (const float*)this;
146146
}
147147

148-
float& operator[](int i)
148+
float* GetFloats()
149149
{
150-
return ((float*)this)[i];
150+
return (float*)this;
151151
}
152152

153153
bool IsNan() const
@@ -179,24 +179,24 @@ class lcVector4
179179
{
180180
}
181181

182-
explicit operator const float*() const
182+
const float& operator[](int i) const
183183
{
184-
return (const float*)this;
184+
return ((float*)this)[i];
185185
}
186186

187-
explicit operator float*()
187+
float& operator[](int i)
188188
{
189-
return (float*)this;
189+
return ((float*)this)[i];
190190
}
191191

192-
const float& operator[](int i) const
192+
const float* GetFloats() const
193193
{
194-
return ((float*)this)[i];
194+
return (const float*)this;
195195
}
196196

197-
float& operator[](int i)
197+
float* GetFloats()
198198
{
199-
return ((float*)this)[i];
199+
return (float*)this;
200200
}
201201

202202
bool IsNan() const
@@ -223,24 +223,24 @@ class lcMatrix33
223223

224224
explicit lcMatrix33(const lcMatrix44& Matrix);
225225

226-
operator const float*() const
226+
const lcVector3& operator[](int i) const
227227
{
228-
return (const float*)this;
228+
return r[i];
229229
}
230230

231-
operator float*()
231+
lcVector3& operator[](int i)
232232
{
233-
return (float*)this;
233+
return r[i];
234234
}
235235

236-
const lcVector3& operator[](int i) const
236+
const float* GetFloats() const
237237
{
238-
return r[i];
238+
return (const float*)this;
239239
}
240240

241-
lcVector3& operator[](int i)
241+
float* GetFloats()
242242
{
243-
return r[i];
243+
return (float*)this;
244244
}
245245

246246
void Orthonormalize();
@@ -281,24 +281,24 @@ class lcMatrix44
281281
r[3] = lcVector4(Translation[0], Translation[1], Translation[2], 1.0f);
282282
}
283283

284-
operator const float*() const
284+
const lcVector4& operator[](int i) const
285285
{
286-
return (const float*)this;
286+
return r[i];
287287
}
288288

289-
operator float*()
289+
lcVector4& operator[](int i)
290290
{
291-
return (float*)this;
291+
return r[i];
292292
}
293293

294-
const lcVector4& operator[](int i) const
294+
const float* GetFloats() const
295295
{
296-
return r[i];
296+
return (const float*)this;
297297
}
298298

299-
lcVector4& operator[](int i)
299+
float* GetFloats()
300300
{
301-
return r[i];
301+
return (float*)this;
302302
}
303303

304304
float Determinant() const;
@@ -459,6 +459,11 @@ inline bool operator==(const lcVector4& a, const lcVector4& b)
459459
return a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w;
460460
}
461461

462+
inline bool operator==(const lcMatrix33& a, const lcMatrix33& b)
463+
{
464+
return a.r[0] == b.r[0] && a.r[1] == b.r[1] && a.r[2] == b.r[2];
465+
}
466+
462467
#ifndef QT_NO_DEBUG
463468

464469
inline QDebug operator<<(QDebug Debug, const lcVector2& v)

common/lc_model.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ void lcModel::SaveLDraw(QTextStream& Stream, bool SelectedOnly, lcStep LastStep)
455455
{
456456
Stream << QLatin1String("0 !LEOCAD SYNTH CONTROL_POINT");
457457

458-
const float* FloatMatrix = ControlPoint.Transform;
458+
const float* FloatMatrix = ControlPoint.Transform.GetFloats();
459459
const float Numbers[13] = { FloatMatrix[12], -FloatMatrix[14], FloatMatrix[13], FloatMatrix[0], -FloatMatrix[8], FloatMatrix[4], -FloatMatrix[2], FloatMatrix[10], -FloatMatrix[6], FloatMatrix[1], -FloatMatrix[9], FloatMatrix[5], ControlPoint.Scale };
460460

461461
for (int NumberIdx = 0; NumberIdx < 13; NumberIdx++)
@@ -742,7 +742,7 @@ void lcModel::LoadLDraw(QIODevice& Device, Project* Project)
742742

743743
PieceInfo* Info = Library->FindPiece(PartId.toLatin1().constData(), Project, true, true);
744744

745-
const float* Matrix = IncludeTransform;
745+
const float* Matrix = IncludeTransform.GetFloats();
746746
const lcMatrix44 Transform(lcVector4(Matrix[0], Matrix[2], -Matrix[1], 0.0f), lcVector4(Matrix[8], Matrix[10], -Matrix[9], 0.0f),
747747
lcVector4(-Matrix[4], -Matrix[6], Matrix[5], 0.0f), lcVector4(Matrix[12], Matrix[14], -Matrix[13], 1.0f));
748748

@@ -849,8 +849,8 @@ bool lcModel::LoadBinary(lcFile* file)
849849
lcVector3 pos, rot;
850850
quint8 color, step, group;
851851

852-
file->ReadFloats((float*)pos, 3);
853-
file->ReadFloats((float*)rot, 3);
852+
file->ReadFloats(pos.GetFloats(), 3);
853+
file->ReadFloats(rot.GetFloats(), 3);
854854
file->ReadU8(&color, 1);
855855
file->ReadBuffer(name, 9);
856856
strcat(name, ".dat");

common/lc_viewmanipulator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ lcViewManipulator::lcViewManipulator(lcView* View)
6565

6666
void lcViewManipulator::CreateResources(lcContext* Context)
6767
{
68-
float* CurVert = (float*)mRotateMoveVertices[0];
68+
float* CurVert = mRotateMoveVertices[0].GetFloats();
6969

7070
const float OverlayMovePlaneSize = 0.5f;
7171
const float OverlayMoveArrowSize = 1.5f;
@@ -283,7 +283,7 @@ void lcViewManipulator::CreateResources(lcContext* Context)
283283
*CurVert++ = OverlayTrainTrackBoxSize; *CurVert++ = OverlayTrainTrackBoxSize; *CurVert++ = OverlayTrainTrackBoxSize;
284284
*CurVert++ = OverlayTrainTrackBoxSize; *CurVert++ = -OverlayTrainTrackBoxSize; *CurVert++ = OverlayTrainTrackBoxSize;
285285

286-
mRotateMoveVertexBuffer = Context->CreateVertexBuffer(sizeof(mRotateMoveVertices), (const float*)mRotateMoveVertices[0]);
286+
mRotateMoveVertexBuffer = Context->CreateVertexBuffer(sizeof(mRotateMoveVertices), mRotateMoveVertices[0].GetFloats());
287287
mRotateMoveIndexBuffer = Context->CreateIndexBuffer(sizeof(mRotateMoveIndices), mRotateMoveIndices);
288288
}
289289

common/piece.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ void lcPiece::SaveLDraw(QTextStream& Stream) const
120120

121121
if (mPivotPointValid)
122122
{
123-
const float* PivotMatrix = mPivotMatrix;
123+
const float* PivotMatrix = mPivotMatrix.GetFloats();
124124
const float PivotNumbers[12] = { PivotMatrix[12], -PivotMatrix[14], PivotMatrix[13], PivotMatrix[0], -PivotMatrix[8], PivotMatrix[4], -PivotMatrix[2], PivotMatrix[10], -PivotMatrix[6], PivotMatrix[1], -PivotMatrix[9], PivotMatrix[5] };
125125

126126
Stream << QLatin1String("0 !LEOCAD PIECE PIVOT ");
@@ -136,7 +136,7 @@ void lcPiece::SaveLDraw(QTextStream& Stream) const
136136

137137
Stream << "1 " << mColorCode << ' ';
138138

139-
const float* Matrix = mModelWorld;
139+
const float* Matrix = mModelWorld.GetFloats();
140140
const float Numbers[12] = { Matrix[12], -Matrix[14], Matrix[13], Matrix[0], -Matrix[8], Matrix[4], -Matrix[2], Matrix[10], -Matrix[6], Matrix[1], -Matrix[9], Matrix[5] };
141141

142142
for (int NumberIdx = 0; NumberIdx < 12; NumberIdx++)
@@ -263,13 +263,13 @@ bool lcPiece::FileLoad(lcFile& file)
263263

264264
if (version > 3)
265265
{
266-
file.ReadFloats(ModelWorld, 16);
266+
file.ReadFloats(ModelWorld.GetFloats(), 16);
267267
}
268268
else
269269
{
270270
lcVector3 Translation;
271271
float Rotation[3];
272-
file.ReadFloats((float*)Translation, 3);
272+
file.ReadFloats(Translation.GetFloats(), 3);
273273
file.ReadFloats(Rotation, 3);
274274
ModelWorld = lcMatrix44Translation(Translation);
275275
ModelWorld = lcMul(lcMatrix44RotationZ(Rotation[2] * LC_DTOR), lcMul(lcMatrix44RotationY(Rotation[1] * LC_DTOR), lcMul(lcMatrix44RotationX(Rotation[0] * LC_DTOR), ModelWorld)));
@@ -290,7 +290,7 @@ bool lcPiece::FileLoad(lcFile& file)
290290
{
291291
lcVector3 Translation;
292292
float Rotation[3];
293-
file.ReadFloats((float*)Translation, 3);
293+
file.ReadFloats(Translation.GetFloats(), 3);
294294
file.ReadFloats(Rotation, 3);
295295
lcMatrix44 ModelWorld = lcMatrix44Translation(Translation);
296296
ModelWorld = lcMul(lcMatrix44RotationZ(Rotation[2] * LC_DTOR), lcMul(lcMatrix44RotationY(Rotation[1] * LC_DTOR), lcMul(lcMatrix44RotationX(Rotation[0] * LC_DTOR), ModelWorld)));

0 commit comments

Comments
 (0)