Engine²
Open-source game engine written in C++.
Loading...
Searching...
No Matches
SphereCollider.hpp
Go to the documentation of this file.
1/**************************************************************************
2 * EngineSquared v0.1.1
3 *
4 * EngineSquared is a software package, part of the Engine² organization.
5 *
6 * This file is part of the EngineSquared project that is under MIT License.
7 * Copyright © 2025-present by @EngineSquared, All rights reserved.
8 *
9 * EngineSquared is a free software: you can redistribute it and/or modify
10 * it under the terms of the MIT License. See the project's LICENSE file for
11 * the full license text and details.
12 *
13 * @file SphereCollider.hpp
14 * @brief Sphere collision shape component
15 *
16 * User-specified sphere collider for physics simulation.
17 * Spheres are the most efficient collision shape.
18 *
19 * @author @EngineSquared
20 * @version 0.1.1
21 * @date 2025-12-05
22 **************************************************************************/
23
24#pragma once
25
26#include <glm/vec3.hpp>
27
28namespace Physics::Component {
29
58 float radius = 0.5f;
59
61 glm::vec3 offset{0.0f, 0.0f, 0.0f};
62
66 SphereCollider() = default;
67
72 explicit SphereCollider(float r) : radius(r) {}
73
79 SphereCollider(float r, const glm::vec3 &localOffset) : radius(r), offset(localOffset) {}
80
85 [[nodiscard]] float GetDiameter() const { return radius * 2.0f; }
86
91 void SetDiameter(float diameter) { radius = diameter * 0.5f; }
92
97 [[nodiscard]] bool IsValid() const { return radius > 0.0f; }
98
99 //=========================================================================
100 // Factory methods
101 //=========================================================================
102
107 static SphereCollider Unit() { return SphereCollider(1.0f); }
108
114 static SphereCollider Ball(float r) { return SphereCollider(r); }
115
122 static SphereCollider AtOffset(float r, const glm::vec3 &localOffset) { return SphereCollider(r, localOffset); }
123};
124
125} // namespace Physics::Component
Definition BoxCollider.hpp:27
static SphereCollider Unit()
Create a unit sphere (radius 1.0).
Definition SphereCollider.hpp:107
static SphereCollider AtOffset(float r, const glm::vec3 &localOffset)
Create a sphere at an offset (useful for compound shapes).
Definition SphereCollider.hpp:122
float GetDiameter() const
Get diameter of the sphere.
Definition SphereCollider.hpp:85
static SphereCollider Ball(float r)
Create a sphere for a ball/projectile.
Definition SphereCollider.hpp:114
SphereCollider(float r, const glm::vec3 &localOffset)
Construct with radius and offset.
Definition SphereCollider.hpp:79
glm::vec3 offset
Local offset from entity transform (center of sphere).
Definition SphereCollider.hpp:61
SphereCollider(float r)
Construct with radius.
Definition SphereCollider.hpp:72
bool IsValid() const
Check if collider is valid.
Definition SphereCollider.hpp:97
SphereCollider()=default
Default constructor (radius 0.5).
void SetDiameter(float diameter)
Set diameter directly (converts to radius).
Definition SphereCollider.hpp:91
float radius
Radius of the sphere in world units.
Definition SphereCollider.hpp:58