Skip to content

Commit 919d5da

Browse files
committed
physics refactore in progress, things are broken and nothing works properly
1 parent 3a6eeea commit 919d5da

18 files changed

Lines changed: 180 additions & 100 deletions

src/Box2D_Helpers.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#pragma once
2+
3+
namespace box2d
4+
{
5+
// simple wrapper for seamlessly cast between math libraries
6+
struct vec2: public b2Vec2
7+
{
8+
public:
9+
vec2() = default;
10+
vec2(float xIn, float yIn): b2Vec2(xIn, yIn)
11+
{
12+
}
13+
template<typename TVec2>
14+
vec2(const TVec2& in_vec2): b2Vec2(in_vec2.x, in_vec2.y)
15+
{
16+
}
17+
template<typename TVec2>
18+
inline vec2& operator = (const TVec2& in_vec2)
19+
{
20+
x = in_vec2.x;
21+
y = in_vec2.y;
22+
return *this;
23+
}
24+
inline operator glm::vec2 () const
25+
{
26+
return {x, y};
27+
}
28+
};
29+
30+
31+
static const vec2 NullVector { 0.0f, 0.0f };
32+
static const vec2 ForwardVector (1.0f, 0.0f);
33+
static const vec2 LateralVector (0.0f, 1.0f);
34+
35+
} // namespace box2d

src/Carnage3D.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@
154154
</ItemDefinitionGroup>
155155
<ItemGroup>
156156
<ClInclude Include="AiCharacterController.h" />
157+
<ClInclude Include="Box2D_Helpers.h" />
157158
<ClInclude Include="common_utils.h" />
158159
<ClInclude Include="Convert.h" />
159160
<ClInclude Include="game_version.h" />

src/Carnage3D.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,9 @@
329329
<ClInclude Include="math_utils.h">
330330
<Filter>Lib</Filter>
331331
</ClInclude>
332+
<ClInclude Include="Box2D_Helpers.h">
333+
<Filter>Game\Physics</Filter>
334+
</ClInclude>
332335
</ItemGroup>
333336
<ItemGroup>
334337
<ClCompile Include="stdafx.cpp">

src/CarnageGame.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ bool CarnageGame::StartScenario(const std::string& mapName)
344344
{
345345
pos[currFindPosIter].x += 0.5f;
346346
pos[currFindPosIter].z += 0.5f;
347-
pos[currFindPosIter].y = currHeight;
347+
pos[currFindPosIter].y = currHeight * 4;
348348
++currFindPosIter;
349349
}
350350
}

src/Convert.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,52 @@ class Convert
9090
MapUnitsToPixels(units.z)
9191
};
9292
}
93+
94+
// Convert pixels directly to meters
95+
static float PixelsToMeters(int pixels)
96+
{
97+
return ((1.0f * pixels) / PIXELS_PER_MAP_UNIT) * METERS_PER_MAP_UNIT;
98+
}
99+
100+
// Convert meters directly to pixels
101+
static int MetersToPixels(float meters)
102+
{
103+
return (int) ((meters / METERS_PER_MAP_UNIT) * PIXELS_PER_MAP_UNIT);
104+
}
105+
106+
// Convert pixels directly to meters
107+
static glm::vec2 PixelsToMeters(const glm::ivec2& pixels)
108+
{
109+
return {
110+
PixelsToMeters(pixels.x),
111+
PixelsToMeters(pixels.y)
112+
};
113+
}
114+
static glm::vec3 PixelsToMeters(const glm::ivec3& pixels)
115+
{
116+
return {
117+
PixelsToMeters(pixels.x),
118+
PixelsToMeters(pixels.y),
119+
PixelsToMeters(pixels.z)
120+
};
121+
}
122+
123+
// Convert meters directly to pixels
124+
static glm::ivec2 MetersToPixels(const glm::vec2& meters)
125+
{
126+
return {
127+
MetersToPixels(meters.x),
128+
MetersToPixels(meters.y)
129+
};
130+
}
131+
static glm::ivec3 MetersToPixels(const glm::vec3& meters)
132+
{
133+
return {
134+
MetersToPixels(meters.x),
135+
MetersToPixels(meters.y),
136+
MetersToPixels(meters.z)
137+
};
138+
}
93139
};
94140

95141
// in original gta1 map height levels is counting from top to bottom -

src/FollowCameraController.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
#include "TimeManager.h"
77

88
FollowCameraController::FollowCameraController()
9-
: mStartupCameraHeight(8.0f)
10-
, mFollowPedCameraHeight(5.0f)
11-
, mFollowPedCameraCatchSpeed(5.0f)
9+
: mStartupCameraHeight(32.0f)
10+
, mFollowPedCameraHeight(20.0f)
11+
, mFollowPedCameraCatchSpeed(20.0f)
1212
, mScrollHeightOffset()
1313
{
1414
}

src/FollowCameraController.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ class FollowCameraController final: public CameraController
2424

2525
private:
2626
// parameters
27-
float mStartupCameraHeight;
28-
float mFollowPedCameraHeight;
29-
float mScrollHeightOffset;
30-
float mFollowPedCameraCatchSpeed;
27+
float mStartupCameraHeight; // meters
28+
float mFollowPedCameraHeight; // meters
29+
float mScrollHeightOffset; // meters
30+
float mFollowPedCameraCatchSpeed; // meters per second
3131

3232
Pedestrian* mFollowPedestrian = nullptr;
3333
};

src/FreeLookCameraController.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void FreeLookCameraController::UpdateFrame()
4949
{
5050
moveDirection -= mCamera->mRightDirection;
5151
}
52-
moveDirection = glm::normalize(moveDirection) * 5.0f * deltaTime;
52+
moveDirection = glm::normalize(moveDirection) * mMoveSpeed * deltaTime;
5353
mCamera->Translate(moveDirection);
5454
}
5555

src/FreeLookCameraController.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ class FreeLookCameraController final: public CameraController
2424
int mLastMouseX, mLastMouseY;
2525
int mRotateDeltaX, mRotateDeltaY;
2626
bool mMouseDragCamera;
27+
float mMoveSpeed = 20.0f; // meters per second
2728
};

src/GameDefs.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// side length of block cube, do not change
66
#define MAP_BLOCK_TEXTURE_DIMS 64
77
#define MAP_BLOCK_TEXTURE_AREA (MAP_BLOCK_TEXTURE_DIMS * MAP_BLOCK_TEXTURE_DIMS)
8+
89
#define MAX_MAP_BLOCK_ANIM_FRAMES 32
910
#define MAX_CAR_DOORS 4
1011
#define MAX_CAR_REMAPS 12
@@ -19,7 +20,7 @@
1920
#define METERS_PER_MAP_UNIT (4.0f)
2021

2122
#define SPRITE_ZERO_ANGLE 90.0f // all sprites in game are rotated at 90 degrees
22-
#define SPRITE_SCALE (1.0f / PIXELS_PER_MAP_UNIT)
23+
#define SPRITE_SCALE (METERS_PER_MAP_UNIT / PIXELS_PER_MAP_UNIT)
2324

2425
#define PED_SPRITE_DRAW_BOX_SIZE_PX 24 // with, height
2526
#define PED_SPRITE_DRAW_BOX_SIZE ((1.0f * PED_SPRITE_DRAW_BOX_SIZE_PX) / MAP_BLOCK_TEXTURE_DIMS)

0 commit comments

Comments
 (0)