Skip to content

Commit c485256

Browse files
committed
-
1 parent 3bf815e commit c485256

11 files changed

Lines changed: 226 additions & 101 deletions

src/GameCamera.h

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,26 @@ class GameCamera final
2222

2323
Rect mViewportRect;
2424

25+
// projection parameters
26+
27+
struct PerspectiveParams
28+
{
29+
float mAspect = 1.0f;
30+
float mFovy = 1.0f;
31+
float mNearPlane = 1.0;
32+
float mFarPlane = 1.0;
33+
};
34+
PerspectiveParams mPerspectiveParams;
35+
36+
struct OrthographicParams
37+
{
38+
float mLeftP = 1.0f;
39+
float mRightP = 1.0;
40+
float mBottomP = 1.0;
41+
float mTopP = 1.0;
42+
};
43+
OrthographicParams mOrthographicParams;
44+
2545
public:
2646
GameCamera();
2747

@@ -75,26 +95,6 @@ class GameCamera final
7595
private:
7696
bool mProjMatrixDirty; // projection matrix need recomputation
7797
bool mViewMatrixDirty; // view matrix need recomputation
78-
79-
// projection parameters
80-
81-
struct PerspectiveParams
82-
{
83-
float mAspect = 1.0f;
84-
float mFovy = 1.0f;
85-
float mNearPlane = 1.0;
86-
float mFarPlane = 1.0;
87-
};
88-
PerspectiveParams mPerspectiveParams;
89-
90-
struct OrthographicParams
91-
{
92-
float mLeftP = 1.0f;
93-
float mRightP = 1.0;
94-
float mBottomP = 1.0;
95-
float mTopP = 1.0;
96-
};
97-
OrthographicParams mOrthographicParams;
9898
};
9999

100100
// defines ui camera

src/MapRenderer.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@ struct MapRenderStats
1515
void FrameEnd();
1616

1717
public:
18-
unsigned int mRenderFramesCounter = 0; // gets incremented on every frame
18+
int mBlockChunksDrawnCount = 0; // per frame
19+
int mSpritesDrawnCount = 0; // per frame
1920

20-
// per frame
21-
int mBlockChunksDrawnCount = 0;
22-
int mSpritesDrawnCount = 0;
21+
unsigned int mRenderFramesCounter = 0; // gets incremented on every frame
2322
};
2423

2524
// renders map mesh, peds, cars and map objects

src/Pedestrian.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Pedestrian::~Pedestrian()
2525

2626
if (mPhysicsBody)
2727
{
28-
gPhysics.DestroyPhysicsBody(mPhysicsBody);
28+
gPhysics.DestroyPhysicsObject(mPhysicsBody);
2929
}
3030
}
3131

@@ -47,7 +47,7 @@ void Pedestrian::Spawn(const glm::vec3& startPosition, cxx::angle_t startRotatio
4747

4848
if (mPhysicsBody == nullptr)
4949
{
50-
mPhysicsBody = gPhysics.CreatePhysicsBody(this, startPosition, startRotation);
50+
mPhysicsBody = gPhysics.CreatePhysicsObject(this, startPosition, startRotation);
5151
debug_assert(mPhysicsBody);
5252
}
5353
else
@@ -370,7 +370,7 @@ void Pedestrian::SetDead(ePedestrianDeathReason deathReason)
370370
}
371371
}
372372

373-
void Pedestrian::ReceiveDamageFromCar(Vehicle* targetCar, float impulse)
373+
void Pedestrian::ReceiveDamageFromCar(Vehicle* targetCar)
374374
{
375375
debug_assert(targetCar);
376376

src/Pedestrian.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class Pedestrian final: public GameObject
7171

7272
// Get damage from vehicle, it may be ignored depending on its current state
7373
// @param impulse: Impact value
74-
void ReceiveDamageFromCar(Vehicle* targetCar, float impulse);
74+
void ReceiveDamageFromCar(Vehicle* targetCar);
7575

7676
// check if pedestrian entering/exiting or driving car at this moment
7777
bool IsCarPassenger() const;

src/PhysicsComponents.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,20 @@ glm::vec2 PhysicsBody::GetLinearVelocity() const
104104
return { b2velocity.x, b2velocity.y };
105105
}
106106

