Skip to content

Commit

Permalink
Optimized some codes (1)
Browse files Browse the repository at this point in the history
  • Loading branch information
xTracr committed Mar 4, 2024
1 parent 7025e76 commit 5af11b4
Show file tree
Hide file tree
Showing 15 changed files with 125 additions and 114 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ jobs:
run: env

- name: Checkout Repository
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: true

- name: Setup JDK
uses: actions/setup-java@v2
uses: actions/setup-java@v4
with:
distribution: "temurin"
java-version: 17
Expand Down
142 changes: 82 additions & 60 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@

### Test Versions ###

* 0.6.0-beta:
* 0.6.0-alpha.1:
* 0.6:
* 0.6.0-alpha.1:
* Added model view screen
* Allowed to select the model part you want to bind directly in the screen
* 0.6.0-alpha.2:
* 0.6.0-alpha.2:
* Fixed #41, #46 and #48
* Fix minor grammar errors (#44)
* Optimized the GUI display and changed logic of selection button
* Changed the way to render player
* Added pause button and show cube button
* Allowed to disable rendering vertices based on depth relative to screen
* Added 'AutoBind' feature
* 0.6.0-alpha.3:
* 0.6.0-alpha.3:
* Changed to bind based on UV coordinates and improved GUI
* Fixed #54
* Improved Gui and Fixed a bug that would cause crash
Expand All @@ -29,101 +29,112 @@
* Added 'preview' feature
* Removed commands
* Improved default configs and reformatted code
* 0.6.0-beta:
* Optimized some codes


* 0.5:
* 0.5.0-beta:
* Redesigned config screen
* Removed commands because it's no longer useful
* Allowed disabling rendering partial model
* 0.5.1-beta:
* Redesigned config screen
* Removed commands because it's no longer useful
* Allowed disabling rendering partial model
* 0.5.1-beta:
* Divided `Bind Rotation` option into three options
* 0.5.2-beta:
* 0.5.2-beta:
* Fixed #7, #8 and clipping issue
* 0.5.3-beta:
* 0.5.3-beta:
* Compatible with Physics Mod ocean physics (#6)
* Allowed disabling when holding a specific item
* Added support for 1.19.2
* Upgraded to 1.20
* 0.5.4-beta:
* 0.5.4-beta:
* Added feature #15, fixed #35
* Changed the way of clipping to space to avoid #23 and #32
* 0.5.5-beta:
* 0.5.5-beta:
* Changed the way of clipping to space to avoid #37
* Deleted the option of disabling "clip to space"
* Separate the part that modifies camera from the part that computes it


* 0.4:
* 0.4.0-alpha:
* Fixed an issue where the camera would not follow the model action when the player started/ended sneaking
* Compatible with Pehkui
* API for others to compat with
* 0.4.1-alpha:
* Fixed an issue where the camera would not follow the model action when the player started/ended sneaking
* Compatible with Pehkui
* API for others to compat with
* 0.4.1-alpha:
* Compatible with EpicFight
* Added commands for debugging
* 0.4.2-alpha:
* 0.4.2-alpha:
* Fixed an issue where extra camera rotation cannot be applied correctly in specific situations
* Allowed adjusting camera rotation with hotkeys
* 0.4.3-alpha:
* 0.4.3-alpha:
* Allowed adjusting camera rotation in classic mode
* Improved calculation of crosshair hit result
* Bug fixes:
* model sometimes isn't rendered when flying with elytra
* leash position isn't correct
* 0.4.4-alpha:
* 0.4.4-alpha:
* Added "dynamic crosshair" feature
* Added "clip to space" feature


* 0.3:
* 0.3.0-alpha:
* Made the hit result of the player's crosshair match the actual position of the crosshair
* Attempted to implement the effect of binding mode
* 0.3.1-alpha:
* Made the hit result of the player's crosshair match the actual position of the crosshair
* Attempted to implement the effect of binding mode
* 0.3.1-alpha:
* Added camera position correction for other actions
* Improved the effect of binding mode
* 0.3.2-alpha:
* 0.3.2-alpha:
* Added more binding mode configurations
* Attempted to bind camera direction to the model part
* 0.3.3-alpha:
* 0.3.3-alpha:
* Allowed camera direction to be bound to the model part
* 0.3.4-alpha:
* 0.3.4-alpha:
* Allowed crosshair direction to follow the camera
* Changed the mod's name
* Fixed two binding mode issues:
* Camera and model animation are not completely synchronized
* When the inventory is opened, the camera follows the character model in the inventory
* 0.3.5-alpha:
* 0.3.5-alpha:
* Optimized code logic
* Allowed to disable in specfic conditions
* 0.3.6-alpha:
* 0.3.6-alpha:
* Optimized code logic
* Upgraded to 1.19.4
* Supported Fabric


* 0.2:
* 0.2.0-alpha:
* Added player model rendering mode
* 0.2.1-alpha:
* Added player model rendering mode
* 0.2.1-alpha:
* Added camera position correction for sneaking action
* Can render crosshairs in model rendering mode


* 0.1.0-alpha:
* Added functionality to move camera and its rotation center
* Added feature to move camera and its rotation center

## 中文 ##

### 正式版 ###

### 测试版 ###

* 0.6.0-beta:
* 0.6.0-alpha.1:
* 0.6:
* 0.6.0-alpha.1:
* 添加了模型视图界面
* 允许在界面中选择想要绑定的模型部位
* 0.6.0-alpha.2:
* 0.6.0-alpha.2:
* 修复了#41#46#48
* 修复了一些语法问题(#44
* 优化了GUI显示效果以及修改了选择按钮的逻辑
* 修改了渲染玩家的方式
* 添加了暂停按钮和显示立方体按钮
* 允许根据相对于屏幕的距离禁用渲染部分顶点
* 添加了'自动绑定'功能
* 0.6.0-alpha.3:
* 0.6.0-alpha.3:
* 改为基于UV坐标绑定并且改进了GUI
* 修复了#54
* 改进了GUI,修复了一个会导致崩溃的问题
Expand All @@ -134,78 +145,89 @@
* 添加了'预览'功能
* 移除了命令
* 改进了默认配置,重新格式化代码
* 0.6.0-beta:
* 优化了部分代码


* 0.5:
* 0.5.0-beta:
* 重新设计了配置屏幕
* 删除了命令,因为它不再有用
* 允许禁用渲染部分模型
* 0.5.1-beta:
* 重新设计了配置屏幕
* 删除了命令,因为它不再有用
* 允许禁用渲染部分模型
* 0.5.1-beta:
*`绑定旋转`选项分为了三个选项
* 0.5.2-beta:
* 0.5.2-beta:
* 修复了#7, #8以及clip的问题
* 0.5.3-beta:
* 0.5.3-beta:
* 兼容Physics Mod的海洋物理 (#6)
* 允许在手持特定物品时禁用
* 添加了对1.19.2的支持
* 更新至1.20
* 0.5.4-beta:
* 0.5.4-beta:
* 添加了功能#15, 修复#35
* 修改了clip to space的方式来避免#23#32
* 0.5.5-beta:
* 0.5.5-beta:
* 修改了clip to space的方式来避免#37
* 删除了禁用"clip to space"的选项
* 将修改摄像头的部分与计算它的部分分离开来


* 0.4:
* 0.4.0-alpha:
* 修复了玩家开始/结束潜行时摄像头未跟上模型动作的问题
* 兼容Pehkui
* 用于兼容的API
* 0.4.1-alpha:
* 修复了玩家开始/结束潜行时摄像头未跟上模型动作的问题
* 兼容Pehkui
* 用于兼容的API
* 0.4.1-alpha:
* 兼容EpicFight
* 新增用于调试的命令
* 0.4.2-alpha:
* 0.4.2-alpha:
* 修复了额外的摄像头旋转在特定情况下无法正确应用的问题
* 允许用按键调整摄像头旋转
* 0.4.3-alpha:
* 0.4.3-alpha:
* 允许调整经典模式下的摄像头旋转
* 改进了准心命中结果的计算
* Bug修复:
* 鞘翅飞行时模型有时不渲染
* 缰绳位置不正确
* 0.4.4-alpha:
* 0.4.4-alpha:
* 添加了动态十字准心功能
* 添加了防止摄像头进入方块内部(Clip to space)的功能


* 0.3:
* 0.3.0-alpha:
* 使玩家十字准心的命中结果与十字准心的实际位置相匹配
* 尝试实现绑定模式的效果
* 0.3.1-alpha:
* 使玩家十字准心的命中结果与十字准心的实际位置相匹配
* 尝试实现绑定模式的效果
* 0.3.1-alpha:
* 添加了对其余动作的摄像头位置修正
* 初步完善了绑定模式
* 0.3.2-alpha:
* 0.3.2-alpha:
* 添加了更多绑定模式的配置
* 尝试将摄像头方向绑定在模型上
* 0.3.3-alpha:
* 0.3.3-alpha:
* 允许将摄像头方向绑定在模型上
* 0.3.4-alpha:
* 0.3.4-alpha:
* 允许让十字准心的方向跟随摄像头
* 修改了MOD名字
* 修复了两个绑定模式下的问题:
* 摄像头与模型动画不完全同步
* 开启物品栏时摄像头跟随物品栏内人物模型转动
* 0.3.5-alpha:
* 0.3.5-alpha:
* 代码逻辑优化
* 允许在特定情况下禁用mod部分功能
* 0.3.6-alpha:
* 0.3.6-alpha:
* 代码逻辑优化
* 更新至1.19.4
* 支持Fabric


* 0.2:
* 0.2.0-alpha:
* 添加了玩家模型渲染模式
* 0.2.1-alpha:
* 添加了玩家模型渲染模式
* 0.2.1-alpha:
* 添加了对潜行动作的摄像头位置的修正
* 可以在玩家模型渲染模式下渲染十字准心


* 0.1.0-alpha:
* 添加了移动摄像头及其旋转中心的功能
* 添加了移动摄像头及其旋转中心的功能
17 changes: 7 additions & 10 deletions common/src/main/java/com/xtracr/realcamera/RealCameraCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,11 @@ public static boolean isActive() {
}

public static void renderPlayer(VertexConsumerProvider vertexConsumers) {
MatrixStack matrixStack = new MatrixStack();
matrixStack.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(roll));
matrixStack.multiply(RotationAxis.POSITIVE_X.rotationDegrees(pitch));
matrixStack.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(yaw + 180.0f));
Matrix3f normalMatrix = matrixStack.peek().getNormalMatrix().transpose().invert();
Matrix4f positionMatrix = matrixStack.peek().getPositionMatrix().transpose().invertAffine()
.translate((float) -pos.getX(), (float) -pos.getY(), (float) -pos.getZ());
Matrix3f normalMatrix = new Matrix3f().rotate(RotationAxis.POSITIVE_Z.rotationDegrees(roll))
.rotate(RotationAxis.POSITIVE_X.rotationDegrees(pitch))
.rotate(RotationAxis.POSITIVE_Y.rotationDegrees(yaw + 180.0f))
.transpose().invert();
Matrix4f positionMatrix = new Matrix4f(normalMatrix).translate((float) -pos.getX(), (float) -pos.getY(), (float) -pos.getZ());
BiFunction<RenderLayer, VertexRecorder.Vertex[], VertexRecorder.Vertex[]> function = (renderLayer, vertices) -> {
double depth = currentTarget.disablingDepth(), centerZ = 0;
int count = vertices.length;
Expand Down Expand Up @@ -134,14 +132,13 @@ public static void computeCamera(MinecraftClient client, float tickDelta) {
pos = new Vec3d(offset.x(), offset.y(), offset.z());
Matrix3f normal = matrixStack.peek().getNormalMatrix().scale(1.0f, -1.0f, -1.0f);
if (config().binding.experimental) {
List<BindingTarget> targetList = new ArrayList<>();
List<BindingTarget> targetList = new ArrayList<>(List.of(config().getTarget()));
if (config().binding.autoBind) {
List<BindingTarget> targets = config().binding.targetList;
recorder.setCurrent(renderLayer -> targets.stream().anyMatch(t -> renderLayer.toString().contains(t.textureId())));
String textureId = recorder.currentTextureId();
if (textureId != null) targetList.addAll(targets.stream().filter(t -> textureId.contains(t.textureId())).toList());
}
targetList.add(config().getTarget(config().binding.targetName));
for (BindingTarget target : targetList) {
try {
recorder.setCurrent(renderLayer -> renderLayer.toString().contains(target.textureId()));
Expand All @@ -156,7 +153,7 @@ public static void computeCamera(MinecraftClient client, float tickDelta) {
normal.rotateLocal((float) Math.toRadians(currentTarget.yaw()), normal.m10, normal.m11, normal.m12);
normal.rotateLocal((float) Math.toRadians(currentTarget.pitch()), normal.m00, normal.m01, normal.m02);
normal.rotateLocal((float) Math.toRadians(currentTarget.roll()), normal.m20, normal.m21, normal.m22);
Vec3d eulerAngle = MathUtil.getEulerAngleYXZ(normal).multiply(180.0d / Math.PI);
Vec3d eulerAngle = MathUtil.getEulerAngleYXZ(normal).multiply(Math.toDegrees(1));
pitch = (float) eulerAngle.getX();
yaw = (float) -eulerAngle.getY();
roll = (float) eulerAngle.getZ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public static Screen create(Screen parent) {
disable.addEntry(disableModWhen.build());

experimental.addEntry(entryBuilder.startBooleanToggle(Text.literal("Enabled"), config.binding.experimental)
.setDefaultValue(true)
.setDefaultValue(false)
.setSaveConsumer(b -> config.binding.experimental = b)
.build());
experimental.addEntry(entryBuilder.startBooleanToggle(Text.literal("Auto Bind"), config.binding.autoBind)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ public boolean isAdjustingOffset() {
return binding.adjustOffset;
}

public BindingTarget getTarget(String name) {
return binding.targetList.stream().filter(target -> target.name().equals(name)).findAny().orElse(null);
public BindingTarget getTarget() {
return binding.targetList.stream().filter(t -> t.name().equals(binding.targetName)).findAny().orElse(null);
}

public boolean isXBound() {
Expand Down Expand Up @@ -306,7 +306,7 @@ private void clamp() {
public static class Binding {
public List<BindingTarget> targetList = new ArrayList<>(BindingTarget.defaultTargets);
public VanillaModelPart vanillaModelPart = VanillaModelPart.head;
public boolean experimental = true;
public boolean experimental = false;
public boolean adjustOffset = true;
public boolean autoBind = true;
public String targetName = "minecraft_head";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@ public int getFocusedIndex(int mouseX, int mouseY, int layers) {
Polygon polygon = new Polygon();
Vertex[] quad = vertices[i];
for (Vertex vertex : quad) polygon.addPoint((int) vertex.x(), (int) vertex.y());
if (!polygon.contains(mouseX, mouseY)) continue;
Vertex point = quad[0];
double deltaZ = 0;
if (point.normalZ() != 0) deltaZ = (point.normalX() * (mouseX - point.x()) + point.normalY() * (mouseY - point.y())) / point.normalZ();
if (polygon.contains(mouseX, mouseY)) sortByDepth.add(new Triple(point.z() + deltaZ, record, i));
sortByDepth.add(new Triple(point.z() + deltaZ, record, i));
}
});
if (sortByDepth.isEmpty()) return -1;
Expand Down
Loading

0 comments on commit 5af11b4

Please sign in to comment.