diff --git a/SpaceCadetPinball/TBall.cpp b/SpaceCadetPinball/TBall.cpp index 4bf91d0..5de74b5 100644 --- a/SpaceCadetPinball/TBall.cpp +++ b/SpaceCadetPinball/TBall.cpp @@ -49,7 +49,7 @@ TBall::TBall(TPinballTable* table) : TPinballComponent(table, -1, false) loader::query_visual(groupIndex, index, &visual); if (ListBitmap) ListBitmap->push_back(visual.Bitmap); - auto visVec = reinterpret_cast(loader::query_float_attribute(groupIndex, index, 501)); + auto visVec = reinterpret_cast(loader::query_float_attribute(groupIndex, index, 501)); auto zDepth = proj::z_distance(visVec); VisualZArray[index] = zDepth; } @@ -129,7 +129,7 @@ int TBall::Message(int code, float value) return 0; } -void TBall::throw_ball(TBall* ball, vector_type* acceleration, float angleMult, float speedMult1, float speedMult2) +void TBall::throw_ball(TBall* ball, vector3* acceleration, float angleMult, float speedMult1, float speedMult2) { ball->CollisionComp = nullptr; ball->Acceleration = *acceleration; diff --git a/SpaceCadetPinball/TBall.h b/SpaceCadetPinball/TBall.h index 421610c..b060b4d 100644 --- a/SpaceCadetPinball/TBall.h +++ b/SpaceCadetPinball/TBall.h @@ -14,11 +14,11 @@ public : bool already_hit(TEdgeSegment* edge); int Message(int code, float value) override; - static void throw_ball(TBall* ball, struct vector_type* acceleration, float angleMult, float speedMult1, + static void throw_ball(TBall* ball, vector3* acceleration, float angleMult, float speedMult1, float speedMult2); - vector_type Position{}; - vector_type Acceleration{}; + vector3 Position{}; + vector3 Acceleration{}; float Speed; float RayMaxDistance; float TimeDelta; @@ -29,7 +29,7 @@ public : int FieldFlag; TEdgeSegment* Collisions[5]{}; int EdgeCollisionCount; - vector_type CollisionOffset{}; + vector3 CollisionOffset{}; int CollisionFlag; float Offset; float VisualZArray[50]{}; diff --git a/SpaceCadetPinball/TEdgeSegment.cpp b/SpaceCadetPinball/TEdgeSegment.cpp index df12ed9..43545c3 100644 --- a/SpaceCadetPinball/TEdgeSegment.cpp +++ b/SpaceCadetPinball/TEdgeSegment.cpp @@ -20,7 +20,8 @@ void TEdgeSegment::port_draw() TEdgeSegment* TEdgeSegment::install_wall(float* floatArr, TCollisionComponent* collComp, char* activeFlagPtr, unsigned int collisionGroup, float offset, size_t wallValue) { - vector_type center{}, start{}, end{}, prevCenter{}, vec1{}, vec2{}, dstVec{}; + vector_type center{}, start{}, end{}, prevCenter{}; + vector3 vec1{}, vec2{}, dstVec{}; TEdgeSegment* edge = nullptr; wall_type wallType = static_cast(static_cast(floor(*floatArr) - 1.0f)); diff --git a/SpaceCadetPinball/TFlipper.cpp b/SpaceCadetPinball/TFlipper.cpp index a227c92..55dc126 100644 --- a/SpaceCadetPinball/TFlipper.cpp +++ b/SpaceCadetPinball/TFlipper.cpp @@ -31,9 +31,9 @@ TFlipper::TFlipper(TPinballTable* table, int groupIndex) : TCollisionComponent(t retractTime = 0.08f; extendTime = 0.04f; } - auto vecT2 = reinterpret_cast(loader::query_float_attribute(groupIndex, 0, 802)); - auto vecT1 = reinterpret_cast(loader::query_float_attribute(groupIndex, 0, 801)); - auto origin = reinterpret_cast(loader::query_float_attribute(groupIndex, 0, 800)); + auto vecT2 = reinterpret_cast(loader::query_float_attribute(groupIndex, 0, 802)); + auto vecT1 = reinterpret_cast(loader::query_float_attribute(groupIndex, 0, 801)); + auto origin = reinterpret_cast(loader::query_float_attribute(groupIndex, 0, 800)); auto flipperEdge = new TFlipperEdge( this, &ActiveFlag, diff --git a/SpaceCadetPinball/TFlipperEdge.cpp b/SpaceCadetPinball/TFlipperEdge.cpp index e99a611..780eba1 100644 --- a/SpaceCadetPinball/TFlipperEdge.cpp +++ b/SpaceCadetPinball/TFlipperEdge.cpp @@ -12,10 +12,10 @@ line_type TFlipperEdge::lineA, TFlipperEdge::lineB; circle_type TFlipperEdge::circlebase, TFlipperEdge::circleT1; TFlipperEdge::TFlipperEdge(TCollisionComponent* collComp, char* activeFlag, unsigned int collisionGroup, TPinballTable* table, - vector_type* origin, vector_type* vecT1, vector_type* vecT2, float extendTime, float retractTime, + vector3* origin, vector3* vecT1, vector3* vecT2, float extendTime, float retractTime, float collMult, float elasticity, float smoothness): TEdgeSegment(collComp, activeFlag, collisionGroup) { - vector_type crossProd{}, vecDir1{}, vecDir2{}; + vector3 crossProd{}, vecDir1{}, vecDir2{}; Elasticity = elasticity; Smoothness = smoothness; diff --git a/SpaceCadetPinball/TFlipperEdge.h b/SpaceCadetPinball/TFlipperEdge.h index 2554b67..a440697 100644 --- a/SpaceCadetPinball/TFlipperEdge.h +++ b/SpaceCadetPinball/TFlipperEdge.h @@ -8,7 +8,7 @@ class TFlipperEdge : public TEdgeSegment { public: TFlipperEdge(TCollisionComponent* collComp, char* activeFlag, unsigned int collisionGroup, TPinballTable* table, - vector_type* origin, vector_type* vecT1, vector_type* vecT2, float extendTime, float retractTime, float collMult, + vector3* origin, vector3* vecT1, vector3* vecT2, float extendTime, float retractTime, float collMult, float elasticity, float smoothness); void port_draw() override; float FindCollisionDistance(ray_type* ray) override; diff --git a/SpaceCadetPinball/THole.cpp b/SpaceCadetPinball/THole.cpp index 49d1321..b93b3a7 100644 --- a/SpaceCadetPinball/THole.cpp +++ b/SpaceCadetPinball/THole.cpp @@ -31,7 +31,7 @@ THole::THole(TPinballTable* table, int groupIndex) : TCollisionComponent(table, Circle.RadiusSq = 0.001f; auto tCircle = new TCircle(this, &ActiveFlag, visual.CollisionGroup, - reinterpret_cast(visual.FloatArr), + reinterpret_cast(visual.FloatArr), Circle.RadiusSq); if (tCircle) { @@ -50,7 +50,6 @@ THole::THole(TPinballTable* table, int groupIndex) : TCollisionComponent(table, circle.RadiusSq = Circle.RadiusSq; circle.Center.X = Circle.Center.X; circle.Center.Y = Circle.Center.Y; - circle.Center.Z = Circle.Center.Z; Field.Flag2Ptr = &ActiveFlag; Field.CollisionComp = this; diff --git a/SpaceCadetPinball/TKickout.cpp b/SpaceCadetPinball/TKickout.cpp index aa41833..400bb21 100644 --- a/SpaceCadetPinball/TKickout.cpp +++ b/SpaceCadetPinball/TKickout.cpp @@ -36,7 +36,7 @@ TKickout::TKickout(TPinballTable* table, int groupIndex, bool someFlag): TCollis if (Circle.RadiusSq == 0.0f) Circle.RadiusSq = 0.001f; auto tCircle = new TCircle(this, &ActiveFlag, visual.CollisionGroup, - reinterpret_cast(visual.FloatArr), Circle.RadiusSq); + reinterpret_cast(visual.FloatArr), Circle.RadiusSq); if (tCircle) { tCircle->place_in_grid(); @@ -54,7 +54,6 @@ TKickout::TKickout(TPinballTable* table, int groupIndex, bool someFlag): TCollis circle.RadiusSq = Circle.RadiusSq; circle.Center.X = Circle.Center.X; circle.Center.Y = Circle.Center.Y; - circle.Center.Z = Circle.Center.Z; Field.Flag2Ptr = &ActiveFlag; Field.CollisionComp = this; Field.Mask = visual.CollisionGroup; diff --git a/SpaceCadetPinball/TKickout.h b/SpaceCadetPinball/TKickout.h index fa2baab..5dfcc89 100644 --- a/SpaceCadetPinball/TKickout.h +++ b/SpaceCadetPinball/TKickout.h @@ -28,7 +28,7 @@ public: float FieldMult; circle_type Circle{}; float OriginalBallZ{}; - vector_type BallAcceleration{}; + vector3 BallAcceleration{}; float ThrowAngleMult; float ThrowSpeedMult1; float ThrowSpeedMult2; diff --git a/SpaceCadetPinball/TRamp.cpp b/SpaceCadetPinball/TRamp.cpp index 5b524ce..4c930dc 100644 --- a/SpaceCadetPinball/TRamp.cpp +++ b/SpaceCadetPinball/TRamp.cpp @@ -85,9 +85,9 @@ TRamp::TRamp(TPinballTable* table, int groupIndex) : TCollisionComponent(table, for (auto index = 0; index < RampPlaneCount; index++) { auto plane = &RampPlane[index]; - auto pVec1 = reinterpret_cast(&plane->V1); - auto pVec2 = reinterpret_cast(&plane->V2); - auto pVec3 = reinterpret_cast(&plane->V3); + auto pVec1 = &plane->V1; + auto pVec2 = &plane->V2; + auto pVec3 = &plane->V3; xMin = std::min(std::min(std::min(plane->V3.X, plane->V1.X), plane->V2.X), xMin); yMin = std::min(std::min(std::min(plane->V3.Y, plane->V1.Y), plane->V2.Y), xMin); // Sic diff --git a/SpaceCadetPinball/TSink.h b/SpaceCadetPinball/TSink.h index f53e39f..db426e2 100644 --- a/SpaceCadetPinball/TSink.h +++ b/SpaceCadetPinball/TSink.h @@ -18,7 +18,7 @@ public: int Timer; float TimerTime; vector_type BallPosition{}; - vector_type BallAcceleration{}; + vector3 BallAcceleration{}; float ThrowAngleMult; float ThrowSpeedMult1; float ThrowSpeedMult2; diff --git a/SpaceCadetPinball/loader.cpp b/SpaceCadetPinball/loader.cpp index 60ffc0f..c01c065 100644 --- a/SpaceCadetPinball/loader.cpp +++ b/SpaceCadetPinball/loader.cpp @@ -390,7 +390,7 @@ int loader::kicker(int groupIndex, visualKickerStruct* kicker) kicker->ThrowBallMult = *floatArr; break; case 404: - kicker->ThrowBallAcceleration = *reinterpret_cast(floatArr); + kicker->ThrowBallAcceleration = *reinterpret_cast(floatArr); floatArr += 3; index += 4; break; diff --git a/SpaceCadetPinball/loader.h b/SpaceCadetPinball/loader.h index 0e7e22a..cd1ffba 100644 --- a/SpaceCadetPinball/loader.h +++ b/SpaceCadetPinball/loader.h @@ -25,7 +25,7 @@ struct visualKickerStruct float Threshold; float Boost; float ThrowBallMult; - vector_type ThrowBallAcceleration; + vector3 ThrowBallAcceleration; float ThrowBallAngleMult; int HardHitSoundId; }; diff --git a/SpaceCadetPinball/maths.cpp b/SpaceCadetPinball/maths.cpp index bb41669..f392680 100644 --- a/SpaceCadetPinball/maths.cpp +++ b/SpaceCadetPinball/maths.cpp @@ -245,14 +245,14 @@ float maths::ray_intersect_line(ray_type* ray, line_type* line) return 1000000000.0; } -void maths::cross(vector_type* vec1, vector_type* vec2, vector_type* dstVec) +void maths::cross(vector3* vec1, vector3* vec2, vector3* dstVec) { dstVec->X = vec2->Z * vec1->Y - vec2->Y * vec1->Z; dstVec->Y = vec2->X * vec1->Z - vec1->X * vec2->Z; dstVec->Z = vec1->X * vec2->Y - vec2->X * vec1->Y; } -float maths::magnitude(vector_type* vec) +float maths::magnitude(vector3* vec) { float result; auto magSq = vec->X * vec->X + vec->Y * vec->Y + vec->Z * vec->Z; @@ -432,9 +432,9 @@ void maths::find_closest_edge(ramp_plane_type* plane, int planeCount, wall_point ramp_plane_type* planePtr = plane; for (auto index = 0; index < planeCount; index++) { - auto vec1 = reinterpret_cast(&planePtr->V1), - vec2 = reinterpret_cast(&planePtr->V2), - vec3 = reinterpret_cast(&planePtr->V3); + auto vec1 = &planePtr->V1, + vec2 = &planePtr->V2, + vec3 = &planePtr->V3; auto distance = Distance(&wallStart, vec1) + Distance(&wallEnd, vec2); if (distance < maxDistance) { diff --git a/SpaceCadetPinball/maths.h b/SpaceCadetPinball/maths.h index 3e0d767..29e87ed 100644 --- a/SpaceCadetPinball/maths.h +++ b/SpaceCadetPinball/maths.h @@ -6,9 +6,16 @@ struct vector_type { float X; float Y; - float Z; }; +struct vector_type2 :vector_type +{ +}; + +struct vector3 :vector_type +{ + float Z; +}; struct rectangle_type { @@ -45,12 +52,6 @@ struct line_type vector_type RayIntersect; }; -struct vector_type2 -{ - float X; - float Y; -}; - struct wall_point_type { float X0; @@ -61,7 +62,7 @@ struct wall_point_type struct ramp_plane_type { - vector_type BallCollisionOffset; + vector3 BallCollisionOffset; vector_type2 V1; vector_type2 V2; vector_type2 V3; @@ -81,8 +82,8 @@ public: static float normalize_2d(vector_type* vec); static void line_init(line_type* line, float x0, float y0, float x1, float y1); static float ray_intersect_line(ray_type* ray, line_type* line); - static void cross(vector_type* vec1, vector_type* vec2, vector_type* dstVec); - static float magnitude(vector_type* vec); + static void cross(vector3* vec1, vector3* vec2, vector3* dstVec); + static float magnitude(vector3* vec); static void vector_add(vector_type* vec1Dst, vector_type* vec2); static float basic_collision(TBall* ball, vector_type* nextPosition, vector_type* direction, float elasticity, float smoothness, diff --git a/SpaceCadetPinball/pb.cpp b/SpaceCadetPinball/pb.cpp index a30c5a2..0df8d6f 100644 --- a/SpaceCadetPinball/pb.cpp +++ b/SpaceCadetPinball/pb.cpp @@ -308,7 +308,6 @@ void pb::timed_frame(float timeNow, float timeDelta, bool drawBalls) { vec2.X = 0.0; vec2.Y = 0.0; - vec2.Z = 0.0; TTableLayer::edge_manager->FieldEffects(ball, &vec2); vec2.X = vec2.X * timeDelta; vec2.Y = vec2.Y * timeDelta; @@ -486,8 +485,8 @@ void pb::InputDown(GameInput input) } } } - ball->Position.X = 1.0; ball->ActiveFlag = 1; + ball->Position.X = 1.0; ball->Position.Z = ball->Offset; ball->Position.Y = 1.0; ball->Acceleration.Z = 0.0; @@ -607,12 +606,8 @@ float pb::collide(float timeNow, float timeDelta, TBall* ball) ball->RayMaxDistance = maxDistance; ball->TimeNow = timeNow; - ray.Origin.X = ball->Position.X; - ray.Origin.Y = ball->Position.Y; - ray.Origin.Z = ball->Position.Z; - ray.Direction.X = ball->Acceleration.X; - ray.Direction.Y = ball->Acceleration.Y; - ray.Direction.Z = ball->Acceleration.Z; + ray.Origin = ball->Position; + ray.Direction = ball->Acceleration; ray.MaxDistance = maxDistance; ray.FieldFlag = ball->FieldFlag; ray.TimeNow = timeNow; @@ -628,7 +623,6 @@ float pb::collide(float timeNow, float timeDelta, TBall* ball) ball->RayMaxDistance = maxDistance; positionMod.X = maxDistance * ball->Acceleration.X; positionMod.Y = maxDistance * ball->Acceleration.Y; - positionMod.Z = 0.0; maths::vector_add(&ball->Position, &positionMod); } else diff --git a/SpaceCadetPinball/proj.cpp b/SpaceCadetPinball/proj.cpp index 4bb42a0..ec73fda 100644 --- a/SpaceCadetPinball/proj.cpp +++ b/SpaceCadetPinball/proj.cpp @@ -26,7 +26,7 @@ void proj::init(float* mat4x3, float d, float centerX, float centerY) centery = centerY; } -void proj::matrix_vector_multiply(mat4_row_major* mat, vector_type* vec, vector_type* dstVec) +void proj::matrix_vector_multiply(mat4_row_major* mat, vector3* vec, vector3* dstVec) { const float x = vec->X, y = vec->Y, z = vec->Z; dstVec->X = z * mat->Row0.Z + y * mat->Row0.Y + x * mat->Row0.X + mat->Row0.W; @@ -34,17 +34,17 @@ void proj::matrix_vector_multiply(mat4_row_major* mat, vector_type* vec, vector_ dstVec->Z = z * mat->Row2.Z + y * mat->Row2.Y + x * mat->Row2.X + mat->Row2.W; } -float proj::z_distance(vector_type* vec) +float proj::z_distance(vector3* vec) { - vector_type dstVec{}; + vector3 dstVec{}; matrix_vector_multiply(&matrix, vec, &dstVec); return maths::magnitude(&dstVec); } -void proj::xform_to_2d(vector_type* vec, int* dst) +void proj::xform_to_2d(vector3* vec, int* dst) { float projCoef; - vector_type dstVec2{}; + vector3 dstVec2{}; matrix_vector_multiply(&matrix, vec, &dstVec2); if (dstVec2.Z == 0.0f) diff --git a/SpaceCadetPinball/proj.h b/SpaceCadetPinball/proj.h index 8cb4c61..e872925 100644 --- a/SpaceCadetPinball/proj.h +++ b/SpaceCadetPinball/proj.h @@ -22,9 +22,9 @@ class proj { public: static void init(float* mat4x3, float d, float centerX, float centerY); - static void matrix_vector_multiply(mat4_row_major* mat, vector_type* vec, vector_type* dstVec); - static float z_distance(vector_type* vec); - static void xform_to_2d(vector_type* vec, int* dst); + static void matrix_vector_multiply(mat4_row_major* mat, vector3* vec, vector3* dstVec); + static float z_distance(vector3* vec); + static void xform_to_2d(vector3* vec, int* dst); static void recenter(float centerX, float centerY); private: static mat4_row_major matrix;