加入 Node节点类 还未测试新框架

This commit is contained in:
2025-10-27 23:12:56 +08:00
parent 80d088316b
commit 0ae47e5d6a
52 changed files with 1642 additions and 458 deletions

View File

@@ -43,35 +43,6 @@ RefPtr<Texture> Sprite::GetTexture()
return m_texture;
}
GlMatrix Sprite::matrix3x2ToGLMatrix(const Matrix3x2 &mat)
{
return {
// 列0x轴线性变换
mat._11, // [0][0]
mat._12, // [1][0]
0.0f, // [2][0]
0.0f, // [3][0]
// 列1y轴线性变换
mat._21, // [0][1]
mat._22, // [1][1]
0.0f, // [2][1]
0.0f, // [3][1]
// 列2z轴固定
0.0f, // [0][2]
0.0f, // [1][2]
1.0f, // [2][2]
0.0f, // [3][2]
// 列3平移
mat._31, // [0][3]x平移
mat._32, // [1][3]y平移
0.0f, // [2][3]
1.0f // [3][3]
};
}
void Sprite::CalcRenderInfoLogic()
{
// 获取至在最终的父对象检查是否显示
@@ -105,8 +76,8 @@ void Sprite::CalcRenderInfoLogic()
// 纹理数据里带的偏移数据 有这个偏移才能保证动画播放时视觉中心点在一个点上
auto T_Size = m_texture->getSize();
auto T_Pos = m_texture->getPos();
float texturePosX = flipX ? -(T_Size.width + T_Pos.x) + SDL_abs(transform.position.x * 2) : T_Pos.x;
float texturePosY = flipY ? -(T_Size.height + T_Pos.y) + SDL_abs(transform.position.y * 2) : T_Pos.y;
float texturePosX = flipX ? -((float)T_Size.width + (float)T_Pos.x) + SDL_fabsf(transform.position.x * 2.0f) : (float)T_Pos.x;
float texturePosY = flipY ? -((float)T_Size.height + (float)T_Pos.y) + SDL_fabsf(transform.position.y * 2.0f) : (float)T_Pos.y;
// 先计算Img坐标与精灵坐标合成后的真实坐标
float RealPosX = transform.position.x + texturePosX;
@@ -117,22 +88,22 @@ void Sprite::CalcRenderInfoLogic()
float baseY = transformIter.position.y + RealPosY;
// 获取当前帧的原始尺寸
int frameWidth = Size.width;
int frameHeight = Size.height;
float frameWidth = (float)Size.width;
float frameHeight = (float)Size.height;
// 原始锚点偏移(基于帧尺寸)
float origAnchorOffsetX = int(frameWidth * Anchor.x);
float origAnchorOffsetY = int(frameHeight * Anchor.y);
float origAnchorOffsetX = frameWidth * Anchor.x;
float origAnchorOffsetY = frameHeight * Anchor.y;
// 缩放的绝对值
float absScaleX = SDL_fabs(scaleX);
float absScaleY = SDL_fabs(scaleY);
float absScaleX = SDL_fabsf(scaleX);
float absScaleY = SDL_fabsf(scaleY);
// 缩放后的尺寸
float scaledWidth = frameWidth * absScaleX;
float scaledHeight = frameHeight * absScaleY;
// 缩放后的锚点偏移
float scaledAnchorOffsetX = int(origAnchorOffsetX * absScaleX);
float scaledAnchorOffsetY = int(origAnchorOffsetY * absScaleY);
float scaledAnchorOffsetX = origAnchorOffsetX * absScaleX;
float scaledAnchorOffsetY = origAnchorOffsetY * absScaleY;
// 计算缩放后的锚点偏移与原锚点偏移的差值
float scaleOffsetX = scaledAnchorOffsetX - origAnchorOffsetX;
@@ -142,9 +113,6 @@ void Sprite::CalcRenderInfoLogic()
float Xpos = baseX - scaleOffsetX;
float Ypos = baseY - scaleOffsetY;
Xpos = (int)Xpos; // 强制转换为整数
Ypos = (int)Ypos; // 强制转换为整数
// 更新渲染信息
_RenderGuidanceInfo.rect = {Xpos, Ypos, scaledWidth, scaledHeight};
_RenderGuidanceInfo.AnchorPos = {scaledAnchorOffsetX, scaledAnchorOffsetY};
@@ -152,8 +120,8 @@ void Sprite::CalcRenderInfoLogic()
m_texture->setAlpha(this->Alpha);
// 屏幕内检测
int screenWidth = Game::GetInstance().Screen_W;
int screenHeight = Game::GetInstance().Screen_H;
float screenWidth = (float)Game::GetInstance().Screen_W;
float screenHeight = (float)Game::GetInstance().Screen_H;
bool isInScreen = (Xpos + scaledWidth >= 0 && Xpos <= screenWidth && Ypos + scaledHeight >= 0 && Ypos <= screenHeight);
_RenderGuidanceInfo.IsInScreen = isInScreen;