Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the odd off-center rotation issue in Danmakufu #81

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions source/GcLib/directx/DirectGraphics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ namespace directx {
static DirectGraphics* thisBase_;
public:
static float g_dxCoordsMul_;
static constexpr float g_dxBias_ = 0.5;
protected:
D3DPRESENT_PARAMETERS d3dppFull_;
D3DPRESENT_PARAMETERS d3dppWin_;
Expand Down
5 changes: 2 additions & 3 deletions source/GcLib/directx/DxObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,8 @@ D3DXVECTOR3 DxScriptPrimitiveObject2D::GetVertexPosition(size_t index) {
RenderObjectTLX* obj = GetRenderObject();
VERTEX_TLX* vert = obj->GetVertex(index);

constexpr float bias = 0.5f;
res.x = vert->position.x + bias;
res.y = vert->position.y + bias;
res.x = vert->position.x;
res.y = vert->position.y;
res.z = 0;

return res;
Expand Down
3 changes: 3 additions & 0 deletions source/GcLib/directx/DxText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,9 @@ void DxTextRenderObject::Render(const D3DXVECTOR2& angX, const D3DXVECTOR2& angY

D3DXMATRIX matWorld = RenderObject::CreateWorldMatrixText2D(center, scale_, angX, angY, angZ,
position, bias, bCamera ? &DirectGraphics::GetBase()->GetCamera2D()->GetMatrix() : nullptr);

matWorld._41 -= DirectGraphics::g_dxBias_;
matWorld._42 -= DirectGraphics::g_dxBias_;

sprite->SetPermitCamera(false);
sprite->SetShader(shader_);
Expand Down
3 changes: 3 additions & 0 deletions source/GcLib/directx/MetasequoiaMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,9 @@ void MetasequoiaMesh::Render(const D3DXVECTOR2& angX, const D3DXVECTOR2& angY, c
D3DXMATRIX mat = RenderObject::CreateWorldMatrix(position_, scale_,
angX, angY, angZ, &camera->GetIdentity(), bCoordinate2D_);
device->SetTransform(D3DTS_WORLD, &mat);

mat._41 -= DirectGraphics::g_dxBias_;
mat._42 -= DirectGraphics::g_dxBias_;

{
size_t i = 0;
Expand Down
45 changes: 25 additions & 20 deletions source/GcLib/directx/RenderObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,9 @@ void RenderObjectTLX::Render(const D3DXVECTOR2& angX, const D3DXVECTOR2& angY, c
else {
matWorld = camera->GetMatrix();
}

matWorld._41 -= DirectGraphics::g_dxBias_;
matWorld._42 -= DirectGraphics::g_dxBias_;

RenderObjectTLX::Render(matWorld);
}
Expand Down Expand Up @@ -551,9 +554,8 @@ void RenderObjectTLX::SetVertexPosition(size_t index, float x, float y, float z,
x *= DirectGraphics::g_dxCoordsMul_;
y *= DirectGraphics::g_dxCoordsMul_;

constexpr float bias = -0.5f;
vertex->position.x = x + bias;
vertex->position.y = y + bias;
vertex->position.x = x;
vertex->position.y = y;
vertex->position.z = z;
vertex->position.w = w;
}
Expand Down Expand Up @@ -631,6 +633,9 @@ void RenderObjectLX::Render(const D3DXVECTOR2& angX, const D3DXVECTOR2& angY, co
D3DXMatrixIdentity(&matWorld);
else matWorld = *matRelative_;
}

matWorld._41 -= DirectGraphics::g_dxBias_;
matWorld._42 -= DirectGraphics::g_dxBias_;

RenderObjectLX::Render(matWorld);
}
Expand Down Expand Up @@ -761,9 +766,8 @@ void RenderObjectLX::SetVertexPosition(size_t index, float x, float y, float z)
x *= DirectGraphics::g_dxCoordsMul_;
y *= DirectGraphics::g_dxCoordsMul_;

constexpr float bias = -0.5f;
vertex->position.x = x + bias;
vertex->position.y = y + bias;
vertex->position.x = x;
vertex->position.y = y;
vertex->position.z = z;
}
void RenderObjectLX::SetVertexUV(size_t index, float u, float v) {
Expand Down Expand Up @@ -971,9 +975,8 @@ void RenderObjectNX::SetVertexPosition(size_t index, float x, float y, float z)
x *= DirectGraphics::g_dxCoordsMul_;
y *= DirectGraphics::g_dxCoordsMul_;

constexpr float bias = -0.5f;
vertex->position.x = x + bias;
vertex->position.y = y + bias;
vertex->position.x = x;
vertex->position.y = y;
vertex->position.z = z;
}
void RenderObjectNX::SetVertexUV(size_t index, float u, float v) {
Expand Down Expand Up @@ -1029,13 +1032,11 @@ void Sprite2D::SetVertex(const DxRect<int>& rcSrc, const DxRect<double>& rcDest,
SetAlpha(ColorAccess::GetColorA(color));
}
DxRect<double> Sprite2D::GetDestinationRect() {
constexpr float bias = -0.5f;

VERTEX_TLX* vertexLeftTop = GetVertex(0);
VERTEX_TLX* vertexRightBottom = GetVertex(3);

DxRect<double> rect(vertexLeftTop->position.x - bias, vertexLeftTop->position.y - bias,
vertexRightBottom->position.x - bias, vertexRightBottom->position.y - bias);
DxRect<double> rect(vertexLeftTop->position.x, vertexLeftTop->position.y,
vertexRightBottom->position.x, vertexRightBottom->position.y);

return rect;
}
Expand Down Expand Up @@ -1105,8 +1106,11 @@ void SpriteList2D::Render(const D3DXVECTOR2& angX, const D3DXVECTOR2& angY, cons

D3DXMATRIX matWorld;
if (bCloseVertexList_)
matWorld = RenderObject::CreateWorldMatrix2D(position_, scale_,
angX, angY, angZ, bCamera ? &camera->GetMatrix() : nullptr);
{
matWorld = RenderObject::CreateWorldMatrix2D(position_, scale_, angX, angY, angZ, bCamera ? &camera->GetMatrix() : nullptr);
matWorld._41 -= DirectGraphics::g_dxBias_;
matWorld._42 -= DirectGraphics::g_dxBias_;
}

vertCopy_ = vertex_;
{
Expand Down Expand Up @@ -1235,6 +1239,8 @@ void SpriteList2D::AddVertex(const D3DXVECTOR2& angX, const D3DXVECTOR2& angY, c

D3DXMATRIX matWorld = RenderObject::CreateWorldMatrix2D(position_, scale_,
angX, angY, angZ, nullptr);
matWorld._41 -= DirectGraphics::g_dxBias_;
matWorld._42 -= DirectGraphics::g_dxBias_;

int* ptrSrc = reinterpret_cast<int*>(&rcSrc_);
double* ptrDst = reinterpret_cast<double*>(&rcDest_);
Expand All @@ -1246,15 +1252,14 @@ void SpriteList2D::AddVertex(const D3DXVECTOR2& angX, const D3DXVECTOR2& angY, c
vt.texcoord.y = (float)ptrSrc[iVert | 0b1] / height;

D3DXVECTOR4 vPos;

constexpr float bias = -0.5f;

vPos.x = (float)ptrDst[(iVert & 0b1) << 1];
vPos.y = (float)ptrDst[iVert | 0b1];
vPos.z = 1.0f;
vPos.w = 1.0f;

vPos.x = vPos.x * DirectGraphics::g_dxCoordsMul_ + bias;
vPos.y = vPos.y * DirectGraphics::g_dxCoordsMul_ + bias;
vPos.x = vPos.x * DirectGraphics::g_dxCoordsMul_;
vPos.y = vPos.y * DirectGraphics::g_dxCoordsMul_;

D3DXVec3TransformCoord((D3DXVECTOR3*)&vPos, (D3DXVECTOR3*)&vPos, &matWorld);
vt.position = vPos;
Expand Down Expand Up @@ -1531,7 +1536,7 @@ void ParticleRendererBase::AddInstance() {
}
VERTEX_INSTANCE instance;
instance.diffuse_color = instColor_;
instance.xyz_pos_x_scale = D3DXVECTOR4(instPosition_.x, instPosition_.y, instPosition_.z, instScale_.x);
instance.xyz_pos_x_scale = D3DXVECTOR4(instPosition_.x - DirectGraphics::g_dxBias_, instPosition_.y - DirectGraphics::g_dxBias_, instPosition_.z, instScale_.x);
instance.yz_scale_xy_ang = D3DXVECTOR4(instScale_.y, instScale_.z, -instAngle_.x, -instAngle_.y);
instance.z_ang_extra = D3DXVECTOR4(-instAngle_.z, instUserData_.x, instUserData_.y, instUserData_.z);
instanceData_[countInstance_++] = instance;
Expand Down
10 changes: 5 additions & 5 deletions source/TouhouDanmakufu/Common/StgShot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1014,13 +1014,11 @@ StgShotData* StgShotObject::_GetShotData(int id) {
}

void StgShotObject::_SetVertexPosition(VERTEX_TLX* vertex, float x, float y, float z, float w) {
constexpr float bias = 0.0f;

x *= DirectGraphics::g_dxCoordsMul_;
y *= DirectGraphics::g_dxCoordsMul_;

vertex->position.x = x + bias;
vertex->position.y = y + bias;
vertex->position.x = x;
vertex->position.y = y;
vertex->position.z = z;
vertex->position.w = w;
}
Expand Down Expand Up @@ -1609,6 +1607,8 @@ void StgNormalShotObject::Render(BlendMode targetBlend) {
sposx = roundf(sposx);
sposy = roundf(sposy);
}
sposx -= DirectGraphics::g_dxBias_;
sposy -= DirectGraphics::g_dxBias_;

float scaleX = 1.0f;
float scaleY = 1.0f;
Expand Down Expand Up @@ -3240,4 +3240,4 @@ void StgShotPatternGeneratorObject::FireSet(void* scriptData, StgStageController
}
}
}
}
}
10 changes: 4 additions & 6 deletions source/TouhouDanmakufu/DnhExecutor/GcLibImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,14 +276,13 @@ void EApplication::_RenderDisplay() {

std::array<VERTEX_TLX, 4> verts;
auto _Render = [](IDirect3DDevice9* device, VERTEX_TLX* verts, const D3DXMATRIX* mat) {
constexpr float bias = -0.5f;
for (size_t iVert = 0; iVert < 4; ++iVert) {
VERTEX_TLX* vertex = (VERTEX_TLX*)verts + iVert;
vertex->diffuse_color = 0xffffffff;

D3DXVECTOR4* vPos = &vertex->position;
vPos->x += bias;
vPos->y += bias;
vPos->x -= DirectGraphics::g_dxBias_;
vPos->y -= DirectGraphics::g_dxBias_;

D3DXVec3TransformCoord((D3DXVECTOR3*)vPos, (D3DXVECTOR3*)vPos, mat);
}
Expand Down Expand Up @@ -343,11 +342,10 @@ void EApplication::_RenderDisplay() {
verts[3] = VERTEX_TLX(D3DXVECTOR4(scW, scH, 0, 1), 0xffffffff,
D3DXVECTOR2(scW / texW, scH / texH));
{
constexpr float bias = -0.5f;
for (size_t iVert = 0; iVert < 4; ++iVert) {
D3DXVECTOR4* vPos = &verts[iVert].position;
vPos->x += bias;
vPos->y += bias;
vPos->x -= DirectGraphics::g_dxBias_;
vPos->y -= DirectGraphics::g_dxBias_;
}
}

Expand Down