加入 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

@@ -1,5 +1,5 @@
#include "ActiveObject.h"
void ActiveObject::SetPosition(VecPos3 pos)
void ActiveObject::SetPosition(VecFPos3 pos)
{
BaseObject::SetPosition(pos);
}
@@ -21,49 +21,36 @@ VecSpeed3 ActiveObject::GetSpeed()
void ActiveObject::Update(float deltaTime)
{
int IntegerDelta = static_cast<int>(deltaTime * 1000);
const int Gravity = 1020;
VecFPos3 MovePos;
// X轴移动含余数补偿
if (Speed.x != 0)
{
int totalX = Speed.x * IntegerDelta + Remainder.x; // 加上上次余数
int moveX = totalX / 1000; // 整数部分为实际移动
Remainder.x = totalX % 1000; // 保留余数(-999~999
MoveBy(moveX, 0, 0);
MovePos.x = Speed.x * deltaTime;
}
// Y轴移动同上
if (Speed.y != 0)
{
int totalY = Speed.y * IntegerDelta + Remainder.y;
int moveY = totalY / 1000;
Remainder.y = totalY % 1000;
MoveBy(0, moveY, 0);
MovePos.y = Speed.y * deltaTime;
}
// Z轴重力与移动含余数补偿
if (Position.z > 0 || Speed.z > 0)
{
// 重力对速度的影响先更新Speed.z含余数
int speedZTotal = -Gravity * IntegerDelta + Remainder.z; // 注意负号(减速)
Speed.z += speedZTotal / 1000; // 速度的整数部分
Remainder.z = speedZTotal % 1000; // 速度的余数
int speedZTotal = -1020 * deltaTime;
// 基于更新后的Speed.z计算移动量同样含余数
int moveZTotal = Speed.z * IntegerDelta + _zRemainderMove; // 新增_zRemainderMove记录移动余数
int moveZ = moveZTotal / 1000;
_zRemainderMove = moveZTotal % 1000;
MoveBy(0, 0, moveZ);
MovePos.z = Speed.z * deltaTime;
}
else if (Position.z < 0)
{
Position.z = 0;
Speed.z = 0;
Remainder.z = 0; // 重置余数
_zRemainderMove = 0;
SetPosition(Position);
}
MoveBy(MovePos);
BaseObject::Update(deltaTime);
}