107+
glm::vec2 PhysicsBody::GetLinearVelocityFromWorldPoint(const glm::vec2& worldPosition) const
108+
{
109+
box2d::vec2 b2point = worldPosition;
110+
box2d::vec2 b2vec = mPhysicsBody->GetLinearVelocityFromWorldPoint(b2point);
111+
return b2vec;
112+
}
113+
114+
glm::vec2 PhysicsBody::GetLinearVelocityFromLocalPoint(const glm::vec2& localPosition) const
115+
{
116+
box2d::vec2 b2point = localPosition;
117+
box2d::vec2 b2vec = mPhysicsBody->GetLinearVelocityFromLocalPoint(b2point);
118+
return b2vec;
119+
}
120+
107121
cxx::angle_t PhysicsBody::GetAngularVelocity() const
108122
{
109123
cxx::angle_t angularVelocity = cxx::angle_t::from_radians(mPhysicsBody->GetAngularVelocity());
@@ -352,6 +366,7 @@ CarPhysicsBody::CarPhysicsBody(b2World* physicsWorld, Vehicle* object)
352366
fixtureDef.shape = &shapeDef;
353367
fixtureDef.density = 1.0f;
354368
fixtureDef.friction = 0.0f;
369+
fixtureDef.restitution = 0.4f;
355370
fixtureDef.filter.categoryBits = PHYSICS_OBJCAT_CAR;
356371

357372
mChassisFixture = mPhysicsBody->CreateFixture(&fixtureDef);
@@ -417,6 +432,17 @@ void CarPhysicsBody::GetChassisCorners(glm::vec2 corners[4]) const
417432
}
418433
}
419434

435+
void CarPhysicsBody::GetLocalChassisCorners(glm::vec2 corners[4]) const
436+
{
437+
const b2PolygonShape* shape = (const b2PolygonShape*) mChassisFixture->GetShape();
438+
debug_assert(shape->m_count == 4);
439+
for (int icorner = 0; icorner < 4; ++icorner)
440+
{
441+
box2d::vec2 point = shape->m_vertices[icorner];
442+
corners[icorner] = point;
443+
}
444+
}
445+
420446
void CarPhysicsBody::GetWheelCorners(eCarWheel wheelID, glm::vec2 corners[4]) const
421447
{
422448
debug_assert(wheelID < eCarWheel_COUNT);

src/PhysicsComponents.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ class PhysicsBody: public cxx::noncopyable
5656
/// @param velocity: New linear velocity of the center of mass, meters per second
5757
void SetLinearVelocity(const glm::vec2& velocity);
5858
glm::vec2 GetLinearVelocity() const;
59+
glm::vec2 GetLinearVelocityFromWorldPoint(const glm::vec2& worldPosition) const;
60+
glm::vec2 GetLinearVelocityFromLocalPoint(const glm::vec2& localPosition) const;
5961
glm::vec2 GetSignVector() const;
6062

6163
// Convert coordinate from local to world space and vice versa
@@ -161,6 +163,7 @@ class CarPhysicsBody: public PhysicsBody
161163
void HandleWaterContact();
162164

163165
void GetChassisCorners(glm::vec2 corners[4]) const;
166+
void GetLocalChassisCorners(glm::vec2 corners[4]) const;
164167
void GetWheelCorners(eCarWheel wheelID, glm::vec2 corners[4]) const;
165168

166169
// steering
@@ -198,6 +201,7 @@ class CarPhysicsBody: public PhysicsBody
198201
b2Vec2 b2GetWheelLocalPoint(eCarWheel wheelID) const;
199202
b2Vec2 b2GetWheelLocalForwardVector(eCarWheel wheelID) const;
200203
b2Vec2 b2GetWheelLocalLateralVector(eCarWheel wheelID) const;
204+
201205
private:
202206
CarStyle* mCarDesc = nullptr;
203207
b2Fixture* mChassisFixture = nullptr;

0 commit comments

Comments
 (0)