mirror of
https://github.com/iAmInActions/SpaceCadetPinballPPC.git
synced 2024-11-21 11:30:07 +00:00
Cleaning up maths: part 1.
Vector3 inherited from vector2.
This commit is contained in:
parent
3f7526ba12
commit
d23444b983
@ -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<vector_type*>(loader::query_float_attribute(groupIndex, index, 501));
|
||||
auto visVec = reinterpret_cast<vector3*>(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;
|
||||
|
@ -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]{};
|
||||
|
@ -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<wall_type>(static_cast<int>(floor(*floatArr) - 1.0f));
|
||||
|
@ -31,9 +31,9 @@ TFlipper::TFlipper(TPinballTable* table, int groupIndex) : TCollisionComponent(t
|
||||
retractTime = 0.08f;
|
||||
extendTime = 0.04f;
|
||||
}
|
||||
auto vecT2 = reinterpret_cast<vector_type*>(loader::query_float_attribute(groupIndex, 0, 802));
|
||||
auto vecT1 = reinterpret_cast<vector_type*>(loader::query_float_attribute(groupIndex, 0, 801));
|
||||
auto origin = reinterpret_cast<vector_type*>(loader::query_float_attribute(groupIndex, 0, 800));
|
||||
auto vecT2 = reinterpret_cast<vector3*>(loader::query_float_attribute(groupIndex, 0, 802));
|
||||
auto vecT1 = reinterpret_cast<vector3*>(loader::query_float_attribute(groupIndex, 0, 801));
|
||||
auto origin = reinterpret_cast<vector3*>(loader::query_float_attribute(groupIndex, 0, 800));
|
||||
auto flipperEdge = new TFlipperEdge(
|
||||
this,
|
||||
&ActiveFlag,
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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<vector_type*>(visual.FloatArr),
|
||||
reinterpret_cast<vector3*>(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;
|
||||
|
@ -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<vector_type*>(visual.FloatArr), Circle.RadiusSq);
|
||||
reinterpret_cast<vector3*>(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;
|
||||
|
@ -28,7 +28,7 @@ public:
|
||||
float FieldMult;
|
||||
circle_type Circle{};
|
||||
float OriginalBallZ{};
|
||||
vector_type BallAcceleration{};
|
||||
vector3 BallAcceleration{};
|
||||
float ThrowAngleMult;
|
||||
float ThrowSpeedMult1;
|
||||
float ThrowSpeedMult2;
|
||||
|
@ -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<vector_type*>(&plane->V1);
|
||||
auto pVec2 = reinterpret_cast<vector_type*>(&plane->V2);
|
||||
auto pVec3 = reinterpret_cast<vector_type*>(&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
|
||||
|
@ -18,7 +18,7 @@ public:
|
||||
int Timer;
|
||||
float TimerTime;
|
||||
vector_type BallPosition{};
|
||||
vector_type BallAcceleration{};
|
||||
vector3 BallAcceleration{};
|
||||
float ThrowAngleMult;
|
||||
float ThrowSpeedMult1;
|
||||
float ThrowSpeedMult2;
|
||||
|
@ -390,7 +390,7 @@ int loader::kicker(int groupIndex, visualKickerStruct* kicker)
|
||||
kicker->ThrowBallMult = *floatArr;
|
||||
break;
|
||||
case 404:
|
||||
kicker->ThrowBallAcceleration = *reinterpret_cast<vector_type*>(floatArr);
|
||||
kicker->ThrowBallAcceleration = *reinterpret_cast<vector3*>(floatArr);
|
||||
floatArr += 3;
|
||||
index += 4;
|
||||
break;
|
||||
|
@ -25,7 +25,7 @@ struct visualKickerStruct
|
||||
float Threshold;
|
||||
float Boost;
|
||||
float ThrowBallMult;
|
||||
vector_type ThrowBallAcceleration;
|
||||
vector3 ThrowBallAcceleration;
|
||||
float ThrowBallAngleMult;
|
||||
int HardHitSoundId;
|
||||
};
|
||||
|
@ -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<vector_type*>(&planePtr->V1),
|
||||
vec2 = reinterpret_cast<vector_type*>(&planePtr->V2),
|
||||
vec3 = reinterpret_cast<vector_type*>(&planePtr->V3);
|
||||
auto vec1 = &planePtr->V1,
|
||||
vec2 = &planePtr->V2,
|
||||
vec3 = &planePtr->V3;
|
||||
auto distance = Distance(&wallStart, vec1) + Distance(&wallEnd, vec2);
|
||||
if (distance < maxDistance)
|
||||
{
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user