Skip to content

Instantly share code, notes, and snippets.

@sknjpn
Created July 10, 2017 14:28
Show Gist options
  • Save sknjpn/a955429249fa13cf7fb04e905b0628c0 to your computer and use it in GitHub Desktop.
Save sknjpn/a955429249fa13cf7fb04e905b0628c0 to your computer and use it in GitHub Desktop.
Camera2Dと同様に使えるカメラ。サンプル付き。
# include <Siv3D.hpp> // OpenSiv3D v0.1.5
struct TinyCamera2D
{
TinyCamera2D() = default;
void update()
{
const Transformer2D t1(Mat3x2::Translate(-sRegion.pos).scale(Window::Size().y / sRegion.size.y), true);
//描画領域をマウスホイールで操作する
dRegion = dRegion.scaledAt(Cursor::PosF(), 1 + Mouse::Wheel() / 10.0);
//描画領域のスムーズな変化
sRegion.pos = sRegion.pos*(1 - s) + dRegion.pos*s;
sRegion.size = sRegion.size*(1 - s) + dRegion.size*s;
}
Transformer2D createTransformer() const
{
return Transformer2D(Mat3x2::Translate(-sRegion.pos).scale(Window::Size().y / sRegion.size.y), true);
}
double s = 0.25; //視点追従性
RectF dRegion = RectF(Window::Size()); //仮想描画領域
RectF sRegion = dRegion; //実描画領域
};
void Main()
{
TinyCamera2D camera;
Graphics::SetBackground(ColorF(0.8, 0.9, 1.0));
const Font font(50);
const Texture textureCat(Emoji(L"🐈"), TextureDesc::Mipped);
while (System::Update())
{
camera.update(); //Camera2Dと一緒だが、Transformer2Dは使えない。。。
{
const auto t1 = camera.createTransformer(); //これも一緒
font(L"Hello, Siv3D!🐣").drawAt(Window::Center(), Palette::Black);
font(Cursor::Pos()).draw(20, 400, ColorF(0.6));
textureCat.resize(80).draw(540, 380);
Circle(Cursor::Pos(), 60).draw(ColorF(1, 0, 0, 0.5));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment