Skip to content

Commit 6a26e60

Browse files
committed
Made vector to float cast explicit, and fixed unintended casts.
1 parent 026a25c commit 6a26e60

11 files changed

+94
-59
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, Options.CameraLatLon, true)) && (fabsf(Options.CameraLatLon[0]) > 360.0f || fabsf(Options.CameraLatLon[1]) > 360.0f))
607+
if ((Options.SetCameraAngles = ParseFloatArray(2, (float*)Options.CameraLatLon, 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, Options.CameraPosition[0], true)))
615+
if ((Options.SetCameraPosition = ParseFloatArray(9, (float*)Options.CameraPosition[0], 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, Options.ZPlanes, false)) && (Options.ZPlanes[0] < 1.0 || Options.ZPlanes[0] >= Options.ZPlanes[1]))
649+
if ((Options.SetZPlanes = ParseFloatArray(2, (float*)Options.ZPlanes, 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: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,11 +1355,11 @@ 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, LightPosition);
1358+
glUniform3fv(Program.LightPositionLocation, 1, (float*)LightPosition);
13591359
}
13601360

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

13651365
glUniformMatrix4fv(Program.WorldViewProjectionMatrixLocation, 1, false, lcMul(mWorldMatrix, mViewProjectionMatrix));
@@ -1370,20 +1370,20 @@ void lcContext::FlushState()
13701370

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

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

13881388
if (mWorldMatrixDirty || mViewMatrixDirty)
13891389
{

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(Vector, 3);
159+
ReadFloats((float*)Vector, 3);
160160
return Vector;
161161
}
162162

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

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

283283
void WriteQString(const QString& String)

common/lc_math.h

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,12 @@ class lcVector2
8888
{
8989
}
9090

91-
operator const float*() const
91+
explicit operator const float*() const
9292
{
9393
return (const float*)this;
9494
}
9595

96-
operator float*()
96+
explicit operator float*()
9797
{
9898
return (float*)this;
9999
}
@@ -130,12 +130,12 @@ class lcVector3
130130

131131
explicit lcVector3(const lcVector4& v);
132132

133-
operator const float*() const
133+
explicit operator const float*() const
134134
{
135135
return (const float*)this;
136136
}
137137

138-
operator float*()
138+
explicit operator float*()
139139
{
140140
return (float*)this;
141141
}
@@ -179,12 +179,12 @@ class lcVector4
179179
{
180180
}
181181

182-
operator const float*() const
182+
explicit operator const float*() const
183183
{
184184
return (const float*)this;
185185
}
186186

187-
operator float*()
187+
explicit operator float*()
188188
{
189189
return (float*)this;
190190
}
@@ -306,6 +306,11 @@ class lcMatrix44
306306
lcVector4 r[4];
307307
};
308308

309+
inline bool operator==(const lcVector2& a, const lcVector2& b)
310+
{
311+
return a.x == b.x && a.y == b.y;
312+
}
313+
309314
inline lcVector3::lcVector3(const lcVector4& v)
310315
: x(v.x), y(v.y), z(v.z)
311316
{
@@ -429,6 +434,31 @@ inline bool operator!=(const lcVector3& a, const lcVector3& b)
429434
return a.x != b.x || a.y != b.y || a.z != b.z;
430435
}
431436

437+
inline bool operator<(const lcVector3& a, const lcVector3& b)
438+
{
439+
if (a.x < b.x)
440+
return true;
441+
else if (a.x > b.x)
442+
return false;
443+
444+
if (a.y < b.y)
445+
return true;
446+
else if (a.y > b.y)
447+
return false;
448+
449+
if (a.z < b.z)
450+
return true;
451+
else if (a.z > b.z)
452+
return false;
453+
454+
return false;
455+
}
456+
457+
inline bool operator==(const lcVector4& a, const lcVector4& b)
458+
{
459+
return a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w;
460+
}
461+
432462
#ifndef QT_NO_DEBUG
433463

434464
inline QDebug operator<<(QDebug Debug, const lcVector2& v)
@@ -1843,10 +1873,10 @@ inline void lcPolygonPlaneClip(lcVector3* InPoints, int NumInPoints, lcVector3*
18431873
}
18441874

18451875
// Return true if a polygon intersects a set of planes.
1846-
inline bool lcTriangleIntersectsPlanes(const float* p1, const float* p2, const float* p3, const lcVector4 Planes[6])
1876+
inline bool lcTriangleIntersectsPlanes(const lcVector3& p1, const lcVector3& p2, const lcVector3& p3, const lcVector4 Planes[6])
18471877
{
18481878
constexpr int NumPlanes = 6;
1849-
const float* const Points[3] = { p1, p2, p3 };
1879+
const lcVector3 Points[3] = { p1, p2, p3 };
18501880
int Outcodes[3] = { 0, 0, 0 }, i;
18511881
constexpr int NumPoints = 3;
18521882

common/lc_model.cpp

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -849,8 +849,8 @@ bool lcModel::LoadBinary(lcFile* file)
849849
lcVector3 pos, rot;
850850
quint8 color, step, group;
851851

852-
file->ReadFloats(pos, 3);
853-
file->ReadFloats(rot, 3);
852+
file->ReadFloats((float*)pos, 3);
853+
file->ReadFloats((float*)rot, 3);
854854
file->ReadU8(&color, 1);
855855
file->ReadBuffer(name, 9);
856856
strcat(name, ".dat");
@@ -4574,8 +4574,7 @@ void lcModel::UpdateFreeMoveTool(lcPiece* MousePiece, const lcMatrix44& StartTra
45744574

45754575
if (!lcMatrix33Similar(CurrentRotation, NewRotation))
45764576
{
4577-
const lcVector3 PieceDistance = NewTransform.GetTranslation() - MousePiece->mModelWorld.GetTranslation();
4578-
const lcVector3 ObjectDistance = PieceDistance;
4577+
const lcVector3 Distance = NewTransform.GetTranslation() - MousePiece->mModelWorld.GetTranslation();
45794578

45804579
lcMatrix33 RotationMatrix = lcMul(lcMatrix33AffineInverse(CurrentRotation), NewRotation);
45814580

@@ -4597,26 +4596,32 @@ void lcModel::UpdateFreeMoveTool(lcPiece* MousePiece, const lcMatrix44& StartTra
45974596
{
45984597
lcPiece* Piece = (lcPiece*)Object;
45994598

4600-
Piece->MoveSelected(mCurrentStep, gMainWindow->GetAddKeys(), PieceDistance);
4599+
Piece->MoveSelected(mCurrentStep, gMainWindow->GetAddKeys(), Distance);
46014600
Piece->UpdatePosition(mCurrentStep);
46024601

46034602
Piece->Rotate(mCurrentStep, gMainWindow->GetAddKeys(), RotationMatrix, Center, WorldToFocusMatrix);
46044603
Piece->UpdatePosition(mCurrentStep);
46054604
}
4606-
else if (Object->IsCamera())
4607-
{
4608-
//move
4609-
//rotate
4610-
}
4611-
else if (Object->IsLight())
4612-
{
4613-
lcLight* Light = (lcLight*)Object;
4605+
else if (Object->IsCamera())
4606+
{
4607+
lcCamera* Camera = (lcCamera*)Object;
46144608

4615-
//move
4609+
Camera->MoveSelected(mCurrentStep, gMainWindow->GetAddKeys(), Distance);
4610+
Camera->UpdatePosition(mCurrentStep);
46164611

4617-
// Light->Rotate(mCurrentStep, gMainWindow->GetAddKeys(), RotationMatrix, Center, WorldToFocusMatrix);
4618-
Light->UpdatePosition(mCurrentStep);
4619-
}
4612+
// Camera->Rotate(mCurrentStep, gMainWindow->GetAddKeys(), RotationMatrix, Center, WorldToFocusMatrix);
4613+
// Camera->UpdatePosition(mCurrentStep);
4614+
}
4615+
else if (Object->IsLight())
4616+
{
4617+
lcLight* Light = (lcLight*)Object;
4618+
4619+
Light->MoveSelected(mCurrentStep, gMainWindow->GetAddKeys(), Distance, mMouseToolFirstMove);
4620+
Light->UpdatePosition(mCurrentStep);
4621+
4622+
Light->Rotate(mCurrentStep, gMainWindow->GetAddKeys(), RotationMatrix, Center, WorldToFocusMatrix);
4623+
Light->UpdatePosition(mCurrentStep);
4624+
}
46204625
}
46214626

46224627
mMouseToolDistance = NewTransform.GetTranslation() - StartTransform.GetTranslation();

common/lc_propertieswidget.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ void lcPropertiesWidget::FloatChanged()
282282

283283
lcVector3 Distance = Position - Center;
284284

285-
Model->MoveSelectedObjects(Distance, Distance, false, true, true, true);
285+
Model->MoveSelectedObjects(Distance, false, false, true, true, true);
286286
}
287287
else if (PropertyId == lcObjectPropertyId::ObjectRotationX || PropertyId == lcObjectPropertyId::ObjectRotationY || PropertyId == lcObjectPropertyId::ObjectRotationZ)
288288
{
@@ -323,7 +323,7 @@ void lcPropertiesWidget::FloatChanged()
323323

324324
lcVector3 Distance = Position - Center;
325325

326-
Model->MoveSelectedObjects(Distance, Distance, false, false, true, true);
326+
Model->MoveSelectedObjects(Distance, false, false, true, true, true);
327327
}
328328
else if (PropertyId == lcObjectPropertyId::CameraTargetX || PropertyId == lcObjectPropertyId::CameraTargetY || PropertyId == lcObjectPropertyId::CameraTargetZ)
329329
{
@@ -339,7 +339,7 @@ void lcPropertiesWidget::FloatChanged()
339339

340340
lcVector3 Distance = Position - Center;
341341

342-
Model->MoveSelectedObjects(Distance, Distance, false, false, true, true);
342+
Model->MoveSelectedObjects(Distance, false, false, true, true, true);
343343
}
344344
else if (PropertyId == lcObjectPropertyId::CameraUpX || PropertyId == lcObjectPropertyId::CameraUpY || PropertyId == lcObjectPropertyId::CameraUpZ)
345345
{
@@ -355,7 +355,7 @@ void lcPropertiesWidget::FloatChanged()
355355

356356
lcVector3 Distance = Position - Center;
357357

358-
Model->MoveSelectedObjects(Distance, Distance, false, false, true, true);
358+
Model->MoveSelectedObjects(Distance, false, false, true, true, true);
359359
}
360360
else if (Camera)
361361
{

common/lc_timelinewidget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ void lcTimelineWidget::Update(bool Clear, bool UpdateItems)
203203

204204
QImage Image(Size, Size, QImage::Format_ARGB32);
205205
Image.fill(0);
206-
float* Color = gColorList[ColorIndex].Value;
206+
const lcVector4& Color = gColorList[ColorIndex].Value;
207207
QPainter Painter(&Image);
208208
Painter.setPen(Qt::darkGray);
209209
Painter.setBrush(QColor::fromRgbF(Color[0], Color[1], Color[2]));

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 = mRotateMoveVertices[0];
68+
float* CurVert = (float*)mRotateMoveVertices[0];
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), mRotateMoveVertices[0]);
286+
mRotateMoveVertexBuffer = Context->CreateVertexBuffer(sizeof(mRotateMoveVertices), (const float*)mRotateMoveVertices[0]);
287287
mRotateMoveIndexBuffer = Context->CreateIndexBuffer(sizeof(mRotateMoveIndices), mRotateMoveIndices);
288288
}
289289

common/light.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ void lcLight::Rotate(lcStep Step, bool AddKey, const lcMatrix33& RotationMatrix,
457457
if (IsPointLight())
458458
return;
459459

460-
if (GetFocusSection() != LC_LIGHT_SECTION_POSITION)
460+
if (GetFocusSection() != LC_LIGHT_SECTION_POSITION && GetFocusSection() != LC_LIGHT_SECTION_INVALID)
461461
return;
462462

463463
lcVector3 Distance = mWorldMatrix.GetTranslation() - Center;

common/piece.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ bool lcPiece::FileLoad(lcFile& file)
269269
{
270270
lcVector3 Translation;
271271
float Rotation[3];
272-
file.ReadFloats(Translation, 3);
272+
file.ReadFloats((float*)Translation, 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(Translation, 3);
293+
file.ReadFloats((float*)Translation, 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)