Skip to content

Commit d17a8a5

Browse files
authored
Merge pull request #154 from AsPJT/feature/ref-draw
GRAPHICAのVec2を削除
2 parents 32217e1 + eae076a commit d17a8a5

98 files changed

Lines changed: 2896 additions & 2022 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Library/PAX_GRAPHICA/3DModel.hpp

Lines changed: 40 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -12,205 +12,93 @@
1212
#ifndef PAX_MAHOROBA_3D_MODEL_HPP
1313
#define PAX_MAHOROBA_3D_MODEL_HPP
1414

15+
#include <memory>
16+
17+
#include <PAX_GRAPHICA/Interface/Graphics3DModelImpl.hpp>
18+
1519
#if defined(PAXS_USING_SIV3D)
16-
#include <Siv3D.hpp>
17-
#elif defined(PAXS_USING_DXLIB)
18-
#include <DxLib.h>
19-
#elif defined(PAXS_USING_SFML)
20-
#include <SFML/Graphics.hpp>
20+
#include <PAX_GRAPHICA/Siv3D/Siv3DGraphics3DModelImpl.hpp>
21+
#else
22+
#include <PAX_GRAPHICA/Null/NullGraphics3DModelImpl.hpp>
2123
#endif
2224

23-
#include <PAX_SAPIENTICA/Core/Math/Math.hpp>
24-
#include <PAX_SAPIENTICA/System/AppConfig.hpp>
25-
2625
namespace paxg {
2726

28-
/// @brief 3D モデル描画の設定
29-
struct Graphics3DModelConfig {
30-
/// @brief カメラ設定
31-
struct Camera {
32-
/// @brief 垂直視野角(度)
33-
double verticalFOV = 40.0;
34-
double posX = 0.0;
35-
double posY = 3.0;
36-
double posZ = -16.0;
37-
} camera;
38-
39-
/// @brief 背景色設定
40-
struct Background {
41-
float r = 1.0f; // 赤成分
42-
float g = 1.0f; // 緑成分
43-
float b = 1.0f; // 青成分
44-
float a = 0.0f; // 透明度
45-
} background;
46-
47-
/// @brief ファイルパス設定
48-
struct FilePaths {
49-
std::string modelPath = "Data/3DModels/KofunOBJ/Model/Sekishitsu/KamoKitaKofun/KamoKitaKofun.obj";
50-
} paths;
51-
52-
/// @brief モデルの回転速度(度/フレーム)
53-
double rotationSpeed = 1.0;
54-
};
55-
56-
/// @brief 3D モデル描画クラス
27+
/// @brief 3D モデル描画クラス with Pimpl idiom for graphics library abstraction
28+
/// @note Uses unique_ptr for implementation hiding and automatic resource management
5729
class Graphics3DModel {
5830
private:
5931
Graphics3DModelConfig config_;
32+
std::unique_ptr<Graphics3DModelImpl> impl_;
6033

61-
#ifdef PAXS_USING_SIV3D
62-
// 回転角度
63-
int rotation_ = 0;
64-
65-
s3d::ColorF backgroundColor_;
66-
67-
// 3D モデルデータ
68-
s3d::Model model_;
69-
70-
// 描画するテクスチャの設定
71-
mutable s3d::MSRenderTexture renderTexture_;
72-
73-
// カメラ
74-
mutable s3d::DebugCamera3D camera_;
34+
/// @brief Create implementation based on the active graphics library
35+
/// @param cfg Configuration for 3D model
36+
/// @return Unique pointer to the implementation
37+
static std::unique_ptr<Graphics3DModelImpl> createImpl(const Graphics3DModelConfig& cfg) {
38+
#if defined(PAXS_USING_SIV3D)
39+
return std::make_unique<Siv3DGraphics3DModelImpl>(cfg);
40+
#else
41+
return std::make_unique<NullGraphics3DModelImpl>(cfg);
7542
#endif
43+
}
7644

7745
public:
7846
/// @brief デフォルト設定でコンストラクタ
7947
Graphics3DModel() : Graphics3DModel(Graphics3DModelConfig{}) {}
8048

8149
/// @brief カスタム設定でコンストラクタ
82-
explicit Graphics3DModel(const Graphics3DModelConfig& cfg) : config_(cfg) {
83-
#ifdef PAXS_USING_SIV3D
84-
// カメラ設定
85-
camera_ = s3d::DebugCamera3D{
86-
s3d::Graphics3D::GetRenderTargetSize(),
87-
paxs::Math<double>::degToRad(config_.camera.verticalFOV),
88-
s3d::Vec3{ config_.camera.posX, config_.camera.posY, config_.camera.posZ }
89-
};
90-
91-
renderTexture_ = s3d::MSRenderTexture{
92-
s3d::Size{s3d::Scene::Width(), s3d::Scene::Height()},
93-
s3d::TextureFormat::R8G8B8A8_Unorm_SRGB,
94-
s3d::HasDepth::Yes
95-
};
96-
97-
// 背景色を設定
98-
backgroundColor_ = s3d::ColorF{
99-
config_.background.r,
100-
config_.background.g,
101-
config_.background.b,
102-
config_.background.a
103-
}.removeSRGBCurve();
104-
105-
// 3D モデルデータをロード
106-
const auto rootPath = s3d::Unicode::FromUTF8(paxs::AppConfig::getInstance().getRootPath());
107-
model_ = s3d::Model{ rootPath + s3d::Unicode::FromUTF8(config_.paths.modelPath) };
108-
109-
// モデルに付随するテクスチャをアセット管理に登録
110-
s3d::Model::RegisterDiffuseTextures(model_, s3d::TextureDesc::MippedSRGB);
111-
#endif
112-
}
50+
explicit Graphics3DModel(const Graphics3DModelConfig& cfg)
51+
: config_(cfg), impl_(createImpl(cfg)) {}
11352

11453
/// @brief 回転角度を更新
115-
/// @brief Update rotation angle
11654
void updateRotation() {
117-
#ifdef PAXS_USING_SIV3D
118-
// モデルの回転更新
119-
++rotation_;
120-
if (rotation_ >= 360) rotation_ = 0;
121-
#endif
55+
if (impl_) {
56+
impl_->updateRotation();
57+
}
12258
}
12359

12460
/// @brief 3Dモデルを描画
125-
/// @brief Render 3D model
12661
void render() const {
127-
#ifdef PAXS_USING_SIV3D
128-
s3d::Graphics3D::SetCameraTransform(camera_); // カメラ情報を設定
129-
130-
// 3D シーンの描画
131-
const s3d::ScopedRenderTarget3D target{ renderTexture_.clear(backgroundColor_) };
132-
133-
// 3Dモデルの描画
134-
const s3d::ScopedRenderStates3D renderStates{
135-
s3d::BlendState::OpaqueAlphaToCoverage,
136-
s3d::RasterizerState::SolidCullNone
137-
};
138-
model_.draw(
139-
s3d::Vec3{ 0, 0, 0 },
140-
s3d::Quaternion::RotateY(paxs::Math<double>::degToRad(static_cast<double>(rotation_)))
141-
);
142-
143-
// RenderTexture を 2D シーンに描画
144-
s3d::Graphics3D::Flush(); // 現在までの 3D 描画を実行
145-
146-
// 画面サイズが変更されたら幅を変える
147-
// 毎フレームチェックすると重いため、3フレームに1回チェック
148-
static int resize_check_count = 0;
149-
if (resize_check_count >= 3) {
150-
resize_check_count = 0;
151-
if (renderTexture_.width() != s3d::Scene::Width()
152-
|| renderTexture_.height() != s3d::Scene::Height()) {
153-
renderTexture_ = s3d::MSRenderTexture{
154-
s3d::Size{s3d::Scene::Width(), s3d::Scene::Height()},
155-
s3d::TextureFormat::R8G8B8A8_Unorm_SRGB,
156-
s3d::HasDepth::Yes
157-
};
158-
}
62+
if (impl_) {
63+
impl_->render();
15964
}
160-
++resize_check_count;
161-
162-
renderTexture_.resolve(); // テクスチャを描画可能にする
163-
renderTexture_.draw(0, 0); // 指定した大きさで描画
164-
#endif
16565
}
16666

16767
/// @brief 設定を取得
16868
const Graphics3DModelConfig& getConfig() const { return config_; }
16969

17070
/// @brief 設定を更新
171-
void setConfig(const Graphics3DModelConfig& cfg) { config_ = cfg; }
71+
void setConfig(const Graphics3DModelConfig& cfg) {
72+
config_ = cfg;
73+
impl_ = createImpl(cfg);
74+
}
17275

17376
/// @brief カメラ設定を更新
17477
void setCameraConfig(const Graphics3DModelConfig::Camera& cam) {
17578
config_.camera = cam;
176-
#ifdef PAXS_USING_SIV3D
177-
camera_ = s3d::DebugCamera3D{
178-
s3d::Graphics3D::GetRenderTargetSize(),
179-
paxs::Math<double>::degToRad(config_.camera.verticalFOV),
180-
s3d::Vec3{ config_.camera.posX, config_.camera.posY, config_.camera.posZ }
181-
};
182-
#endif
79+
if (impl_) {
80+
impl_->setCameraConfig(cam);
81+
}
18382
}
18483

18584
/// @brief 背景色設定を更新
18685
void setBackgroundConfig(const Graphics3DModelConfig::Background& bg) {
18786
config_.background = bg;
188-
#ifdef PAXS_USING_SIV3D
189-
backgroundColor_ = s3d::ColorF{
190-
config_.background.r,
191-
config_.background.g,
192-
config_.background.b,
193-
config_.background.a
194-
}.removeSRGBCurve();
195-
#endif
87+
if (impl_) {
88+
impl_->setBackgroundConfig(bg);
89+
}
19690
}
19791

19892
/// @brief 現在の回転角度を取得(度)
19993
int getRotation() const {
200-
#ifdef PAXS_USING_SIV3D
201-
return rotation_;
202-
#else
203-
return 0;
204-
#endif
94+
return impl_ ? impl_->getRotation() : 0;
20595
}
20696

20797
/// @brief 回転角度を設定(度)
20898
void setRotation(int angle) {
209-
#ifdef PAXS_USING_SIV3D
210-
rotation_ = angle % 360;
211-
#else
212-
(void)angle;
213-
#endif
99+
if (impl_) {
100+
impl_->setRotation(angle);
101+
}
214102
}
215103
};
216104

Library/PAX_GRAPHICA/Circle.hpp

Lines changed: 84 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -12,66 +12,108 @@
1212
#ifndef PAX_GRAPHICA_CIRCLE_HPP
1313
#define PAX_GRAPHICA_CIRCLE_HPP
1414

15+
#include <memory>
16+
17+
#include <PAX_GRAPHICA/Color.hpp>
18+
#include <PAX_GRAPHICA/Interface/CircleImpl.hpp>
19+
#include <PAX_SAPIENTICA/Core/Type/Vector2.hpp>
20+
1521
#if defined(PAXS_USING_SIV3D)
16-
#include <Siv3D.hpp>
22+
#include <PAX_GRAPHICA/Siv3D/Siv3DCircleImpl.hpp>
1723
#elif defined(PAXS_USING_DXLIB)
18-
#include <DxLib.h>
24+
#include <PAX_GRAPHICA/DxLib/DxLibCircleImpl.hpp>
1925
#elif defined(PAXS_USING_SFML)
20-
#include <SFML/Graphics.hpp>
21-
#include <PAX_GRAPHICA/SFML_Circle.hpp>
26+
#include <PAX_GRAPHICA/SFML/SFMLCircleImpl.hpp>
27+
#else
28+
#include <PAX_GRAPHICA/Null/NullCircleImpl.hpp>
2229
#endif
2330

24-
#include <PAX_GRAPHICA/Window.hpp>
25-
26-
#include <PAX_SAPIENTICA/Core/Type/Vector2.hpp>
27-
2831
namespace paxg {
2932

30-
struct Circle
31-
{
33+
/// @brief Circle class with Pimpl idiom for graphics library abstraction
34+
/// @note Uses shared_ptr for value semantics and automatic resource management
35+
struct Circle {
36+
private:
37+
std::shared_ptr<CircleImpl> impl;
38+
39+
/// @brief Create implementation based on the active graphics library
40+
/// @param x X-coordinate of the circle center
41+
/// @param y Y-coordinate of the circle center
42+
/// @param r Radius of the circle
43+
/// @return Shared pointer to the implementation
44+
static std::shared_ptr<CircleImpl> createImpl(float x, float y, float r) {
3245
#if defined(PAXS_USING_SIV3D)
33-
s3d::Circle circle;
34-
constexpr Circle(const paxs::Vector2<int>& pos, const float r) : circle(pos.x, pos.y, r) {}
35-
constexpr Circle(const paxs::Vector2<float>& pos, const float r) : circle(pos.x, pos.y, r) {}
36-
constexpr Circle(const paxs::Vector2<double>& pos, const float r) : circle(static_cast<float>(pos.x), static_cast<float>(pos.y), r) {}
37-
constexpr operator s3d::Circle() const { return circle; }
46+
return std::make_shared<Siv3DCircleImpl>(x, y, r);
47+
#elif defined(PAXS_USING_DXLIB)
48+
return std::make_shared<DxLibCircleImpl>(x, y, r);
49+
#elif defined(PAXS_USING_SFML)
50+
return std::make_shared<SFMLCircleImpl>(x, y, r);
3851
#else
39-
float x, y, r;
40-
constexpr Circle(const paxs::Vector2<int>& pos, const float r) : x(static_cast<float>(pos.x)), y(static_cast<float>(pos.y)), r(r) {}
41-
constexpr Circle(const paxs::Vector2<float>& pos, const float r) : x(pos.x), y(pos.y), r(r) {}
42-
constexpr Circle(const paxs::Vector2<double>& pos, const float r) : x(static_cast<float>(pos.x)), y(static_cast<float>(pos.y)), r(r) {}
52+
return std::make_shared<NullCircleImpl>(x, y, r);
4353
#endif
54+
}
55+
56+
public:
57+
/// @brief Constructor with separate x, y coordinates and radius
58+
/// @param x X-coordinate of the circle center
59+
/// @param y Y-coordinate of the circle center
60+
/// @param r Radius of the circle
61+
Circle(float x, float y, float r)
62+
: impl(createImpl(x, y, r)) {}
63+
64+
/// @brief Constructor with Vector2<int> position and radius
65+
/// @param pos Position of the circle center
66+
/// @param r Radius of the circle
67+
Circle(const paxs::Vector2<int>& pos, const float r)
68+
: impl(createImpl(static_cast<float>(pos.x), static_cast<float>(pos.y), r)) {}
69+
70+
/// @brief Constructor with Vector2<float> position and radius
71+
/// @param pos Position of the circle center
72+
/// @param r Radius of the circle
73+
Circle(const paxs::Vector2<float>& pos, const float r)
74+
: impl(createImpl(pos.x, pos.y, r)) {}
75+
76+
/// @brief Constructor with Vector2<double> position and radius
77+
/// @param pos Position of the circle center
78+
/// @param r Radius of the circle
79+
Circle(const paxs::Vector2<double>& pos, const float r)
80+
: impl(createImpl(static_cast<float>(pos.x), static_cast<float>(pos.y), r)) {}
81+
82+
/// @brief Draw the circle without color
4483
void draw() const {
45-
#if defined(PAXS_USING_SIV3D)
46-
circle.draw();
84+
if (impl) {
85+
impl->draw();
86+
}
87+
}
4788

48-
#elif defined(PAXS_USING_SFML)
49-
SFML_Circle::getInstance()->circle.setRadius(r);
50-
SFML_Circle::getInstance()->circle.setPosition({ x, y });
51-
paxg::Window::window().draw(SFML_Circle::getInstance()->circle);
52-
#endif
89+
/// @brief Draw the circle with specified color
90+
/// @param color The color to draw the circle
91+
void draw(const Color& color) const {
92+
if (impl) {
93+
impl->draw(color);
94+
}
5395
}
5496

55-
#if defined(PAXS_USING_SIV3D)
56-
void draw(const paxg::Color& c_) const {
57-
circle.draw(c_.color);
97+
/// @brief Get the position of the circle center
98+
/// @return Position as Vector2<float>
99+
paxs::Vector2<float> getPosition() const {
100+
return impl ? impl->getPosition() : paxs::Vector2<float>(0.0f, 0.0f);
58101
}
59-
#elif defined(PAXS_USING_DXLIB)
60-
void draw(const paxg::Color& c_) const {
61-
DxLib::DrawCircle(
62-
static_cast<int>(x), static_cast<int>(y), static_cast<int>(r),
63-
DxLib::GetColor(c_.r, c_.g, c_.b), TRUE);
102+
103+
/// @brief Get the radius of the circle
104+
float getRadius() const {
105+
return impl ? impl->getRadius() : 0.0f;
64106
}
65-
#elif defined(PAXS_USING_SFML)
66-
void draw(const paxg::Color& c_) const {
67-
SFML_Circle::getInstance()->circle.setRadius(r);
68-
SFML_Circle::getInstance()->circle.setPosition({ x, y });
69107

70-
SFML_Circle::getInstance()->circle.setFillColor(c_.color);
71-
paxg::Window::window().draw(SFML_Circle::getInstance()->circle);
108+
#if defined(PAXS_USING_SIV3D)
109+
/// @brief Conversion operator to s3d::Circle (Siv3D only)
110+
operator s3d::Circle() const {
111+
auto* siv3dImpl = dynamic_cast<Siv3DCircleImpl*>(impl.get());
112+
if (siv3dImpl) {
113+
return siv3dImpl->getNativeCircle();
114+
}
115+
return s3d::Circle(0, 0, 0);
72116
}
73-
#else
74-
void draw(const paxg::Color&) const {}
75117
#endif
76118
};
77119
}

0 commit comments

Comments
 (0)