Skip to content

Commit 40fef48

Browse files
committed
rafactore car physics, it is completely broken now
1 parent 995c96a commit 40fef48

8 files changed

Lines changed: 302 additions & 265 deletions

File tree

src/Box2D_Helpers.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ namespace box2d
2525
{
2626
return {x, y};
2727
}
28+
inline vec2 operator * (float scalar) const
29+
{
30+
return {x * scalar, y * scalar};
31+
}
2832
};
2933

3034

src/GameCheatsWindow.cpp

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@
66
#include "CarnageGame.h"
77
#include "Pedestrian.h"
88

9+
namespace ImGui
10+
{
11+
inline void HorzSpacing(float spacingSize = 10.0f)
12+
{
13+
Dummy(ImVec2(0.0f, spacingSize));
14+
}
15+
inline void VertSpacing(float spacingSize = 10.0f)
16+
{
17+
Dummy(ImVec2(spacingSize, 0.0f));
18+
}
19+
}
20+
921
GameCheatsWindow gGameCheatsWindow;
1022

1123
GameCheatsWindow::GameCheatsWindow()
@@ -66,7 +78,7 @@ void GameCheatsWindow::DoUI(ImGuiIO& imguiContext)
6678
// pedestrian stats
6779
if (Pedestrian* pedestrian = gCarnageGame.mHumanSlot[0].mCharPedestrian)
6880
{
69-
ImGui::Separator();
81+
ImGui::HorzSpacing();
7082
glm::vec3 pedPosition = pedestrian->mPhysicsComponent->GetPosition();
7183
ImGui::Text("physical pos: %.3f, %.3f, %.3f", pedPosition.x, pedPosition.y, pedPosition.z);
7284
glm::vec3 logicalPosition = Convert::MetersToMapUnits(pedPosition);
@@ -76,7 +88,7 @@ void GameCheatsWindow::DoUI(ImGuiIO& imguiContext)
7688
ImGui::Text("heading: %f", pedHeading.mDegrees);
7789
ImGui::Text("weapon: %s", cxx::enum_to_string(pedestrian->mCurrentWeapon));
7890
ImGui::Text("state: %s", cxx::enum_to_string(pedestrian->GetCurrentStateID()));
79-
ImGui::Separator();
91+
ImGui::HorzSpacing();
8092

8193
// get block location
8294
glm::ivec3 blockPosition = Convert::MetersToMapUnits(pedPosition);
@@ -88,7 +100,7 @@ void GameCheatsWindow::DoUI(ImGuiIO& imguiContext)
88100
ImGui::Text("b directions: %d, %d, %d, %d", currBlock->mUpDirection, currBlock->mRightDirection,
89101
currBlock->mDownDirection, currBlock->mLeftDirection);
90102

91-
ImGui::Separator();
103+
ImGui::HorzSpacing();
92104
ImGui::SliderInt("ped remap", &pedestrian->mRemapIndex, -1, MAX_PED_REMAPS - 1);
93105

94106
if (pedestrian->IsCarPassenger())
@@ -131,12 +143,11 @@ void GameCheatsWindow::DoUI(ImGuiIO& imguiContext)
131143
ImGui::EndCombo();
132144
}
133145

134-
if (ImGui::CollapsingHeader("Physics"))
135-
{
136-
ImGui::Checkbox("Enable map collisions", &mEnableMapCollisions);
137-
ImGui::Checkbox("Enable gravity", &mEnableGravity);
138-
ImGui::Separator();
139-
}
146+
//if (ImGui::CollapsingHeader("Physics"))
147+
//{
148+
// ImGui::Checkbox("Enable map collisions", &mEnableMapCollisions);
149+
// ImGui::Checkbox("Enable gravity", &mEnableGravity);
150+
//}
140151

141152
if (ImGui::CollapsingHeader("Map Draw"))
142153
{
@@ -155,6 +166,34 @@ void GameCheatsWindow::DoUI(ImGuiIO& imguiContext)
155166
Convert::MapUnitsToMeters(16.0f), "%.2f");
156167
}
157168

