Skip to content

Instantly share code, notes, and snippets.

@comefrombottom
comefrombottom / layoutRect.cpp
Last active October 3, 2025 08:37
UIレイアウトのAnkerの概念を取り入れ、rectを元に配置するrectを求める関数
# include <Siv3D.hpp> // Siv3D v0.6.16
constexpr RectF layoutRect(const RectF& rect, double width, double height)
{
return RectF(Arg::center = rect.center(), width, height);
}
constexpr RectF layoutRect(const RectF& rect, Arg::left_<double> left, double width, double height)
{
@comefrombottom
comefrombottom / GlassRefraction.cpp
Last active September 22, 2025 12:54
iOSのLiquidGlassみたいな屈折をSiv3D+HLSLで再現
# include <Siv3D.hpp> // Siv3D v0.6.16
struct Refraction {
Float2 uvPos;
Float2 uvSize;
};
// 近傍のcircleの縁からpointへの内向き法線ベクトルと距離を計算する
std::pair<Vec2, double> calcInnerNormalDistance(const Vec2& point, const Circle& circle) {
Vec2 dir = point - circle.center;
@comefrombottom
comefrombottom / HashCashe.cpp
Created August 28, 2025 02:41
HashCacheと暗黙の型変換
# include <Siv3D.hpp>
// Tがstd::hashを持つかをチェックするコンセプト
template <typename T>
concept is_std_hashable = requires(const T & val) {
{ std::hash<T>{}(val) } -> std::same_as<std::size_t>;
};
// ハッシュ値をキャッシュするラッパークラス
template <typename T>
@comefrombottom
comefrombottom / makeSmoothRoundRect.cpp
Created June 16, 2025 15:50
roundRectを少し綺麗にします。毎フレーム実行しても大丈夫なくらい高速です。
# include <Siv3D.hpp> // Siv3D v0.6.16
Shape2D makeSmoothShape(const RoundRect& roundRect) {
//頂点と三角形インデックスのサンプルをキャッシュ
static Array<Float2> sampleVertices;
static Array<TriangleIndex> sampleIndices;
constexpr Vec2 sampleSize{ 4,4 };
# include <Siv3D.hpp> // Siv3D v0.6.16
void Main()
{
Window::Resize(800, 800);
Scene::SetBackground(Palette::Black);
Font font(FontMethod::MSDF, 30, Typeface::Heavy);
@comefrombottom
comefrombottom / ScrollBar.cpp
Created December 3, 2024 07:41
[Siv3D]: Camera2Dのように.createTransformer()して使うスクロールバー
# include <Siv3D.hpp> // Siv3D v0.6.15
struct ScrollBar
{
RectF moveArea;
Optional<double> dragOffset;
double viewHeight = 600;
double pageHeight = 1000;
double viewTop = 0;
@comefrombottom
comefrombottom / AnimeText.cpp
Created November 25, 2024 17:20
3Blue1Brown like font animation on Siv3D
# include <Siv3D.hpp> // Siv3D v0.6.15
struct AnimeGlyph : Glyph
{
Array<std::pair<LineString,double>> lines;
static constexpr double lineSpeed = 3;
AnimeGlyph(const Glyph& glyph, const Array<LineString> lineStrings)
: Glyph( glyph ), lines(lineStrings.map([](const LineString& lineString) { return std::make_pair(lineString, lineString.calculateLength()); }))
@comefrombottom
comefrombottom / GatheringParticles.cpp
Created August 9, 2024 20:29
Tanhを使った遊び
# include <Siv3D.hpp>
struct Particle
{
Vec2 pos{};
Vec2 vel{};
};
void Main()
{
@comefrombottom
comefrombottom / GaussianBlur.cpp
Last active August 2, 2024 13:45
パラメータtに応じてぼかしの強さを動的に変えられるサンプル
# include <Siv3D.hpp>
//与えるTextureは全て異なるものである必要がある。
void GaussianBlur(const TextureRegion& from, const RenderTexture& internalBuffer, const RenderTexture& internalBuffer2, const RenderTexture& to,
double t = 1.0, BoxFilterSize boxFilterSize = BoxFilterSize::BoxFilter9x9)
{
//t=0,1,2,4,8,16,32...ごとに区切り、ミックスする。tは何倍縮小してぼかしをかけるかを表す。0の場合はそのまま描画する。
double floor_t = 0;
double ceil_t = 1;
@comefrombottom
comefrombottom / Main.cpp
Created August 1, 2024 13:03
Siv3Dで3Dの鏡。対面にカメラをおいて撮影したものを鏡に映している。鏡の裏側の物が映らないようにしている。
# include <Siv3D.hpp>
class Mirror {
public:
Mesh mesh;
Vec3 offset{};
Quaternion quaternion;
Mirror() = default;