Skip to content

Commit

Permalink
Fixed #266
Browse files Browse the repository at this point in the history
  • Loading branch information
MineDragonCZ committed Jul 6, 2023
1 parent 36c8a83 commit c7c5001
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 331 deletions.
32 changes: 0 additions & 32 deletions src/main/java/tauri/dev/jsg/raycaster/BetterRaycaster.java

This file was deleted.

4 changes: 2 additions & 2 deletions src/main/java/tauri/dev/jsg/raycaster/Raycaster.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ public boolean onActivated(World world, BlockPos pos, EntityPlayer player, float

// Create rect as surface of the button
Rect rect = new Rect(lines);
if(lines.size() == 4){
if (lines.size() == 4) {
// Probably normal square button
// try this for better mapping
rect = new Rect(lines.get(0), lines.get(2), lines.get(1), lines.get(3));
}
if (rect.checkForPointInBox(lookVec2f)) {
if (rect.checkForPointInRect(lookVec2f)) {
buttonClicked(world, player, btn.buttonId, pos, hand);
return true;
}
Expand Down
260 changes: 130 additions & 130 deletions src/main/java/tauri/dev/jsg/raycaster/dhd/RaycasterDHD.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -20,64 +20,41 @@ public class RaycasterRingsGoauldController extends RaycasterRingsAbstractContro
add(new RayCastedButton(0, Arrays.asList(
new Vector3f(0.566581f, -0.961707f, 0.387802f),
new Vector3f(0.565342f, -0.961707f, 0.468747f),
new Vector3f(0.683045f, -0.96172f, 0.387804f),
new Vector3f(0.684695f, -0.961707f, 0.468747f)
new Vector3f(0.684695f, -0.961707f, 0.468747f),
new Vector3f(0.683045f, -0.96172f, 0.387804f)
)));
add(new RayCastedButton(1, Arrays.asList(
new Vector3f(0.315226f, -0.961707f, 0.382972f),
new Vector3f(0.315226f, -0.961707f, 0.468873f),
new Vector3f(0.432101f, -0.961707f, 0.386276f),
new Vector3f(0.431275f, -0.961707f, 0.46846f)
new Vector3f(0.431275f, -0.961707f, 0.46846f),
new Vector3f(0.432101f, -0.961707f, 0.386276f)
)));
add(new RayCastedButton(2, Arrays.asList(
new Vector3f(0.3144f, -0.961707f, 0.283443f),
new Vector3f(0.315226f, -0.961707f, 0.382972f),
new Vector3f(0.430864f, -0.96172f, 0.282202f),
new Vector3f(0.432101f, -0.961707f, 0.386276f)
new Vector3f(0.432101f, -0.961707f, 0.386276f),
new Vector3f(0.430864f, -0.96172f, 0.282202f)
)));
add(new RayCastedButton(3, Arrays.asList(
new Vector3f(0.564515f, -0.96172f, 0.28662f),
new Vector3f(0.566581f, -0.961707f, 0.387802f),
new Vector3f(0.682219f, -0.96172f, 0.285381f),
new Vector3f(0.683045f, -0.96172f, 0.387804f)
new Vector3f(0.683045f, -0.96172f, 0.387804f),
new Vector3f(0.682219f, -0.96172f, 0.285381f)
)));
add(new RayCastedButton(4, Arrays.asList(
new Vector3f(0.566167f, -0.96172f, 0.199477f),
new Vector3f(0.564515f, -0.96172f, 0.28662f),
new Vector3f(0.682219f, -0.96172f, 0.201129f),
new Vector3f(0.682219f, -0.96172f, 0.285381f)
new Vector3f(0.682219f, -0.96172f, 0.285381f),
new Vector3f(0.682219f, -0.96172f, 0.201129f)
)));
add(new RayCastedButton(5, Arrays.asList(
new Vector3f(0.314399f, -0.96172f, 0.201255f),
new Vector3f(0.3144f, -0.961707f, 0.283443f),
new Vector3f(0.431277f, -0.96172f, 0.200429f),
new Vector3f(0.430864f, -0.96172f, 0.282202f)
new Vector3f(0.430864f, -0.96172f, 0.282202f),
new Vector3f(0.431277f, -0.96172f, 0.200429f)
)));
}};


private static final List<Vector3f> VERTICES = Arrays.asList(
new Vector3f(0.314399f, -0.96172f, 0.201255f),
new Vector3f(0.3144f, -0.961707f, 0.283443f),
new Vector3f(0.315226f, -0.961707f, 0.382972f),
new Vector3f(0.315226f, -0.961707f, 0.468873f),

new Vector3f(0.431277f, -0.96172f, 0.200429f),
new Vector3f(0.430864f, -0.96172f, 0.282202f),
new Vector3f(0.432101f, -0.961707f, 0.386276f),
new Vector3f(0.431275f, -0.961707f, 0.46846f),

new Vector3f(0.566167f, -0.96172f, 0.199477f),
new Vector3f(0.564515f, -0.96172f, 0.28662f),
new Vector3f(0.566581f, -0.961707f, 0.387802f),
new Vector3f(0.565342f, -0.961707f, 0.468747f),

new Vector3f(0.682219f, -0.96172f, 0.201129f),
new Vector3f(0.682219f, -0.96172f, 0.285381f),
new Vector3f(0.683045f, -0.96172f, 0.387804f),
new Vector3f(0.684695f, -0.961707f, 0.468747f)
);

@Override
protected List<RayCastedButton> getButtons() {
return BUTTONS;
Expand Down
28 changes: 0 additions & 28 deletions src/main/java/tauri/dev/jsg/raycaster/util/RayCastedButton.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package tauri.dev.jsg.raycaster.util;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.math.BlockPos;
import tauri.dev.vector.Vector2f;
import tauri.dev.vector.Vector3f;

import java.util.ArrayList;
import java.util.List;

public class RayCastedButton {
Expand All @@ -16,28 +12,4 @@ public RayCastedButton(int buttonId, List<Vector3f> vectors) {
this.buttonId = buttonId;
this.vectors = vectors;
}

private Vector2f getTransposedVector(Vector3f v, float rotation, BlockPos pos, EntityPlayer player, Vector3f translation) {
RaycasterVertex current = new RaycasterVertex(v.x, v.y, v.z);
return current.rotate(rotation).localToGlobal(pos, translation).calculateDifference(player).getViewport(player.getLookVec());
}

public boolean isPointInsideButton(Vector2f point, float rotation, BlockPos pos, EntityPlayer player, Vector3f translation) {
List<Vector2f> vectors = new ArrayList<>();

for (Vector3f v : this.vectors) {
vectors.add(getTransposedVector(new Vector3f(v.x, v.y, v.z), rotation, pos, player, translation));
}

int i, j, n = vectors.size();
int count = 0;

for (i = 0, j = n - 1; i < n; j = i++) {
if ((vectors.get(i).y > point.y) != (vectors.get(j).y > point.y) && (point.x < (vectors.get(j).x - vectors.get(i).x) * (point.y - vectors.get(i).y) / (vectors.get(j).y - vectors.get(i).y) + vectors.get(i).x)) {
count++;
}
}

return (count % 2 > 0);
}
}
103 changes: 0 additions & 103 deletions src/main/java/tauri/dev/jsg/raycaster/util/RaycasterPolygon.java

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/java/tauri/dev/jsg/raycaster/util/Rect.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public Rect(List<Line> lines) {
this.lines = lines;
}

public boolean checkForPointInBox(Vector2f p) {
public boolean checkForPointInRect(Vector2f p) {
int intersects = 0;

float a = 0.3f;
Expand Down

0 comments on commit c7c5001

Please sign in to comment.