169+
if (Pedestrian* pedestrian = gCarnageGame.mHumanSlot[0].mCharPedestrian)
170+
{
171+
if (Vehicle* currCar = pedestrian->mCurrentCar)
172+
{
173+
CarStyle* carInformation = currCar->mCarStyle;
174+
175+
if (ImGui::CollapsingHeader("Vehicle Info"))
176+
{
177+
ImVec4 physicsPropsColor(0.75f, 0.75f, 0.75f, 1.0f);
178+
ImGui::Text("VType - %s", cxx::enum_to_string(carInformation->mVType));
179+
ImGui::HorzSpacing();
180+
ImGui::TextColored(physicsPropsColor, "Turning : %d", carInformation->mTurning);
181+
ImGui::TextColored(physicsPropsColor, "Turn Ratio : %d", carInformation->mTurnRatio);
182+
ImGui::TextColored(physicsPropsColor, "Moment : %d", carInformation->mMoment);
183+
ImGui::TextColored(physicsPropsColor, "Mass : %.3f", carInformation->mMass);
184+
ImGui::TextColored(physicsPropsColor, "Thurst : %.3f", carInformation->mThrust);
185+
ImGui::TextColored(physicsPropsColor, "Tyre Adhesion X/Y : %.3f / %.3f", carInformation->mTyreAdhesionX, carInformation->mTyreAdhesionY);
186+
ImGui::HorzSpacing();
187+
ImGui::TextColored(physicsPropsColor, "Handbrake Friction : %.3f", carInformation->mHandbrakeFriction);
188+
ImGui::TextColored(physicsPropsColor, "Footbrake Friction : %.3f", carInformation->mFootbrakeFriction);
189+
ImGui::TextColored(physicsPropsColor, "Front Brake Bias : %.3f", carInformation->mFrontBrakeBias);
190+
ImGui::HorzSpacing();
191+
192+
ImGui::Text("Current velocity : %.3f", currCar->mPhysicsComponent->GetCurrentVelocity());
193+
}
194+
}
195+
}
196+
158197
if (ImGui::CollapsingHeader("Graphics"))
159198
{
160199
if (ImGui::Checkbox("Enable vsync", &gSystem.mConfig.mEnableVSync))

src/GameDefs.h

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#define SPRITE_ZERO_ANGLE 90.0f // all sprites in game are rotated at 90 degrees
2323
#define SPRITE_SCALE (METERS_PER_MAP_UNIT / PIXELS_PER_MAP_UNIT)
2424
#define PED_SPRITE_DRAW_BOX_SIZE_PX 24 // with, height
25+
#define CAR_WHEEL_SIZE_W_PX 6
26+
#define CAR_WHEEL_SIZE_H_PX 12
2527

2628
// in original gta1 map height levels is counting from top to bottom -
2729
// 0 is highest and 5 is lowest level
@@ -565,30 +567,42 @@ struct CarStyle
565567
public:
566568
short mWidth, mHeight, mDepth; // dimensions of the car with respect to collision checking, x, y, z
567569
short mSprNum; // first sprite number offset for this car
568-
short mWeight;
569-
short mMaxSpeed, mMinSpeed;
570-
short mAcceleration, mBraking;
571-
short mGrip, mHandling;
570+
571+
struct // specs, usage is unknown
572+
{
573+
short mWeight;
574+
short mMaxSpeed, mMinSpeed;
575+
short mAcceleration, mBraking;
576+
short mGrip, mHandling;
577+
};
578+
572579
short mRemapsBaseIndex;
573580
HLSRemap mRemap[MAX_CAR_REMAPS];
574581
eCarVType mVType; // is a descriptor of the type of car / vehicle
575582
eCarModel mModelId;
583+
576584
int mTurning;
585+
577586
int mDamagable;
578587
int mValue[4];
579-
char mCx, mCy; // pixel co-ordinates of the centre of mass of the car, relative to the graphical centre
580-
int mMoment;
581-
float mRbpMass;
582-
float mG1Thrust;
583-
float mTyreAdhesionX, mTyreAdhesionY;
584-
float mHandbrakeFriction;
585-
float mFootbrakeFriction;
586-
float mFrontBrakeBias;
587-
short mTurnRatio;
588-
short mDriveWheelOffset;
589-
short mSteeringWheelOffset;
590-
float mBackEndSlideValue;
591-
float mHandbrakeSlideValue;
588+
589+
struct // physics props
590+
{
591+
char mCx, mCy; // pixel co-ordinates of the centre of mass of the car, relative to the graphical centre
592+
int mMoment; // moment of inertia
593+
float mMass;
594+
float mThrust; // 1st gear thrust
595+
float mTyreAdhesionX, mTyreAdhesionY;
596+
float mHandbrakeFriction;
597+
float mFootbrakeFriction;
598+
float mFrontBrakeBias;
599+
short mTurnRatio;
600+
short mDriveWheelOffset;
601+
short mSteeringWheelOffset;
602+
float mBackEndSlideValue;
603+
float mHandbrakeSlideValue;
604+
};
605+
592606
eCarConvertible mConvertible;
593607
int mEngine;
594608
int mRadio;

src/Pedestrian.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,12 @@ void Pedestrian::DrawFrame(SpriteBatch& spriteBatch)
116116

117117
void Pedestrian::DrawDebug(DebugRenderer& debugRender)
118118
{
119-
glm::vec3 position = mPhysicsComponent->GetPosition();
120-
121-
glm::vec2 signVector = mPhysicsComponent->GetSignVector() * gGameParams.mPedestrianSpotTheCarDistance;
122-
123-
debugRender.DrawLine(position, position + glm::vec3(signVector.x, 0.0f, signVector.y), Color32_White, false);
119+
if (mCurrentCar == nullptr)
120+
{
121+
glm::vec3 position = mPhysicsComponent->GetPosition();
122+
glm::vec2 signVector = mPhysicsComponent->GetSignVector() * gGameParams.mPedestrianSpotTheCarDistance;
123+
debugRender.DrawLine(position, position + glm::vec3(signVector.x, 0.0f, signVector.y), Color32_White, false);
124+
}
124125
}
125126

126127
void Pedestrian::ComputeDrawHeight(const glm::vec3& position)

0 commit comments

Comments
 (0)